在R
包{Epi}
中,ROC()
函数可以生成aSAH
包中数据集{pROC}
的图,如下所示:
使用以下命令:
require(Epi)
require(pROC)
data(aSAH)
rock = ROC(form = outcome ~ s100b, data=aSAH, plot = "ROC", MX = T)
计算对象nrow(rock$res)
中包含的51个点的灵敏度和特异性。在这方面,请注意nrow(aSAH)
而不是113。
哪些点用于生成rock$res
?
如果我们使用的是roc()
包中的{pROC}
函数,我们可以通过以下方式获取:roc(aSAH$outcome, aSAH$s100b)$threshold
。但是作为不同的套餐,它们可能不同。
答案 0 :(得分:2)
答案是......当然......在package documentation:
res 数据框,包含变量sens,spec,pvp,pvn和测试名称 变量。后者是测试或线性预测器的唯一值 从逻辑回归中按升序排列-Inf prepended。
那么有什么独特的价值观:
points = unique(aSAH$s100b); length(points) [1] 50
加上预先结束的-Inf
!
好看,但我们可以证明这一点......我想是的:
require(Epi)
require(pROC)
data(aSAH)
rock = ROC(form = outcome ~ s100b, data=aSAH, plot = "ROC", MX = T)
d = aSAH
points = sort(unique(d$s100b))
length(points)
## Logistic regression coefficients:
beta.0 = as.numeric(rock$lr$coefficients[1])
beta.1 = as.numeric(rock$lr$coefficients[2])
## Sigmoid function:
sigmoid = 1 / (1 + exp(-(beta.0 + beta.1 * points)))
sigmoid = as.numeric(c("-Inf", sigmoid))
lr.eta = rock$res$lr.eta
length(lr.eta)
head(lr.eta)
head(sigmoid)
> head(lr.eta)
[1] -Inf 0.1663429 0.1732556 0.1803934 0.1877585 0.1953526
> head(sigmoid)
[1] -Inf 0.1663429 0.1732556 0.1803934 0.1877585 0.1953526
## Trying to get the lr.eta number 0.304 on the plot:
which.max(rowSums(rock$res[, c("sens", "spec")])) 0.30426295405785 18
## Excluding the "-Inf" introduced by the ROC function (position 17 as opposed to 18):
max.sens.sp.cut = points[17]
1 / (1 + exp(-(beta.0 + beta.1 * max.sens.sp.cut))) [1] 0.304263 !!!
完成!