### 理解gbm生存预测模型

我是一个使用和理解机器学习方法的新手,目前正在使用R语言中的gbm包进行生存分析。

我难以理解生存预测模型的一些输出。我已经查看了这个教程和这个帖子,但仍然难以理解输出的生存预测模型。

以下是我基于示例数据的分析代码:

rm(list=ls(all=TRUE))library(randomForestSRC)library(gbm)library(survival)library(Hmisc)data(pbc, package="randomForestSRC")data <- na.omit(pbc)set.seed(9512)train <- sample(1:nrow(data), round(nrow(data)*0.7))data.train <- data[train, ]data.test <- data[-train, ]set.seed(9741)model <- gbm(Surv(days, status)~.,           data.train,           interaction.depth=2,           shrinkage=0.01,           n.trees=500,           distribution="coxph",           cv.folds = 5)summary(model)best.iter <- gbm.perf(model, plot.it = TRUE, method = 'cv',                      overlay = TRUE) #to get the optimal number of Boosting iterationsbest.iter#Us the best number of tree to produce predicted values for each observation in newdata # return a vector of prediction on n.trees indicting log hazard scale.f(x)# By default the predictions are on log hazard scale for coxph# proportional hazard model assumes h(t|x)=lambda(t)*exp(f(x)).# estimate the f(x) component of the hazard functionpred.train <- predict(object=model, newdata=data.train, n.trees = best.iter)pred.test <- predict(object=model, newdata=data.test, n.trees = best.iter)#trainig setHmisc::rcorr.cens(-pred.train, Surv(data.train$days, data.train$status))#val setHmisc::rcorr.cens(-pred.test, Surv(data.test$days, data.test$status))# Estimate the cumulative baseline hazard function using training databasehaz.cum <- basehaz.gbm(t=data.train$days,       #The survival times.                           delta=data.train$status, #The censoring indicator                           f.x=pred.train,          #The predicted values of the regression model on the log hazard scale.                           t.eval = data.train$days,  #Values at which the baseline hazard will be evaluated                           cumulative = TRUE,       #If TRUE the cumulative survival function will be computed                           smooth = FALSE)          #If TRUE basehaz.gbm will smooth the estimated baseline hazard using Friedman's super smoother supsmu.basehaz.cum#Estimation of survival rate of all:surv.rate <- exp(-exp(pred.train)*basehaz.cum)surv.rateres_train <- data.train# predicted outcome for train setres_train$pred <- pred.trainres_train$survival_rate <- surv.rateres_train# Estimate the cumulative baseline hazard function using training databasehaz.cum <- basehaz.gbm(t=data.test$days,       #The survival times.                           delta=data.test$status, #The censoring indicator                           f.x=pred.test,          #The predicted values of the regression model on the log hazard scale.                           t.eval = data.test$days,  #Values at which the baseline hazard will be evaluated                           cumulative = TRUE,       #If TRUE the cumulative survival function will be computed                           smooth = FALSE)          #If TRUE basehaz.gbm will smooth the estimated baseline hazard using Friedman's super smoother supsmu.basehaz.cum#Estimation of survival rate of all at specified time is:surv.rate <- exp(-exp(pred.test)*basehaz.cum)surv.rateres_test <- data.test# predicted outcome for test setres_test$pred <- pred.testres_test$survival_rate <- surv.rateres_test#--------------------------------------------------#Estimate survival rate at time of interest# Specify time of interesttime.interest <- sort(unique(data.train$days[data.train$status==1]))# Estimate the cumulative baseline hazard function using training databasehaz.cum <- basehaz.gbm(t=data.train$days,       #The survival times.                           delta=data.train$status, #The censoring indicator                           f.x=pred.train,          #The predicted values of the regression model on the log hazard scale.                           t.eval = time.interest,  #Values at which the baseline hazard will be evaluated                           cumulative = TRUE,       #If TRUE the cumulative survival function will be computed                           smooth = FALSE)          #If TRUE basehaz.gbm will smooth the estimated baseline hazard using Friedman's super smoother supsmu.#For individual $i$ in test set, estimation of survival function is:surf.i <- exp(-exp(pred.test[1])*basehaz.cum) #survival rate#Estimation of survival rate of all at specified time is:specif.time <- time.interest[10]surv.rate <- exp(-exp(pred.test)*basehaz.cum[10])cat("Survival Rate of all at time", specif.time, "\n")print(surv.rate)

predict函数返回的输出代表了危险函数的f(x)部分(即h(t|x)=lambda(t)*exp(f(x)))。

我的问题:

• 我有点困惑,这里是否可以计算危险比?

• 我想知道如何将人群分为低风险和高风险组?我能否依赖于危险函数的估计f(x)部分来对训练集进行评分系统?我希望从中建立一个评分系统,展示训练集和测试集中低风险和高风险组的KM图。

• 我如何构建校准曲线图,绘制训练集和测试集的观察生存率与预测生存率?


回答:

感谢您阅读我的教程!

正如您提到的“predict函数返回的输出代表了危险函数的f(x)部分(即h(t|x)=lambda(t)*exp(f(x)))”,我们可能需要理解危险函数,即h(t|x)。

在此之前,请确保您已经具备了生存分析的基础知识。如果没有,建议阅读这个很棒的帖子。我认为这个帖子会帮助您解决这些问题。

回到您的问题上:

  • 确实,我们可以通过调用predict函数获取对数尺度的危险比。因此,可以通过exp()计算危险比。
  • 当然!根据危险比的值,我们可以将人群分为低风险和高风险组。或者,您可以使用危险比的中位数作为 cutoff 值。我认为 cutoff 值应该从训练集中得出,然后在测试集中进行测试。如果您的模型有效,低风险和高风险组的KM图将会表现出显著差异(通过统计上的log-rank测试测量)。
  • 校准曲线图通常用于评估输出概率或可能性范围在[0.0, 1.0]之间的模型的性能。我们可以计算生存函数,然后指定感兴趣的时间点,例如5年。最后,我们将生存概率与指定时间的实际生存状态进行比较,这与评估二分类模型的方式相同。获取生存函数的更多细节可以参考我的教程,而相关原理可以在前述帖子中找到。

Related Posts

LensKit推荐系统仅对某些用户返回结果,其他情况下返回空DataFrame。这是为什么?

我在尝试使用Django框架实现一个群体推荐系统,并使…

如何在Python中将一个列中的字符串值与其他列名匹配

数据框: MovieID movieCater 1 A…

AttributeError: ‘Pipeline’ 对象没有属性 ‘get_feature_names’

我构建了一个如下所示的 Pipeline: Pipel…

令人惊讶的测试/训练集大数组

我正在尝试使用包含157673条记录的数据集,通过线性…

训练数据集和测试数据集可以分开而不是分割

已关闭。 此问题不符合 Stack Overflow …

如何使用留一法预测多列的Y值,使用SKlearn?

我有一个示例数据框,如下所示。Y列全部包含0,1的二元…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注