coxph函数构建公式,公式包括生存对象和纳入多因素cox的变量,注意变量可以是分类变量 需要Surv函数构建生存对象 多因素分析得到HR, 95%CI,Pvalue 还可一句简单的命令绘制森林图
require("survival")
require(survminer)
library(ggplot2)
head(colon)
## id study rx sex age obstruct perfor adhere nodes status differ
## 1 1 1 Lev+5FU 1 43 0 0 0 5 1 2
## 2 1 1 Lev+5FU 1 43 0 0 0 5 1 2
## 3 2 1 Lev+5FU 1 63 0 0 0 1 0 2
## 4 2 1 Lev+5FU 1 63 0 0 0 1 0 2
## 5 3 1 Obs 0 71 0 0 1 7 1 2
## 6 3 1 Obs 0 71 0 0 1 7 1 2
## extent surg node4 time etype
## 1 3 0 1 1521 2
## 2 3 0 1 968 1
## 3 3 0 0 3087 2
## 4 3 0 0 3087 1
## 5 2 0 1 963 2
## 6 2 0 1 542 1
## 多因素cox回归
# coef回归系数
model <- coxph( Surv(time, status) ~ sex + rx + adhere,
data = colon )
model
## Call:
## coxph(formula = Surv(time, status) ~ sex + rx + adhere, data = colon)
##
## coef exp(coef) se(coef) z p
## sex -0.04615 0.95490 0.06609 -0.698 0.484994
## rxLev -0.02724 0.97313 0.07690 -0.354 0.723211
## rxLev+5FU -0.43723 0.64582 0.08395 -5.208 1.91e-07
## adhere 0.29355 1.34118 0.08696 3.376 0.000736
##
## Likelihood ratio test=46.51 on 4 df, p=1.925e-09
## n= 1858, number of events= 920
ggforest(model)
再一次说明变量可以有多个分类,不一定是二分类变量 这样就能清楚的指定参考的分类变量标签
colon <- within(colon, {
sex <- factor(sex, labels = c("female", "male"))
differ <- factor(differ, labels = c("well", "moderate", "poor"))
extent <- factor(extent, labels = c("submuc.", "muscle", "serosa", "contig."))
})
bigmodel <-
coxph(Surv(time, status) ~ sex + rx + adhere + differ + extent + node4,
data = colon )
ggforest(bigmodel)
## Warning in .get_data(model, data = data): The `data` argument is not
## provided. Data will be extracted from model fit.
## Warning: Removed 4 rows containing missing values (geom_errorbar).