到目前为止,我已经达到了将模型用于survreg函数,如下所示:
model <- survreg(formula = Surv(TimeDeath, event) ~ age + BM1 + BM2 +
mutation + sex + BM1:BM2 + BM1:mutation,
data = DF, dist = "lognormal")
现在,我需要预测一名51岁的男性患者的失败时间,他没有基因突变,而对于BM1,他的值为3.7 mg / dL,BM2的值为251 mg / dL。
我继续如下:
ND <- with(DF, data.frame(
age = rep(seq(min(age), max(age), length.out = 20), 2),
BM1 = rep(seq(min(BM1), max(BM1), length.out = 20), 2),
BM2 = rep(seq(min(BM2), max(BM2), length.out = 20), 2),
mutation = c("No", "Yes"),
sex = c("male", "40")
))
prs <- predict(model_final, ND, se.fit = TRUE, type = "lp")
ND$pred <- prs[[1]]
ND$se <- prs[[2]]
ND$lo <- exp(ND$pred - 1.96 * ND$se)
ND$up <- exp(ND$pred + 1.96 * ND$se)
ND$pred <- exp(ND$pred)
library(lattice)
xyplot(pred + lo + up ~ age + BM1, data = ND, type = "l",
lty = c(1,2,2), col = "black", lwd = 4, xlab = "Age",
ylab = "Survival Time")
我知道我没有正确定义ND对象,但我不知道该怎么做,还有绘图功能。
请帮忙吗?
答案 0 :(得分:0)
看看?predict.survreg
。 CI的构建确实看起来很可疑,我原以为你会设置se.fit=TRUE
有一个新的数据参数,你可以在其中包含预测所需的参数作为newdata参数的一部分:
all.combos < expand.grid( mutation=c("No", "Yes"), BM1= 3.7 , BM2= 251 ,
sex = c("male", "40"),
age-seq(min(age), max(age), length.out = 20) ) )
preds.combos <- predict(model, all.combos, se.fit=TRUE)