使用 pRoc 包进行 ROC 分析后如何获取 p 值?
How to get p value after ROC analysis with pRoc package?
一组数据ROC分析后,p-value怎么计算?同样的统计,我看到在SPSS中可以输出p-value。
示例代码如下:
library(pROC)
data(aSAH)
head(aSAH)
# gos6 outcome gender age wfns s100b ndka
# 29 5 Good Female 42 1 0.13 3.01
# 30 5 Good Female 37 1 0.14 8.54
# 31 5 Good Female 42 1 0.10 8.09
# 32 5 Good Female 27 1 0.04 10.42
# 33 1 Poor Female 42 3 0.13 17.40
# 34 1 Poor Male 48 2 0.10 12.75
(rr <- roc(aSAH$outcome, aSAH$s100b, plot=T))
# Setting levels: control = Good, case = Poor
# Setting direction: controls < cases
#
# Call:
# roc.default(response = aSAH$outcome, predictor = aSAH$s100b, plot = F)
#
# Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
# Area under the curve: 0.7314
编辑:
SPSS中计算的p值为0.000007,而verification::roc.area()
计算的p值为0.000022546,难道roc.area()
和SPSS的计算方法不一致?
levels(aSAH$outcome) <- c(0, 1)
library(verification)
ra <- roc.area(as.numeric(as.vector(aSAH$outcome)), rr$predictor)
ra$p.value
# [1] 0.00002254601
pROC::roc
中没有获取 p 值的选项,您可以设置选项 ci=TRUE
来获取置信区间。 pROC::roc
产生一个不可见的输出,您可以通过将其分配给一个对象来获取该输出。
library(pROC)
data(aSAH)
rr <- pROC::roc(aSAH$outcome, aSAH$s100b, ci=TRUE)
使用 str(rr)
揭示了如何访问 ci
:
rr$ci
# 95% CI: 0.6301-0.8326 (DeLong)
所以你已经有了一个置信区间。
此外,您还可以获得方差,使用 pROC::var
*,您可以从中手动计算标准误差。
(v <- var(rr))
# [1] 0.002668682
b <- rr$auc - .5
se <- sqrt(v)
(se <- sqrt(v))
# [1] 0.05165929
* 注意,还有一个 bootstrap 选项 pROC::var(rr, method="bootstrap")
.
这与 Stata 计算的相同,
# . roctab outcome_num s100b, summary
#
# ROC -Asymptotic Normal--
# Obs Area Std. Err. [95% Conf. Interval]
# ------------------------------------------------------------
# 113 0.7314 0.0517 0.63012 0.83262
# .
# . display r(se)
# .05165929
其中 Stata Base Reference Manual 14 - roctab
(第 2329 页)指出:
By default, roctab
calculates the standard error for the area under
the curve by using an algorithm suggested by DeLong, DeLong, and
Clarke-Pearson (1988) and asymptotic normal confidence intervals.
一旦我们有了标准误差,我们也可以根据 z 分布计算 p 值(Ref.).
z <- (b / se)
2 * pt(-abs(z), df=Inf) ## two-sided test
# [1] 0.000007508474
这个p-值接近你的SPSS值,所以很可能是用类似于Stata的算法计算出来的(比较:IBM SPSS Statistics 24 Algorithms,p.888:889).
然而, ROC 分析的 p 值的计算可能存在争议.例如。您在编辑中显示的方法(另请参阅下面的第一个 link)基于 Mann–Whitney U 统计量。
在决定哪种方法最适合您的分析之前,您可能希望更深入地研究该主题。我在这里为您提供一些阅读建议:
- Does AUC/ROC curve return a p-value? (Cross Validated)
- Which standard error formula for the area under the ROC curve should I use? (Cross Validated)
- Differences between cross validation and bootstrapping to estimate the standard error of the AUC of a given ROC curve (Cross Validated)
- Comparison of Three Methods for Estimating the Standard Error of the Area Under the Curve in ROC Analysis of Quantitative Data (Hajian-Tilaki and Hanley 2002)
- Testing Statistical Significance of the Area under aReceiving Operating Characteristics Curve forRepeated Measures Design with Bootstrapping (Liu et al. 2005)
一组数据ROC分析后,p-value怎么计算?同样的统计,我看到在SPSS中可以输出p-value。 示例代码如下:
library(pROC)
data(aSAH)
head(aSAH)
# gos6 outcome gender age wfns s100b ndka
# 29 5 Good Female 42 1 0.13 3.01
# 30 5 Good Female 37 1 0.14 8.54
# 31 5 Good Female 42 1 0.10 8.09
# 32 5 Good Female 27 1 0.04 10.42
# 33 1 Poor Female 42 3 0.13 17.40
# 34 1 Poor Male 48 2 0.10 12.75
(rr <- roc(aSAH$outcome, aSAH$s100b, plot=T))
# Setting levels: control = Good, case = Poor
# Setting direction: controls < cases
#
# Call:
# roc.default(response = aSAH$outcome, predictor = aSAH$s100b, plot = F)
#
# Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
# Area under the curve: 0.7314
编辑:
SPSS中计算的p值为0.000007,而verification::roc.area()
计算的p值为0.000022546,难道roc.area()
和SPSS的计算方法不一致?
levels(aSAH$outcome) <- c(0, 1)
library(verification)
ra <- roc.area(as.numeric(as.vector(aSAH$outcome)), rr$predictor)
ra$p.value
# [1] 0.00002254601
pROC::roc
中没有获取 p 值的选项,您可以设置选项 ci=TRUE
来获取置信区间。 pROC::roc
产生一个不可见的输出,您可以通过将其分配给一个对象来获取该输出。
library(pROC)
data(aSAH)
rr <- pROC::roc(aSAH$outcome, aSAH$s100b, ci=TRUE)
使用 str(rr)
揭示了如何访问 ci
:
rr$ci
# 95% CI: 0.6301-0.8326 (DeLong)
所以你已经有了一个置信区间。
此外,您还可以获得方差,使用 pROC::var
*,您可以从中手动计算标准误差。
(v <- var(rr))
# [1] 0.002668682
b <- rr$auc - .5
se <- sqrt(v)
(se <- sqrt(v))
# [1] 0.05165929
* 注意,还有一个 bootstrap 选项 pROC::var(rr, method="bootstrap")
.
这与 Stata 计算的相同,
# . roctab outcome_num s100b, summary
#
# ROC -Asymptotic Normal--
# Obs Area Std. Err. [95% Conf. Interval]
# ------------------------------------------------------------
# 113 0.7314 0.0517 0.63012 0.83262
# .
# . display r(se)
# .05165929
其中 Stata Base Reference Manual 14 - roctab
(第 2329 页)指出:
By default,
roctab
calculates the standard error for the area under the curve by using an algorithm suggested by DeLong, DeLong, and Clarke-Pearson (1988) and asymptotic normal confidence intervals.
一旦我们有了标准误差,我们也可以根据 z 分布计算 p 值(Ref.).
z <- (b / se)
2 * pt(-abs(z), df=Inf) ## two-sided test
# [1] 0.000007508474
这个p-值接近你的SPSS值,所以很可能是用类似于Stata的算法计算出来的(比较:IBM SPSS Statistics 24 Algorithms,p.888:889).
然而, ROC 分析的 p 值的计算可能存在争议.例如。您在编辑中显示的方法(另请参阅下面的第一个 link)基于 Mann–Whitney U 统计量。
在决定哪种方法最适合您的分析之前,您可能希望更深入地研究该主题。我在这里为您提供一些阅读建议:
- Does AUC/ROC curve return a p-value? (Cross Validated)
- Which standard error formula for the area under the ROC curve should I use? (Cross Validated)
- Differences between cross validation and bootstrapping to estimate the standard error of the AUC of a given ROC curve (Cross Validated)
- Comparison of Three Methods for Estimating the Standard Error of the Area Under the Curve in ROC Analysis of Quantitative Data (Hajian-Tilaki and Hanley 2002)
- Testing Statistical Significance of the Area under aReceiving Operating Characteristics Curve forRepeated Measures Design with Bootstrapping (Liu et al. 2005)