#竞争风险模型
tmp <- data.frame(gene = tiaoxuan[,5:6],OS.Time = Train[,"Survival_months"], OS = Train[,"CSS"],stringsAsFactors = F)
colnames(tmp)
#方法1:riskregression
library(riskRegression)
fgr1<-FGR(Hist(OS.Time,OS)~gene.Cancer_directed_surgery+gene.Systemic_therapy,data = tmp,cause = 1)#方法2:cmprsk
library(cmprsk)
help(package="cmprsk")
CIF <- cuminc(ftime = tmp$OS.Time, fstatus =tmp$OS, group = tmp$gene.Cancer_directed_surgery, cencode = 0)
CIF
vars <- tmp[, c("gene.Cancer_directed_surgery","gene.Systemic_therapy")] %>% sapply(.,as.numeric)
str(tmp)
fit <- crr(ftime=tmp$OS.Time, fstatus=tmp$OS, vars,failcode=1,cencode = 0) ##拟合模型
summary(fit)#mstate:构建列线图
#方法1
library(mstate)
tmp$id<-1:1193
df.w <- crprep("OS.Time", "OS",data=tmp, trans=c(1,2),id="id",cens=0,keep=c("gene.Cancer_directed_surgery","gene.Systemic_therapy"))
df.w$Time<- df.w$Tstop - df.w$Tstart
cox <- coxph(Surv(Time,status==1)~ gene.Cancer_directed_surgery+gene.Systemic_therapy, data=df.w[df.w$failcode==1,],weight=weight.cens,subset=failcode==1)
cox
library(regplot)
regplot(cox)
#方法2
#install.packages("QHScrnomo")
library(QHScrnomo)
help(package="QHScrnomo")
dd <- datadist(tmp)
options(datadist = "dd")
prostate.f <- cph(Surv(OS.Time,OS == 1) ~ gene.Cancer_directed_surgery+gene.Systemic_therapy,data = tmp,x = TRUE, y= TRUE, surv=TRUE,time.inc = 12)
prostate.crr <- crr.fit(prostate.f,cencode = 0,failcode = 1)
## make a CRR nomogram
nomogram.crr(prostate.crr,failtime = 12,lp=FALSE,funlabel = "Predicted 1-year cumulative incidence")
值得注意的是,使用crprep构建模型的系数与上述两种方法相近但是不一致,知道原因的同志欢迎在评论区留言。