dbc*_*fee 4 r spss roc proc-r-package
对一组数据进行ROC分析后,如何计算p-value?通过同样的统计,我看到SPSS中可以输出p值。示例代码如下:
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
Run Code Online (Sandbox Code Playgroud)
SPSS中计算的p值为0.000007,但计算出来的p值为verification::roc.area()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
Run Code Online (Sandbox Code Playgroud)
没有选项可以获取 中的 p 值pROC::roc,您可以设置选项ci=TRUE来获取置信区间。pROC::roc产生一个不可见的输出,您可以通过将其分配给一个对象来获取它。
library(pROC)\ndata(aSAH)\nrr <- pROC::roc(aSAH$outcome, aSAH$s100b, ci=TRUE)\nRun Code Online (Sandbox Code Playgroud)\n\n使用str(rr)揭示了如何访问ci:
rr$ci\n# 95% CI: 0.6301-0.8326 (DeLong)\nRun Code Online (Sandbox Code Playgroud)\n\n所以你已经有了一个置信区间。
\n\n此外,您还可以使用*获得方差pROC::var,从中您可以手动计算标准误差。
(v <- var(rr))\n# [1] 0.002668682\nb <- rr$auc - .5\nse <- sqrt(v)\n(se <- sqrt(v))\n# [1] 0.05165929\nRun Code Online (Sandbox Code Playgroud)\n\n* 请注意,还有一个引导选项pROC::var(rr, method="bootstrap")。
这与 Stata 计算的结果相同,
\n\n# . roctab outcome_num s100b, summary\n# \n# ROC -Asymptotic Normal--\n# Obs Area Std. Err. [95% Conf. Interval]\n# ------------------------------------------------------------\n# 113 0.7314 0.0517 0.63012 0.83262\n# .\n# . display r(se)\n# .05165929\nRun Code Online (Sandbox Code Playgroud)\n\n其中Stata Base 参考手册 14 -roctab(第 2329 页)指出:
\n\n\n默认情况下,
\nroctab使用 DeLong、DeLong 和 Clarke-Pearson (1988) 建议的算法和渐近正态置信区间计算曲线下方面积的标准误差。
一旦我们有了标准误差,我们还可以根据z分布计算p值(参考文献 1)。)。
\n\nz <- (b / se)\n2 * pt(-abs(z), df=Inf) ## two-sided test\n# [1] 0.000007508474\nRun Code Online (Sandbox Code Playgroud)\n\n此p值接近您的 SPSS 值,因此很可能是使用类似于 Stata 的算法计算的(比较:IBM SPSS Statistics 24 Algorithms,第 888:889 页)。
\n\n然而, p的计算 ROC 分析的例如,您在编辑中显示的方法(另请参阅下面的第一个链接)基于 Mann\xe2\x80\x93Whitney U 统计。
\n\n在决定哪种方法最适合您的分析之前,您可能需要更深入地研究该主题。我在这里为您提供一些阅读建议:
\n\n| 归档时间: |
|
| 查看次数: |
4349 次 |
| 最近记录: |