简体   繁体   中英

Predict function in survreg in r

I have this model in survival analysis:

full_model_lognormal <- survreg(Surv(DF$TimeDeath, DF$event) ~ age + sex + mutation +BM1 + BM2, data = DF,
                             dist = "lognormal")

I need to calculate the expected failure time of a male patient who is 51 years old, no gene mutation, and for BM1 he had the value 3.7 mg/dL and for BM2 the value 251 mg/dL.

I need to do it using the predict function, any help?

This question is really a duplicate: Finding the mean of the log-normal distribution in survival analysis in R

but cannot mark it as such because the answer (mine) has no upvotes or checkmark:

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)
 # The plot should be examined since you asked for a median survival time
 abline(h= 0.5)
 # You can  drop a vertical from the intersection to get that graphically 
.... or ...
 str(ptime)
List of 2
 $ fit   : num [1:98] 9.77 16.35 22.13 27.46 32.49 ...
 $ se.fit: num [1:98] 2.39 3.53 4.42 5.16 5.82 ...

You can extract the 50th percentile (which is the median survival) from that sequence of survival times with:

ptime$fit[which((1-pct)==0.5)]
# [1] 221.6023   

If you wanted to get mean time you would not want to use a "100th quantile" since it is Infinity. You could, I suppose, calculate the mean of the 0.1-0.99 quantiles and divide by 0.99.

For predicting the response you can do something like the following:

require(survival)
fit <- survreg(Surv(time,status) ~ age + I(age^2), data=stanford2, 
               dist='lognormal') 
pred <- predict(fit, newdata=list(age=1:65), type='quantile', 
                p=c(.1, .5, .9))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM