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 realize Cox proportional risk Model in R language

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, I would like to share with you how R language to achieve Cox proportional risk model of the relevant knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

Cox proportional hazard model (cox proportional-hazards model), referred to as Cox model

It is a semiparametric regression model proposed by British statistician D.R.Cox (1972). Taking survival outcome and survival time as dependent variables, the model can analyze the influence of many factors on survival time at the same time, can analyze the data with truncated survival time, and does not require to estimate the survival distribution type of the data.

The basic assumptions of the Cox model are:

At any point in time, the risk ratio of occurrence time between the two groups is constant; or the risk curve should be proportional and cannot be crossed. That is, if the risk of death of one individual at a certain point is twice that of another, then the risk of death at any other point in time is also twice as high. In short, the covariates (variable factors) parameters of the Cox model must satisfy the above assumptions, but sometimes there is a delayed response and false progress in the course of the study, resulting in the survival curve (such as PFS) entangled in the early stage and separated several months later. This will encounter the dilemma of immunotherapy in immunotherapy: what if the COX model does not meet the proportional risk hypothesis? At this point, the hypothesis of the Cox model is not valid

If there is more than one end point of the event, that is, there are multiple end points and competitive risks at the same time, then the Cox model is not applicable. Generally, the competitive risk model will be considered, and these end events are called competitive risk events.

Cox model and Kaplan-Meier method:

Kaplan-Meier method is a nonparametric method, while Cox model is a semi-parametric method. Generally speaking, under certain conditions, the test effect of the latter is greater than that of the former.

Kaplan-Meier method generally deals with the influence of single factor on survival outcome, while Cox model can deal with the influence of multiple factors on survival outcome at the same time.

The Cox model can be expressed by hazard function, h (t); simply speaking, it is the risk of death at t moment, and the formula is as follows:

H (t) = h0 (t) × exp (b1x1 + b2x2 +... + bpxp)

T stands for time to live.

X1-xp stands for covariates

B1-bp represents the regression coefficient of the covariable

Then how to calculate the Cox model in R

The following two packages are also used:

Library ("survival") library ("survminer")

The coxph () function is mainly used to calculate the Cox model, but it is necessary to use the Surv () function to generate a survival object first; in addition, the coxph () function supports exact,breslow and exact, and the default is exact

Take the lung dataset as an example to look at the impact of gender factors on survival outcomes.

Data ("lung") res.cox summary (res.cox) Call:coxph (formula = Surv (time, status) ~ sex, data = lung) n = 228, number of events= 165coef exp (coef) se (coef) z Pr (> | z |) sex-0.5310 0.5880 0.1672-3.176 0.00149 * *-Signif. Codes: 00.1exp (coef) exp (- coef) lower .95 upper .95sex 0.588 1.701 0.4237 0.816Concordance0.579 (se = 0.022) Rsquare= 0.046 (max possible= 0.999) Likelihood ratio test= 10.63 on 1 df, p=0.001Wald test= 10.09 on 1 df P=0.001Score (logrank) test = 10.33 on 1 df

The coef in the above summary results is the regression coefficient b (sometimes called beta) in the formula, so exp (coef) is the most important conceptual risk ratio (HR-hazard ratio) in the Cox model:

HR = 1: No effect

HR

< 1: Reduction in the hazard HR >

1: Increase in Hazard

In cancer research:

Hazard ratio > 1 is called bad prognostic factor

Hazard ratio

< 1 is called good prognostic factor z(-3.176)值代表Wald统计量,其值等于回归系数coef除以其标准误se(coef),即z = coef/se(coef);有统计量必有其对应的假设检验的显著性P值(0.00149),其说明bata值是否与0有统计学意义上的显著差别 coef(-0.5310)值小于0说明HR值小于1,而这里的Cox模型是group two相对于group one而言的,那么按照测试数据集来说:male=1,female=1,即女性的死亡风险相比男性要低 exp(coef)等于0.59,即风险比例等于0.59,说明女性(male=2)减少了0.59倍风险,女性与良好预后相关 lower .95 upper .95则是exp(coef)的95%置信区间 Likelihood ratio test,Wald test,Score (logrank) test则是给出了3种可选择的P值,这三者是asymptotically equivalent;当样本数目足够大时(我也不知道多少样本是足够大。。),这三者的值是相似的;当样本数目较少时,这三者是有差别的,但是Likelihood ratio test会比其他两种在小样本中表现的更优 Cox模型在于其可以对多因素进行Cox回归分析,如我们想同时考虑年龄、性别以及ECOG performance score(ph.ecog)对生存结局的影响 res.cox summary(res.cox)Call:coxph(formula = Surv(time, status) ~ age + sex + ph.ecog, data = lung) n= 227, number of events= 164 (1 observation deleted due to missingness) coef exp(coef) se(coef) z Pr(>

| z |) age 0.011067 1.011128 0.009267 1.194 0.232416 sex-0.552612 0.575445 0.167739-3.294 0.000986 * ph.ecog 0.463728 1.589991 0.113577 4.083 4.45e-05 *-- Signif. Codes: 00.1exp (coef) exp (- coef) lower. 95 upper .95age 1.0111 0.9890 0.9929 1.0297sex 0.5754 1.7378 0.4142 0.7994ph.ecog 1.5900 0.6289 1.2727 1.9864 Concordance0.637 (se = 0.026) ) Rsquare= 0.126 (max possible= 0.999) Likelihood ratio test= 30.5 on 3 df P=1e-06Wald test = 29.93 on 3 df, p=1e-06Score (logrank) test = 30.5 on 3 df, p=1e-06

The form of the result here is roughly the same as that of a single factor, and we mainly need to look at the following points:

The P values given by the three hypothesis testing methods of Likelihood ratio test/Wald test/Score (logrank) test show that the Cox model tests whether the beta value of the three factors is zero, and rejects omnibus null hypothesis (beta=0 's zero hypothesis).

The results of the model show that the HR and P values of the three factors remain unchanged respectively, such as the HR=1.01 and PP0.23 of the age factor, indicating that the age factor has little contribution to the change of HR after adjusting for the influence of gender and ph.ecog factors.

Looking at gender factors, HR=0.58 and Purge 0.000986, it shows that while other factors remain unchanged, there is a strong relationship between age and the risk of death, and female performance reduces the risk of death by 0.58 times, which once again shows that women are associated with a good prognosis.

Finally, take a look at the survival curve.

According to the Cox model of data fitting, we can visually display its predicted survival ratio at each time. Using the survfit () function to evaluate the survival ratio, the default is based on the average of all factors (covariates)

Ggsurvplot (survfit (res.cox), data = lung, palette = "# 2E9FDF", ggtheme = theme_minimal (), legend = "none")

If you want to take a separate look at the predictive visualization of one of the factors (covariates) in the above Cox model, the tutorial deals with the other two factors (covariates):

In this case, we construct a new data frame with two rows, one for each value of sex; the other covariates are fixed to their average values (if they are continuous variables) or to their lowest level (if they are discrete variables). For a dummy covariate, the average value is the proportion coded 1 in the data set

Copy the code below:

# Create the new data sex_df

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

Development

Wechat

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

12
Report