data(dataDIVAT2)
dataDIVAT2$train <- 1*rbinom(n=dim(dataDIVAT2)[1], size = 1, prob=1/3)
# The training of the super learner with 2 algorithms
sl<-sl.time(method=c("cox.ridge", "aft.ggamma"), metric="ribs",
data=dataDIVAT2[dataDIVAT2$train==1,], times="times", failures="failures", pro.time = 12,
cov.quanti=c("age"), cov.quali=c("hla", "retransplant", "ecd"), cv=3)
# Individual prediction for 2 new subjects
pred <- predict(sl,
newdata=data.frame(age=c(52,52), hla=c(0,1), retransplant=c(1,1), ecd=c(0,1)))
plot(y=pred$predictions$sl[1,], x=pred$times, xlab="Time (years)", ylab="Predicted survival",
col=1, type="l", lty=1, lwd=2, ylim=c(0,1))
lines(y=pred$predictions$sl[2,], x=pred$times, col=2, type="l", lty=1, lwd=2)
legend("bottomright", col=c(1,2), lty=1, lwd=2, c("Subject #1", "Subject #2"))
Run the code above in your browser using DataLab