R語言cox實現
加載包
library("survival")
沒有的先安裝
install.packages('survival')
示例
testdata <- data.frame(time=c(3,5,6,7,9),status=c(1,0,1,0,1),z=c(0,1,1,0,1))
resCox<-coxph(Surv(time,status)~z,data=testdata)
summary(resCox)
結果
Call:
coxph(formula = Surv(time, status) ~ z, data = testdata)
n= 5, number of events= 3
coef exp(coef) se(coef) z Pr(>|z|)
z -0.5493 0.5774 1.4179 -0.387 0.698
exp(coef) exp(-coef) lower .95 upper .95
z 0.5774 1.732 0.03585 9.297
Concordance= 0.667 (se = 0.222 )
Likelihood ratio test= 0.15 on 1 df, p=0.7
Wald test = 0.15 on 1 df, p=0.7
Score (logrank) test = 0.15 on 1 df, p=0.7