今天我们再一起看看如何使用R软件进行COX比例风险模型。
对于生存分析,我们上一讲讲了如何使用R软件进行生存曲线的绘制,以及进行两组的log-rank比较。但是之前介绍的都只是分析单个因变量,而且只能是分类变量,无法分析连续性自变量。今天我们再一起看看如何使用R软件进行COX比例风险模型。
HR = 1: 无影响
HR < 1: 风险降低
HR > 1: 风险增高
同样首先安装两个包
install.packages(c("survival", "survminer"))
然后调用这两个包
library("survival")
library("survminer")
构建COX语句常规语句
coxph(formula, data, method)
数据还是调用R自带的lung数据,需要先调用survival包
data("lung")
head(lung)
先来看看单因素COX,我去,什么是单因素cox,这就和单因素回归和单因素分析一个道理。
res.cox <- coxph(Surv(time, status) ~ sex, data = lung)
res.cox
Call:
coxph(formula = Surv(time, status) ~ sex, data = lung)
coef exp(coef) se(coef) z p
sex -0.531 0.588 0.167 -3.18 0.0015
Likelihood ratio test=10.6 on 1 df, p=0.00111
n= 228, number of events= 165
妥妥的,年龄是影响生存时间的一个自变量。
summary(res.cox)
Call:
coxph(formula = Surv(time, status) ~ sex, data = lung)
n= 228, number of events= 165
coef exp(coef) se(coef) z Pr(>|z|)
sex -0.5310 0.5880 0.1672 -3.176 0.00149 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
sex 0.588 1.701 0.4237 0.816
Concordance= 0.579 (se = 0.022 )
Rsquare= 0.046 (max possible= 0.999 )
Likelihood ratio test= 10.63 on 1 df, p=0.001111
Wald test = 10.09 on 1 df, p=0.001491
Score (logrank) test = 10.33 on 1 df, p=0.001312
下面看看多因素的cox比例风险模型
res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
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: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
age 1.0111 0.9890 0.9929 1.0297
sex 0.5754 1.7378 0.4142 0.7994
ph.ecog 1.5900 0.6289 1.2727 1.9864
Concordance= 0.637 (se = 0.026 )
Rsquare= 0.126 (max possible= 0.999 )
Likelihood ratio test= 30.5 on 3 df, p=1.083e-06
Wald test = 29.93 on 3 df, p=1.428e-06
Score (logrank) test = 30.5 on 3 df, p=1.083e-06
图形的展示绝对是画龙点睛之处
ggsurvplot(survfit(res.cox), color = "#2E9FDF",
ggtheme = theme_minimal())
看看不同性别之间的cox生存曲线
sex_df <- with(lung,
data.frame(sex = c(1, 2),
age = rep(mean(age, na.rm = TRUE), 2),
ph.ecog = c(1, 1)
)
)
sex_df
fit <- survfit(res.cox, newdata = sex_df)
ggsurvplot(fit, conf.int = TRUE, legend.labs=c("Sex=1", "Sex=2"),
ggtheme = theme_minimal())
不感兴趣
看过了
取消
人点赞
人收藏
打赏
不感兴趣
看过了
取消
打赏金额
认可我就打赏我~
1元 5元 10元 20元 50元 其它打赏作者
认可我就打赏我~
扫描二维码
立即打赏给Ta吧!
温馨提示:仅支持微信支付!