Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use R language to survive in KM

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use R language for KM survival". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

R is one of the commonly used software for data analysis. Through various powerful R packages, various analysis can be realized simply and conveniently. In R language, there are many R packages that can perform survival analysis. Survival and survivor are the two most basic ones. Survival is responsible for analysis, survivor is responsible for visualization, and the combination of the two can easily achieve survival analysis. specific process is as follows

1. Prepare survival data

For each individual, survival data can occur in two ways: the first is observed survival time, usually denoted by 1, and the second is censored. It is usually represented by 0. Survival comes with a test data lung, which looks like this

Each row represents a sample, time represents survival time, status represents censoring, and there are only two values, 1 and 2. The value corresponding to the first level after sorting is censoring by default, and 1 represents censoring here. Other basic information such as gender and age corresponding to the sample is listed.

2. for survival analysis

Here, KM algorithm is used to estimate survival curve according to sex, which is a binary variable. The code is as follows

Extract the results from the fit to form the data box d, you can see that it already contains the survival probability, censoring and other information at each time point, through this information, you can write your own code to draw. For convenience, we directly use the functions in survminer for visualization.

3. Visualization of analytical results

The most basic visualizations are as follows

library("survminer")

ggsurvplot(fit)

The renderings are as follows

The two polylines of different colors represent survival curves regardless of gender. For two groups of survival data, it is usually necessary to compare whether there is a difference between the two, and the most commonly used algorithm is log-rank test. survminer also supports difference testing when visualizing results, and marks the corresponding p value on the graph. The code is as follows

ggsurvplot(fit, pval = TRUE)

The renderings are as follows

The p value in the graph above is less than 0.05, indicating that there is a significant difference in survival curves between sexes. In addition to these basic functions, the function has multiple parameters, which can flexibly display the results, such as adding confidence intervals. The code is as follows

ggsurvplot(fit, pval = TRUE, conf.int = TRUE)

The renderings are as follows

It is also supported to label the median of survival time with the following code

ggsurvplot(fit, pval = TRUE, conf.int = TRUE, surv.median.line = "hv")

The renderings are as follows

This function also has many parameters, which can adjust the visualization result very personalized. For more detailed parameter usage, please refer to the official help document.

"How to use R language KM survival" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report