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