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

Nir*_*haR 4 r survival-analysis

我正在尝试在 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")
Run Code Online (Sandbox Code Playgroud)

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

> 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
Run Code Online (Sandbox Code Playgroud)

Hac*_*k-R 6

我们需要为模型中的每个变量赋予值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")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述