我正在尝试在R中预测并绘制一个(估计的)新观察值的生存曲线。使用“survival”库和“lung”数据集,我首先对数据进行了Cox比例风险模型拟合。然后,我试图预测并绘制一个假想的新观察值的生存曲线(我在“list”命令中输入了此假想新观察值的详细信息)。但是,这不起作用。
以下是我的代码:
#load library
library(survival)
data(lung)
#create survival object
s <- with(lung,Surv(time,status))
#create model
modelA <- coxph(s ~ as.factor(sex)+age+ph.ecog+wt.loss+ph.karno,data=lung, model=TRUE)
summary(modelA)
#plot
plot(survfit(modelA), ylab="Probability of Survival",
xlab="Time", col=c("red", "black", "black"))
#predict for a hypothetical NEW observation (here is where the error is)
lines(predict(modelA, newdata=list(sex=1,
age = 56,
ph.ecog = 1,
ph.karno = 50,
wt.loss = 11),
type="quantile",
p=seq(.01,.99,by=.01)),
seq(.99,.01,by=-.01),
col="blue")
## Error in match.arg(type) :
## 'arg' should be one of “lp”, “risk”, “expected”, “terms”, “survival”
有人知道我做错了什么吗?谢谢
survreg()
函数不运行比例风险模型,在这种情况下应该使用coxph()
函数。 - Vasily A