簡體   English   中英

Cox ph的出色預測准確性

[英]Extimate prediction accuracy of cox ph

我想用r開發一個cox比例風險模型 ,用它來預測輸入並評估模型的准確性。 為了進行評估,我想使用Brior評分

# 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) 

作為預測的結果,我希望有一定的時間(如“何時該個體遇到失敗)。相反,我得到了這樣的值

[1]  0.017576359 -0.135928959 -0.347553969  0.112509137 -0.229301199 -0.131861582  0.044589175  0.002634008
[9]  0.345966978  0.209488560  0.002418358  

這意味着什么?

此外,更聰明的行不通。 顯然,它不能與預測謂詞配合使用(在此不足為奇)

我該如何解決? 如何使用cox.ph2進行預測? 之后如何評估模型?

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模型

您也可以閱讀以下文章: 使用R中的Cox比例危害模型計算生存預測

希望對你有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM