生存分析与cox回归
# setwd('E:/医学统计学(第4版)/各章例题SPSS数据文件') data_19_2 <-
# haven::read_sav('例19-02.sav') data_19_1 <- haven::read_sav('例19-01.sav') data_19_3 <-
# haven::read_sav('例19-03.sav') data_19_5 <- haven::read_sav('例19-05.sav') save(data_19_2,
# file='19_2.Rdata') save(data_19_5, file='19_5.Rdata')
load(url("https://github.com/x2yline/Rdata/raw/master/mediacl_statistics/19_2.Rdata"))
load(url("https://github.com/x2yline/Rdata/raw/master/mediacl_statistics/19_5.Rdata"))
par(family = "simhei")
library(survival)
CPCOLS <- c("#FF0A58", "#AB9E9E")
CPCOLS <- c("#F01641", "#A19999")
## 生存分析
fit2 <- survfit(Surv(time, status) ~ group, data = data_19_2)
plot(fit2, lty = c(1, 1), ylab = "生存率", xlab = "生存时间(月)", bty = "n", main = "生存曲线",
col = c(CPCOLS[1], CPCOLS[2]), lwd = 2, mark.time = T, mark = 19, cex = 1.1)
legend(40, 1, c("甲种手术方式", "乙种手术方式", "删失"), lty = c(1, 1, NA), pch = c(NA, NA,
16), col = c(CPCOLS[1], CPCOLS[2], CPCOLS[1]), lwd = 2, bty = "n", cex = 0.8)
生存分析曲线
diff_sur <- survdiff(Surv(time, status) ~ group, data = data_19_2)
pchisq(q = diff_sur$chisq, df = 1, lower.tail = FALSE)
## [1] 0.003089351
## http://sites.stat.psu.edu/~drh20/R/html/survival/html/plot.survfit.html
## cox回归分析
fit5 = coxph(Surv(t, y) ~ X4 + X5, data = data_19_5)
# plot(survfit( fit5))
fit5.sum <- summary(fit5)
fit5.sum[["coefficients"]]
## coef exp(coef) se(coef) z Pr(>|z|)
## X4 -1.7830043 0.1681323 0.5478848 -3.254342 0.001136555
## X5 0.9395114 2.5587308 0.4446201 2.113066 0.034595151
网友评论