15  ROC 曲线与多元回归

15.1 分析目的

单个标记物的诊断能力往往有限,多个标记物联合使用可提高整体区分能力。ivdtoolsroc() 除单标记物 ROC 外,还支持用多元 Logistic 回归(mlr())把多个标记物组合成一个联合得分, 计算其 AUC 并对新样本做阳性概率预测。

本文演示两个标记物(x1、x2)的联合分析:先比较单标记物 AUC,再拟合多元 Logistic 回归模型, 绘制多曲线 ROC,并预测新样本。联合模型在训练数据上的 AUC 是表观性能,推广前应在独立数据上 验证;参考变量必须是二分类。

代码
library(ivdtools)
library(readr)

15.2 函数概述

函数 主要用途 关键输入或输出
roc() 创建 ROC 对象 cols 支持多个标记物
auc() 单标记物 AUC 逐列
mlr() 多元 Logistic 回归 colsname,需先 auc()
plot() ROC 曲线 mlr="all" 叠加联合模型曲线
predict() 预测阳性概率 newdatacolumn_map
summary() 汇总

15.3 示例:多标记物联合分析

15.3.1 读取和核验数据

代码
mlr_dat <- read_csv("./data/roc-multimarker.csv", show_col_types = FALSE)
mlr_dat <- as.data.frame(mlr_dat)
str(mlr_dat)
'data.frame':   120 obs. of  4 variables:
 $ sid: num  1 2 3 4 5 6 7 8 9 10 ...
 $ ref: num  0 0 0 0 0 0 0 0 0 0 ...
 $ x1 : num  5.51 3.19 8.13 6.16 11.12 ...
 $ x2 : num  8.3 12.9 12.4 16.1 11.9 ...
代码
table(mlr_dat$ref)

 0  1 
60 60 

数据包含 120 例(正、负各 60),两个定量标记物 x1、x2。

15.3.2 创建对象与单标记物 AUC

代码
ro2 <- roc(mlr_dat, cols = c("x1", "x2"), reference = "ref", id = "sid")
ro2 <- auc(ro2)

AUC Table
  Column               AUC          95% CI  Direction
  ------------------------------------------------------------ 
  x1                0.9219  [0.8712, 0.9727]       geq
  x2                0.8322  [0.7587, 0.9057]       geq
代码
ro2$auc_table

x1 的 AUC ≈ 0.922,x2 的 AUC ≈ 0.832,单标记物中 x1 区分能力更强。

15.3.3 多元 Logistic 回归

用两个标记物联合建模:

代码
ro2 <- mlr(ro2, cols = c("x1", "x2"), name = "combined")

Multivariate Logistic Regression (combined)
  -------------------------------------------------- 
  Formula: reference_binary ~ x1 + x2
  n = 120  (positive = 60, negative = 60)
  AUC = 0.9642  [0.9298, 0.9985]

  Coefficients:
                   Estimate Std. Error   z value     Pr(>|z|) 
    (Intercept) -13.6586717  2.7569949 -4.954188 7.263286e-07 
    x1            0.7638502  0.1549103  4.930919 8.184356e-07 
    x2            0.3949617  0.1064673  3.709700 2.075049e-04 

  * Note: AUC is evaluated on the same data used for fitting;
    the estimate may be optimistic.
代码
ro2$mlr_results$combined$fit_summary

Call:
glm(formula = formula, family = binomial, data = model_data)

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -13.6587     2.7570  -4.954 7.26e-07 ***
x1            0.7639     0.1549   4.931 8.18e-07 ***
x2            0.3950     0.1065   3.710 0.000208 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 166.355  on 119  degrees of freedom
Residual deviance:  58.112  on 117  degrees of freedom
AIC: 64.112

Number of Fisher Scoring iterations: 7
代码
ro2$mlr_results$combined$auc
[1] 0.9641667

联合模型的 AUC ≈ 0.964(95% CI [0.930, 0.999]),高于任一单标记物,说明两标记物联合确有增益。

参数说明: mlr(cols, name, ...) 用二分类 Logistic 回归(glm)拟合选中标记物,name 为 模型名(自动生成 MLR01MLR02 …);... 透传给 glm必须先执行 auc() 才能调用 mlr()。 系数解释为对数优势比;联合 AUC 在拟合所用数据上计算,属于表观性能。

15.3.4 多曲线 ROC 图

代码
plot(ro2, mlr = "all")

plot(ro2, mlr="all") 同时画出各单标记物与联合模型的 ROC 曲线,便于比较。

15.3.5 对新样本预测

代码
predict(ro2, newdata = data.frame(x1 = c(7, 12), x2 = c(16, 21)))

predict() 返回各预测变量、阳性概率(pred_prob)、标准误与置信区间,以及默认阈值 0.5 下的 预测类别(pred_class)。两例分别得到 0.12 与 0.98 的阳性概率,与期望方向一致。

参数说明:newdata 的列名与建模时不一致时,用命名向量 column_map 映射 (如 column_map = c(new_x1 = "x1"))。若对象中有多个模型,predict() 需用 mlr 指定模型名。

15.3.6 汇总

代码
summary(ro2)

ROC Analysis -- Summary
-------------------------------------------------- 

ROC Analysis
  Data class:        data.frame
  Total rows:        120
  Complete cases:    120
  Reference:         ref (binary)
  Positive / Neg:    60 / 60
  Evaluation cols:   2  (x1, x2)
  Duplicate IDs:     none

Analysis slots:
    [ ] Describe
    [x] AUC
    [ ] Cutoff
    [x] MLR


AUC Table
  Column               AUC          95% CI  Direction
  ------------------------------------------------------------ 
  x1                0.9219  [0.8712, 0.9727]       geq
  x2                0.8322  [0.7587, 0.9057]       geq

MLR Results

Multivariate Logistic Regression (combined)
  -------------------------------------------------- 
  Formula: reference_binary ~ x1 + x2
  n = 120  (positive = 60, negative = 60)
  AUC = 0.9642  [0.9298, 0.9985]

  Coefficients:
                   Estimate Std. Error   z value     Pr(>|z|) 
    (Intercept) -13.6586717  2.7569949 -4.954188 7.263286e-07 
    x1            0.7638502  0.1549103  4.930919 8.184356e-07 
    x2            0.3949617  0.1064673  3.709700 2.075049e-04 

  * Note: AUC is evaluated on the same data used for fitting;
    the estimate may be optimistic.

15.4 结果判读要点

  1. 联合增益:联合 AUC 高于各单标记物仅说明线性组合有增益;是否显著改善应结合置信区间与临床 决策需要判断。
  2. 表观性能:训练数据上的 AUC 是乐观估计,必须在独立验证集上重估,避免过拟合误判。
  3. 共线性与分离:标记物高度相关或完全分离时 Logistic 回归可能不稳定或无法收敛。
  4. 事件数:多元模型每个参数需要足够的事件数,事件过少时慎用。
  5. cutoff 与决策:联合得分的最终判定阈值应结合临床代价与方案,不限于默认 0.5。
  6. 变量选择mlr() 一次拟合给定标记物集合;多组变量比较应在方案中预设,避免反复试错。