我正嘗試在R中爲survreg或flexsurvreg創建預測的生存圖。但是當我在倖存中使用多於一個預測變量時,我得到了該圖的錯誤。我想嘗試使用flexsurvreg或survreg,對於肺部數據集,我使用下面的代碼來擬合模型。R預測生存曲線R-參數法
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
您正在使用模型中的許多變量。在創建'newdata'時,您需要爲模型中的所有變量創建值。 –
謝謝羅馬。在我的模型中,我必須使用許多變量,還有另一種方法可以在調整許多變量後創建生存曲線。 – NiroshaR