我想用r开发cox proportional hazard model,用它来预测输入并评估模型的准确性。对于评估,我想使用Brior score。
for /D %%D in ("*") do (
if /I not "%%~nxD"=="p%1" rd /S /Q "%%~D"
)
for %%F in ("*") do (
del "%%~F"
作为预测的结果,我期待时间(如“这个个体经历失败的时间”。相反,我得到这样的价值
# import various packages, needed at some point of the script
library("survival")
library("survminer")
library("prodlim")
library("randomForestSRC")
library("pec")
library("rpart")
library("mlr")
library("Hmisc")
library("ipred")
# load lung cancer data
data("lung")
head(lung)
# recode status variable
lung$status <- lung$status-1
# Delete rows with missing values
lung <- na.omit(lung)
# split data into training and testing
## 80% of the sample size
smp_size <- floor(0.8 * nrow(lung))
## set the seed to make your partition reproducible
set.seed(123)
train_ind <- sample(seq_len(nrow(lung)), size = smp_size)
# training and testing data
train.lung <- lung[train_ind, ]
test.lung <- lung[-train_ind, ]
# time and failure event
s <- Surv(train.lung$time, train.lung$status)
# create model
cox.ph2 <- coxph(s~age+meal.cal+wt.loss, data=train.lung)
# predict
pred <- predict(cox.ph2, newdata = train.lung)
# evaluate
sbrier(s, pred)
这是什么意思?
此外,sbrier不起作用。显然它不能与预测pred一起工作(毫不奇怪)
我该如何解决这个问题?如何使用cox.ph2进行预测?之后如何评估模型?
答案 0 :(得分:2)
predict()
函数不会返回时间值,您必须在type = c("lp", "risk","expected","terms","survival")
函数中指定参数predict()
。
如果您想获得风险比:
predict(cox.ph2, newdata = test.lung, type = "risk")
请注意,您要预测测试集上的值而不是训练集。
我已经读过你可以在你的情况下使用AFT模型: https://stats.stackexchange.com/questions/79362/how-to-get-predictions-in-terms-of-survival-time-from-a-cox-ph-model
你也可以阅读这篇文章: Calculate the Survival prediction using Cox Proportional Hazard model in R
希望它会有所帮助