library(timeROC)
library(survival)
library(ggplot2)
train12<-na.omit(lung)
table(train12$status)
moxing<-coxph(Surv(time,status)~age+sex,train12)
train12$marker<-predict(moxing)
ROC_1<-timeROC(T=train12$time,delta=train12$status,
marker=train12$marker,cause=2,
weighting="cox",
times=c(365,730),ROC=TRUE)
ROC_1$FP_1
ggplot() +
geom_line(aes(x=ROC_1[["FP_1"]][,1],y=ROC_1[["TP"]][,1],color="1 year"),size=1.2)+
geom_line(aes(x=ROC_1[["FP_1"]][,2],y=ROC_1[["TP"]][,2],color="2 years"),size=1.2)+
geom_abline(intercept = 0, slope = 1, linetype="dotted")+
labs(title="ROC Curve", x="1 - Specificity", y="Sensitivity", color="Timepoint")+
scale_color_manual(values=c("#009E73","#D55E00","#0072B2"))+
annotate("text", x=0.8, y=0.2, label=paste0("AUC (1 year) = ",round(ROC_1$AUC_1,2)), color="black", size=3.5) +
annotate("text", x=0.8, y=0.15, label=paste0("AUC (2 years) = ",round(ROC_1$AUC_2,2)), color="red", size=3.5)