R-参数方法中的预测生存曲线

predicted survival curve in R- Parametric method

我正在尝试在 R 中为 survreg 或 flexsurvreg 创建预测生存图。但是当我在 survreg 中使用多个预测变量时,我得到了该图的错误。我想尝试使用 flexsurvreg 或 survreg,对于肺部数据集,我使用以下代码来拟合模型。

require(survival)
s <- with(lung,Surv(time,status))

sWei  <- survreg(s ~ as.factor(sex)+age+ph.ecog+wt.loss+ph.karno,dist='weibull',data=lung)

fitKM <- survfit(s ~ sex,data=lung)
plot(fitKM)

lines(predict(sWei, newdata=list(sex=1),type="quantile",p=seq(.01,.99,by=.01)),seq(.99,.01,by=-.01),col="blue")
lines(predict(sWei, newdata=list(sex=2),type="quantile",p=seq(.01,.99,by=.01)),seq(.99,.01,by=-.01),col="red")

当我使用上面的命令进行绘图时出现错误。请让我知道我在绘制预测生存曲线时哪里做错了。

> lines(predict(sWei, newdata=list(sex=1),type="quantile",p=seq(.01,.99,by=.01)),seq(.99,.01,by=-.01),col="red")
Error in eval(expr, envir, enclos) : object 'age' not found

我们需要将 list 中的值赋予模型中的每个变量,以便它可以绘制曲线。

require(survival)
s <- with(lung,Surv(time,status))

sWei  <- survreg(s ~ as.factor(sex)+age+ph.ecog+wt.loss+ph.karno,dist='weibull',data=lung)

fitKM <- survfit(s ~ sex,data=lung)
plot(fitKM)

lines(predict(sWei, newdata=list(sex=1, 
                                 age = 1, 
                                 ph.ecog = 1, 
                                 ph.karno = 90,
                                 wt.loss = 2),
                                 type="quantile",
                                 p=seq(.01,.99,by=.01)),
                                 seq(.99,.01,by=-.01),
                                 col="blue")
lines(predict(sWei, newdata=list(sex=2, 
                                 age = 1, 
                                 ph.ecog = 1, 
                                 ph.karno = 90,
                                 wt.loss = 2),
                                 type="quantile",
                                 p=seq(.01,.99,by=.01)),
                                 seq(.99,.01,by=-.01),
                                 col="red")