Solved – How to make prediction in survival analysis using R

predictionrsurvival

I have fitted a survival model in R which is below. However, I am not sure how to make predictions. I tried predicting the survival probability that a patient whose design matrix is X lives longer than 100 days, but no matter what design matrix I use, the probability is always 0. What do you think I am doing wrong?

library(survival)
attach
weibull <- survreg(Surv(time,status)~celltype + karno+diagtime+age+prior+trt ,dist="w")
beta[,1] <- as.matrix(c(weibull$coef))
x <- as.matrix(c(1,1,0,0,80,10,65,0,2)) #Design matrix
lambda <- beta[,1]%*%x
1 - (1 - exp(-lambda*100))

Best Answer

This is the code, copied & pasted from the help file to the function predict.survreg, which relates to predicting Weibull models:

lfit <- survreg(Surv(time, status) ~ ph.ecog, data=lung)
pct <- 1:98/100   # The 100th percentile of predicted survival is at +infinity
ptime <- predict(lfit, newdata=data.frame(ph.ecog=2), type='quantile',
                 p=pct, se=TRUE)
matplot(cbind(ptime$fit, ptime$fit + 2*ptime$se.fit,
                             ptime$fit - 2*ptime$se.fit)/30.5, 1-pct,
        xlab="Months", ylab="Survival", type='l', lty=c(1,2,2), col=1)

Hope this helps.

Related Question