生存树R中带rpart的ROC曲线
我在为我的生存树创建ROC曲线时遇到了一个问题,该生存树是由rpart包创建的。我的目标是通过ROC曲线中的曲线下面积(AUC)来评估我的存活树。我尝试了很多方法来绘制ROC曲线,但都失败了。我怎样才能进入下一步——ROC曲线图 以下是我目前掌握的R代码:生存树R中带rpart的ROC曲线,r,decision-tree,roc,rpart,survival,R,Decision Tree,Roc,Rpart,Survival,我在为我的生存树创建ROC曲线时遇到了一个问题,该生存树是由rpart包创建的。我的目标是通过ROC曲线中的曲线下面积(AUC)来评估我的存活树。我尝试了很多方法来绘制ROC曲线,但都失败了。我怎样才能进入下一步——ROC曲线图 以下是我目前掌握的R代码: library(survival) library("rpart") library("partykit") library(rattle) library(rpart.plot) temp =
library(survival)
library("rpart")
library("partykit")
library(rattle)
library(rpart.plot)
temp = coxph(Surv(pgtime, pgstat) ~ age+eet+g2+grade+gleason+ploidy, stagec)
newtime = predict(temp, type = 'expected')
fit <- rpart(Surv(pgtime, pgstat) ~ age+eet+g2+grade+gleason+ploidy, data = stagec)
fancyRpartPlot(fit)
tfit <- as.party(fit) #Transfer "rpart" to "party"
predtree<-predict(tfit,newdata=stagec,type="prob") #Prediction
我尝试推导每个终端节点的生存函数值,并使用这些值绘制ROC曲线。这是正确的吗?以这种方式绘制的ROC曲线似乎将预测的分类结果视为连续变量,而不是分类变量
这是我试过的R代码:
tree2 = fit
tree2$frame$yval = as.numeric(rownames(tree2$frame))
#Get the survival function value of each sample
Surv_value = data.frame(predict(tree2, newdata=stagec,type = "matrix"))[,1]
Out=data.frame()
Out=cbind(stagec,Surv_value)
#ROC
library(survivalROC)
roc=survivalROC(Stime=Out$pgtime, status=Out$pgstat, marker = Out$Surv_value, predict.time =5, method="KM")
roc$AUC #Get the AUC of ROC plot
#Plot ROC
aucText=c()
par(oma=c(0.5,1,0,1),font.lab=1.5,font.axis=1.5)
plot(roc$FP, roc$TP, type="l", xlim=c(0,1), ylim=c(0,1),col="#f8766d",
xlab="False positive rate", ylab="True positive rate",
lwd = 2, cex.main=1.3, cex.lab=1.2, cex.axis=1.2, font=1.2)
aucText=c(aucText,paste0("498"," (AUC=",sprintf("%.3f",roc$AUC),")"))
legend("bottomright", aucText,lwd=2,bty="n",col=c("#f8766d","#00bfc4","blue","green"))
abline(0,1)
你看了吗?你能给我们看看你已经试过的吗?谢谢!在编辑的问题中,我更新了我尝试的所有方法@卡里莫斯坦克斯!我在你提到的帖子中尝试过这种方法。已编辑问题中的R代码已更新,但仍报告错误。我猜这可能是因为这种方法不适合“生存”对象@你看过吗?你能给我们看看你已经试过的吗?谢谢!在编辑的问题中,我更新了我尝试的所有方法@卡里莫斯坦克斯!我在你提到的帖子中尝试过这种方法。已编辑问题中的R代码已更新,但仍报告错误。我猜这可能是因为这种方法不适合“生存”对象@江户
predict(tfit, newdata = stagec, type = "prob")[[1]]
Call: survfit(formula = y ~ 1, weights = w, subset = w > 0)
n events median 0.95LCL 0.95UCL
33 1 NA NA NA
tree2 = fit
tree2$frame$yval = as.numeric(rownames(tree2$frame))
#Get the survival function value of each sample
Surv_value = data.frame(predict(tree2, newdata=stagec,type = "matrix"))[,1]
Out=data.frame()
Out=cbind(stagec,Surv_value)
#ROC
library(survivalROC)
roc=survivalROC(Stime=Out$pgtime, status=Out$pgstat, marker = Out$Surv_value, predict.time =5, method="KM")
roc$AUC #Get the AUC of ROC plot
#Plot ROC
aucText=c()
par(oma=c(0.5,1,0,1),font.lab=1.5,font.axis=1.5)
plot(roc$FP, roc$TP, type="l", xlim=c(0,1), ylim=c(0,1),col="#f8766d",
xlab="False positive rate", ylab="True positive rate",
lwd = 2, cex.main=1.3, cex.lab=1.2, cex.axis=1.2, font=1.2)
aucText=c(aucText,paste0("498"," (AUC=",sprintf("%.3f",roc$AUC),")"))
legend("bottomright", aucText,lwd=2,bty="n",col=c("#f8766d","#00bfc4","blue","green"))
abline(0,1)