BioNews,專注於報導生命科學領域相關新聞,長按下方二維碼即可關注"BioNews"(id : iBioNews)
概念通常我們對於biomarker的預測模型會用ROC曲線來評價其性能,但是對於一些生存資料數據的預測模型或者需要加入時間因素,則會使用時間依賴(time dependent)的ROC曲線
傳統的ROC曲線分析方法認為個體的事件(疾病)狀態和markers是隨著時間的推移而固定的,但在臨床流行病學研究中,疾病狀態和markers都是隨著時間的推移而變化的(即time-to-event outcomes)。早期無病的個體由於研究隨訪時間較長,可能較晚發病,而且其markers可能在隨訪期間較基線發生變化。如果使用傳統的ROC會忽略疾病狀態或markers的時間依賴性,此時用隨時間變化的time-dependent ROC(時間相依ROC)比較合適。來自---真實世界大數據分析系列|ROC曲線與Time-dependent ROC 曲線
對於常規的ROC曲線,在之前的筆記(理解ROC和AUC)中對其原理做了簡單的介紹,而time-dependent ROC曲線的原理與常規的ROC曲線比較類似,前者相比後者多了時間因素,以便我們可以根據不同時間節點繪製不同的ROC曲線
本質上ROC曲線可以根據靈敏度和特異度兩個指標來繪製的,所以我們通過比較常規的ROC曲線和time-dependent的ROC曲線對於靈敏度和特異度的計算公式即可明白兩者的差別了
公式可以參考真實世界大數據分析系列|ROC曲線與Time-dependent ROC 曲線和時間依賴性ROC曲線(一),雖然兩者公式的表現形式不同,但是細想下,其實是同一個意思
上述說的是Cumulative case/dynamic control ROC,另外還有一種Incident case/dynamic control ROC(似乎不太常見),可參考:Time-dependent ROC for Survival Prediction Models in R
實現方式對於R中time-dependent ROC的實現方式,我一般會用timeROC和survivalROC包,當然還有其他的包(聽說。。未嘗試過),如:tdROC, timereg, risksetROC和survAUC
timeROC包相比survivalROC包會多計算個AUC的置信區間
若數據是生存資料數據,那麼還會有不同的處理刪除(censoring)方式,如Kaplan-Meier(KM), Cox model以及NNE(Nearest Neighbor Estimation)等等
下面以survivalROC包的mayo數據為例,其中mayoscore5和mayoscore4是兩個marker,ROC曲線的繪製則用timeROC包
library(timeROC)library(survival)
data(mayo)
time_roc_res <- timeROC(T = mayo$time,delta = mayo$censor,marker = mayo$mayoscore5,cause = 1,weighting="marginal",times = c(3 * 365, 5 * 365, 10 * 365),ROC = TRUE,iid = TRUE)計算AUC值及其置信區間> time_roc_res$AUC t=1095 t=1825 t=3650 0.8982790 0.9153621 0.8576153查看AUC的95%置信區間
> confint(time_roc_res, level = 0.95)$CI_AUC 2.5% 97.5%t=1095 85.01 94.64t=1825 87.42 95.65t=3650 79.38 92.14繪製time-dependent ROC曲線簡單繪製下time-dependent ROC曲線(這裡的plot函數對應的是timeROC::plot.ipcwsurvivalROC函數)
plot(time_roc_res, time=3 * 365, col = "red", title = FALSE) plot(time_roc_res, time=5 * 365, add=TRUE, col="blue") plot(time_roc_res, time=10 * 365, add=TRUE, col="green") legend("bottomright",c("3 Years" ,"5 Years", "10 Years"), col=c("red", "blue", "green"), lty=1, lwd=2)time-dependent-ROC1
也可以通過修改在再美觀點,如:
time_ROC_df <- data.frame(TP_3year = time_roc_res$TP[, 1],FP_3year = time_roc_res$FP[, 1],TP_5year = time_roc_res$TP[, 2],FP_5year = time_roc_res$FP[, 2],TP_10year = time_roc_res$TP[, 3],FP_10year = time_roc_res$FP[, 3])library(ggplot2)ggplot(data = time_ROC_df) +geom_line(aes(x = FP_3year, y = TP_3year), size = 1, color = "#BC3C29FF") +geom_line(aes(x = FP_5year, y = TP_5year), size = 1, color = "#0072B5FF") +geom_line(aes(x = FP_10year, y = TP_10year), size = 1, color = "#E18727FF") +geom_abline(slope = 1, intercept = 0, color = "grey", size = 1, linetype = 2) +theme_bw() +annotate("text",x = 0.75, y = 0.25, size = 4.5,label = paste0("AUC at 3 years = ", sprintf("%.3f", time_roc_res$AUC[[1]])), color = "#BC3C29FF" ) +annotate("text",x = 0.75, y = 0.15, size = 4.5,label = paste0("AUC at 5 years = ", sprintf("%.3f", time_roc_res$AUC[[2]])), color = "#0072B5FF" ) +annotate("text",x = 0.75, y = 0.05, size = 4.5,label = paste0("AUC at 10 years = ", sprintf("%.3f", time_roc_res$AUC[[3]])), color = "#E18727FF" ) +labs(x = "False positive rate", y = "True positive rate") +theme(axis.text = element_text(face = "bold", size = 11, color = "black"),axis.title.x = element_text(face = "bold", size = 14, color = "black", margin = margin(c(15, 0, 0, 0))),axis.title.y = element_text(face = "bold", size = 14, color = "black", margin = margin(c(0, 15, 0, 0))) )time-dependent-ROC2比較兩個time-dependent AUC按照上述方式對mayoscore4marker做類似的分析
time_roc_res2 <- timeROC(T = mayo$time,delta = mayo$censor,marker = mayo$mayoscore4,cause = 1,weighting="marginal",times = c(3 * 365, 5 * 365, 10 * 365),ROC = TRUE,iid = TRUE)> time_roc_res2$AUCt=1095 t=1825 t=3650 0.8454230 0.8285379 0.7667952然後通過compare函數進行比較,並輸出矯正後的P值和相關係數矩陣,假設檢驗的原假設是兩個AUC是相等的
> compare(time_roc_res, time_roc_res2, adjusted = TRUE)$p_values_AUC t=1095 t=1825 t=3650Non-adjusted 0.007250057 2.022776e-05 0.006565526Adjusted 0.020362878 5.796255e-05 0.018496963
$Cor [,1] [,2] [,3][1,] 1.0000000 0.6222982 0.1760154[2,] 0.6222982 1.0000000 0.2813782[3,] 0.1760154 0.2813782 1.0000000接著可通過plotAUCcurve函數繪製不同時間節點的AUC曲線及其置信區間,也可將多個ROC曲線的AUC值放在一起繪製(節點多一點,曲線會展示的更加細緻一點)
plotAUCcurve(time_roc_res, conf.int=TRUE, col="red")plotAUCcurve(time_roc_res2, conf.int=TRUE, col="blue", add=TRUE)legend("bottomright",c("mayoscore5", "mayoscore4"), col = c("red","blue"), lty=1, lwd=2)time-dependent-ROC3ROC的最佳閾值(cutoff)一般來說,對於一個biomarker或者簡單的說診斷指標/試劑,我們使用ROC曲線計算出AUC值後,還會根據ROC曲線的最佳閾值來確定其靈敏度和特異度,有時在研究中,還會用於KM曲線的分類指標
確定閾值的方法很多,一般會用最常見的約登指數(Youden index),即敏感度+特異性-1;有時也會考慮用其他確定閾值的方法,比如Minimum ROC distance, Misclassification Cost Term等等
對於上述timeROC的結果,如3年ROC曲線的約登指數(因為TP代表的是True Positive fraction,即sensitivity;而FP代表的是False Positive fraction,即1-specificity):
> mayo$mayoscore5[which.max(time_ROC_df$TP_3year - time_ROC_df$FP_3year)][1] 6.273571即對於mayoscore5這個marker而言,最佳閾值(cutoff)為6.27
由於醫藥診斷領域一般是二分類診斷模型,所以上述我們討論的都是基於二分類的ROC曲線,對於一些特殊情況,還會有多分類的ROC,則不在此之列
本文出自於http://www.bioinfo-scrounger.com
另:我們創建了生物信息學習交流群,如需進群,請長按下方二維碼,添加管理員微信(禁廣告)。
溫馨提示:添加管理員微信時請備註姓名/學校/專業