美文网首页
2020-01-16 生存曲线和ROC曲线代码

2020-01-16 生存曲线和ROC曲线代码

作者: 海阔天空周 | 来源:发表于2020-01-16 08:51 被阅读0次

    libiary(survival)

    library(survivalROC)

    fit_curve_train4<-survfit(Surv(life_span,status)~risk,data = risk_train4data)

    plot(fit_curve_train4,,col=c("red","blue"),xlab = "time(years)",ylab = "survival rate",

        main="survival curve of train set",mark.time=T)

    legend(5,.4,paste("High risk (n=",nrow(risk_train4data[risk_train4data[,5]=="high",]),")",sep = ""),lty = NULL,text.col = "red",bty = "n")

    legend(5,.3,paste("Low risk (n=",nrow(risk_train4data[risk_train4data[,5]=="low",]),")",sep = ""),lty = NULL,text.col = "blue",bty = "n")

    legend(15,.2,paste("P value =",p_value_train4,sep = ""),lty = NULL,col = "black",bty = "n")

    fit_curve_test4<-survfit(Surv(life_span,status)~risk,data = risk_test4data)

    plot(fit_curve_test4,,col=c("red","blue"),xlab = "time(years)",ylab = "survival rate",

        main="survival curve of test set",mark.time=T)

    legend(5,.4,paste("High risk (n=",nrow(risk_test4data[risk_test4data[,5]=="high",]),")",sep = ""),lty = NULL,text.col = "red",bty = "n")

    legend(5,.3,paste("Low risk (n=",nrow(risk_test4data[risk_test4data[,5]=="low",]),")",sep = ""),lty = NULL,text.col = "blue",bty = "n")

    legend(15,.2,paste("P value =",p_value_test4,sep = ""),lty = NULL,col = "black",bty = "n")

    fit_curve_all_set4<-survfit(Surv(life_span,status)~risk,data = all_set4)

    plot(fit_curve_all_set4,col=c("red","blue"),xlab = "time(years)",ylab = "survival rate",

        main="survival curve of all set",mark.time=T)

    legend(5,.4,paste("High risk (n=",nrow(all_set4[all_set4[,5]=="high",]),")",sep = ""),lty = NULL,text.col = "red",bty = "n")

    legend(5,.3,paste("Low risk (n=",nrow(all_set4[all_set4[,5]=="low",]),")",sep = ""),lty = NULL,text.col = "blue",bty = "n")

    legend(15,.2,paste("P value =",p_value_all4,sep = ""),lty = NULL,col = "black",bty = "n")

    ##绘制ROC 曲线

    roc<-survivalROC(Stime = risk_train4data$life_span,status = risk_train4data$status,marker = risk_train4data$riskscore,

                    predict.time = 5,method = "KM")

    plot(roc$FP,roc$TP,type = "l",xlim = c(0,1),ylim = c(0,1),col="green")

    roc$AUC

    roctest4<-survivalROC(Stime = risk_test4data$life_span,status = risk_test4data$status,marker = risk_test4data$riskscore,

                    predict.time = 5,method = "KM")

    plot(roctest4$FP,roctest4$TP,type = "l",xlim = c(0,1),ylim = c(0,1),col="green")

    rocall4<-survivalROC(Stime = all_set4$life_span,status = all_set4$status,marker = all_set4$riskscore,

                          predict.time = 5,method = "KM")

    plot(rocall4$FP,rocall4$TP,type = "l",xlim = c(0,1),ylim = c(0,1),col="green")

    相关文章

      网友评论

          本文标题:2020-01-16 生存曲线和ROC曲线代码

          本文链接:https://www.haomeiwen.com/subject/cjtfzctx.html