set.seed(5)
d <- sampleData(80,outcome="comp")
nd <- sampleData(4,outcome="comp")
d$time <- round(d$time,1)
ttt <- sort(sample(x = unique(d$time), size = 10))
# coxph function
CSC.fit <- CSC(Hist(time,event)~ X3+X8,data=d, method = "breslow")
x= predict(CSC.fit,newdata=nd,times=1:10,cause=1,se=1L)
px=print(x)
px
predCSC <- predict(CSC.fit, newdata = d, cause = 2, times = ttt)
predCSC.se <- predict(CSC.fit, newdata = d[1:5,], cause = 2, times = ttt,
se = TRUE,keep.newdata=TRUE)
predCSC.iid <- predict(CSC.fit, newdata = d[1:5,],
cause = 2, times = ttt, iid = TRUE)
# predCSC.se$absRisk.se
# sqrt(apply(predCSC.iid$absRisk.iid[,1,]^2,1,function(x){sum(x)}))
## strata
CSC.fit.s <- CSC(list(Hist(time,event)~ strata(X1)+X2+X9,
Hist(time,event)~ X2+strata(X4)+X8+X7),data=d, method = "breslow")
predict(CSC.fit.s,cause=1,times=ttt,se=1L)
# cph function
CSC.cph <- CSC(Hist(time,event)~ X1+X2,data=d, method = "breslow", fitter = "cph")
predict(CSC.cph, newdata = d, cause = 2, times = ttt)
# landmark analysis
T0 <- 1
predCSC_afterT0 <- predict(CSC.fit, newdata = d, cause = 2, times = ttt[ttt>T0], landmark = T0)
predCSC_afterT0
Run the code above in your browser using DataLab