资讯详情

资讯详情

clinpubr 模型评估与比较:从 AUC 到 DCA 的全面指南

写在前面在临床预测模型的研究中仅仅报告”模型的 AUC 为 0.85”是远远不够的。一个完整的模型评估需要从判别力Discrimination、校准度Calibration和临床实用性Clinical Utility三个维度进行全面考量。审稿人也越来越倾向于看到多角度的模型评估证据。clinpubr 提供了一站式的模型评估工具涵盖分类模型比较、时间依赖性 ROC、C-Index 计算和变量重要性可视化。本文将通过实战案例带你完成从模型拟合到全面评估的全流程。适用场景预测模型开发、模型比较研究、临床决策支持系统评估等。library(clinpubr)library(dplyr)library(survival)library(ggplot2)评估维度概览数据准备我们使用 NCCTG 肺癌数据集拟合三个复杂度递增的 Logistic 回归模型data(cancer, packagesurvival)cancer$dead- cancer$status2cancer$event- ifelse(cancer$status2,1,0)cancer_clean- cancer %% mutate(sexfactor(sex, labelsc(Male,Female)))%% na.omit()# 拟合三个复杂度递增的模型cancer_clean$pred_model1- predict( glm(dead ~ age sex ph.karno, datacancer_clean, familybinomial), typeresponse)cancer_clean$pred_model2- predict( glm(dead ~ age sex ph.karno pat.karno, datacancer_clean, familybinomial), typeresponse)cancer_clean$pred_model3- predict( glm(dead ~ age sex ph.karno wt.loss, datacancer_clean, familybinomial), typeresponse)knitr::kable(head(cancer_clean[, c(dead,pred_model1,pred_model2,pred_model3)]), caption模型预测值 vs 实际结局前 6 行)Table: 模型预测值 vs 实际结局前6行||dead|pred_model1|pred_model2|pred_model3||:--|:-----|-----------:|-----------:|-----------:||2|TRUE|0.7868731|0.7661243|0.7858287||4|TRUE|0.7436147|0.8215218|0.7434448||6|FALSE|0.9260244|0.8954047|0.9273628||7|TRUE|0.7052554|0.7566565|0.7049340||8|TRUE|0.7704063|0.7279677|0.7724185||9|TRUE|0.8207969|0.8021612|0.8203195|模型比较classif_model_compare() 使用多个指标AUC、准确率、灵敏度、特异度、PPV、NPV、PRAUC、Brier Score进行全面的模型比较并自动生成 ROC、PR、校准和 DCA 图model_comparison- classif_model_compare( datacancer_clean, target_vardead, model_namesc(pred_model1,pred_model2,pred_model3), save_outputFALSE )AssumingTRUEis[Event]andFALSEis[non-Event]knitr::kable(model_comparison$metric_table, caption模型性能比较)Table: 模型性能比较||Model|AUC|AUC_lower|AUC_upper|PRAUC|Accuracy|Sensitivity|Specificity|Pos Pred Value|Neg Pred Value|F1|Kappa|Brier|cutoff|Youden|HosLem||:--|:-----------|-----:|---------:|---------:|-----:|--------:|-----------:|-----------:|--------------:|--------------:|-----:|-----:|-----:|------:|------:|------:||3|pred_model3|0.684|0.594|0.774|0.820|0.581|0.50|0.787|0.857|0.381|0.632|0.217|0.185|0.777|0.287|0.985||1|pred_model1|0.684|0.594|0.774|0.817|0.557|0.45|0.830|0.871|0.371|0.593|0.203|0.185|0.786|0.280|0.967||2|pred_model2|0.684|0.590|0.777|0.821|0.605|0.55|0.745|0.846|0.393|0.667|0.232|0.182|0.765|0.295|0.353|可视化ROC 曲线——展示不同阈值下的灵敏度与特异度权衡model_comparison$roc_plotPR 曲线——对不平衡数据更灵敏的性能评估model_comparison$pr_plot校准图——评估预测概率与实际概率的一致性model_comparison$calibration_plot决策曲线分析DCA——评估不同阈值下的临床净获益model_comparison$dca_plot时间依赖性 ROC 分析对于生存结局时间依赖性 ROC 考虑了事件发生的时间。首先我们拟合 Cox 比例风险模型并获取风险评分library(survival)# 拟合 Cox 模型用于生存预测cox_model- coxph(Surv(time, event)~ age sex ph.karno, datacancer_clean)cancer_clean$risk_score- predict(cox_model,typerisk)现在我们可以在特定时间点评估模型time_roc_result- time_roc_plot( datacancer_clean, event_varevent, time_vartime, marker_varrisk_score, timesc(200,365), time_unitdays, save_plotFALSE )time_roc_result$time_rocTime-dependent-Roc curve estimated using IPCW(n167, without competing risks). Cases Survivors Censored AUC(%)t20048111867.32t36587493160.85Method usedforestimating IPCW:marginal Total computationtime:0secs.$plotC-IndexC-index一致性指数衡量生存模型的判别能力。解读标准0.5 无判别力0.7-0.8 可接受0.8 优秀。c_index- calc_cindex(cancer_clean,time,event,risk_score)警告信息: In calc_cindex(cancer_clean,time,event,risk_score):C-index islessthan0.5, possibly indicating a reversed relationship. Reversed to1- C-index.c_index C Index0.6243374变量重要性变量重要性列表可以从随机森林、梯度提升机等不同模型中获取。这里我们假设从某个模型中获得了变量重要性评分importance_scores- c( Age0.25, Sex0.15, Karnofsky0.30, WeightLoss0.12, Calories0.08, PatKarnofsky0.10)importance_plot(ximportance_scores, x_labVariable Importance)仅展示排名前 N 的变量并自定义样式importance_plot(ximportance_scores, x_labVariable Importance)importance_plot( ximportance_scores, x_labRelative Importance, top_n4, colorsteelblue)小结核心函数classif_model_compare()全面的模型比较含 ROC、PR、校准和 DCA 图time_roc_plot()生存结局的时间依赖性 ROC 分析calc_cindex()计算生存模型的一致性指数importance_plot()可视化变量重要性模型评估清单判别力AUC二分类或 C-index生存模型临床阈值处的灵敏度/特异度校准度校准图、Brier 评分临床实用性决策曲线分析相关阈值处的净获益外部验证在独立人群中的表现安装 clinpubrinstall.packages(“clinpubr”, dependencies TRUE)
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →