小编Nir*_*haR的帖子

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

我正在尝试在 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)

r survival-analysis

4
推荐指数
1
解决办法
1285
查看次数

标签 统计

r ×1

survival-analysis ×1