library(mstate)
help(package="mstate")
data(aidssi)
aidssi.w <- crprep("time", "cause", data=aidssi, trans=c("AIDS","SI"),
cens="event-free", id="patnr", keep="ccr5")
#计算特殊原因累积率
ci <- Cuminc(aidssi$time, aidssi$status)
#结局事件1"AIDS"
sf <- survfit(Surv(Tstart,Tstop,status=="AIDS")~1, data=aidssi.w,
weight=weight.cens, subset=failcode=="AIDS")
plot(sf, fun="event", mark.time=FALSE)
lines(CI.1~time,data=ci,type="s",col="red")
#结局事件2"SI"
sf <- survfit(Surv(Tstart,Tstop,status=="SI")~1, data=aidssi.w,
weight=weight.cens, subset=failcode=="SI")
plot(sf, fun="event", mark.time=FALSE)
lines(CI.2~time,data=ci,type="s",col="red")
# Fine and Gray 回归:结局事件1"AIDS"
cw <- coxph(Surv(Tstart,Tstop,status=="AIDS")~ccr5, data=aidssi.w,
weight=weight.cens, subset=failcode=="AIDS")
cw
#与crr (cmprsk)的结果对比
crr(ftime=aidssi$time, fstatus=aidssi$status, cov1=as.numeric(aidssi$ccr5)) %>% summary
# Gray's log-rank 检验
aidssi.wCCR <- crprep("time", "cause", data=aidssi, trans=c("AIDS","SI"),
cens="event-free", id="patnr", strata="ccr5")
test.AIDS <- coxph(Surv(Tstart,Tstop,status=="AIDS")~ccr5, data=aidssi.wCCR,
weights=weight.cens, subset=failcode=="AIDS")
test.SI <- coxph(Surv(Tstart,Tstop,status=="SI")~ccr5, data=aidssi.wCCR,
weights=weight.cens, subset=failcode=="SI")
#统计量和P值
c(test.AIDS$score, 1-pchisq(test.AIDS$score,1)) # AIDS
c(test.SI$score, 1-pchisq(test.SI$score,1)) # SI
# 与cuminc (cmprsk)结果对比
with(aidssi, cuminc(time, status, group=ccr5)$Tests)
值得注意的是上述结果与cuminc (cmprsk)并不完全相同。