gpt4 book ai didi

r - 使用ROCR计算“最佳”(=最大灵敏度和特异性)截止值

转载 作者:行者123 更新时间:2023-12-03 17:21:57 25 4
gpt4 key购买 nike

我想计算出最佳的临界值,在我的案例中,这是最大灵敏度和特异性的交集,用于为逻辑回归分类方法定义决策规则。在堆栈溢出中寻找解决方案时,我找到了calculate cut-off that max sensitivity vs specificity using ROCR的建议解决方案。

但是,当我在ROCR上绘制联合标度的特异性和灵敏度值(y轴)作为我的预测对象(由eRm软件包计算)的临界值(x值)的函数时包中,我得到了下图(如下所示)。

现在,如果按照先前线程中的建议,计算两个函数的交点,使特异性和灵敏度最大化,那么该值将位于该点旁边的其他位置,我将在视觉上将其检测为交点。

我的问题很简单:有人可以给我展示一种方法来计算两个函数的交点以获得R中的“最佳”截止点吗?

Figure 1: Example Plot of sensitivity and specificity as a function of probability cutoff. The line indicates the 'optimal' cutoff value deviating from the visually detected optimal threshold. The calculation of the 'optimal' cutoff value has been done as suggested in an earlier stack overflow thread

library(ROCR)
library(eRm)
set.seed(1)
data <- sim.rasch(30, 300) # simulate Rasch homogenous data
model.RM<-RM(data, se=T)#estimate Rasch model
PPAR.X <-person.parameter(model.RM)
#Goodness-of-fit test (see Mair et al. 2008)
gof.model.RM<-gofIRT(PPAR.X)
#summary(gof.model.RM)

#ROCR
pred.model.RM <- gof.model.RM$predobj
Sens.model.RM <- performance(pred.model.RM, measure="sens", x.measure="cutoff")
Spec.model.RM <- performance(pred.model.RM, measure="spec", x.measure="cutoff")

#Identify the 'optimal' cutoff that yields the highest sensitivity and specificity according to prior stack overflow thread:
SensSpec.model.RM <- performance(pred.model.RM, "sens", "spec")
CP<-SensSpec.model.RM@alpha.values[[1]][which.max(SensSpec.model.RM@x.values[[1]]+SensSpec.model.RM@y.values[[1]])]
# [1] 0.5453864 # 'optimal' cutoff value

#Plot
plot(Sens.model.RM, type="l", col="red",xlab="",ylab="")
par(new=TRUE)
plot(Spec.model.RM, type="l", col="blue", xlab="Probability cutoff (threshold)",ylab="Sensitivity/Specificity")
abline(v = CP, col = "black", lty = 3)#add a line indicating the suggested 'optimal' cutoff value differing from the visually expected one

最佳答案

如果您想找到最大的和,可以

best.sum <- which.max(Sens.model.RM@y.values[[1]]+Spec.model.RM@y.values[[1]])
Sens.model.RM@x.values[[1]][best.sum]
# [1] 0.5453863


如果要查找最近的交叉点,可以执行

both.eq <- which.min(abs(Sens.model.RM@y.values[[1]]-Spec.model.RM@y.values[[1]]))
Sens.model.RM@x.values[[1]][both.eq]
# [1] 0.5380422

关于r - 使用ROCR计算“最佳”(=最大灵敏度和特异性)截止值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35731526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com