我想要计算的最优截断值,在我的情况下,最大灵敏度和特异性的交集定义了一个决策规则的逻辑回归分类方法。为了寻找堆栈溢出的解决方案,我找到了一个建议的用ROCR计算最大灵敏度与特异性的截止值解决方案。
但是,当我在联合标度上用ROCR包绘制我的预测对象(由eRm包计算)的截止值(x值)的函数时,我得到了以下数字(见下文)。
现在,如果我计算这两个函数的交点,其中的特异性和敏感性最大化,就像前面的线程中所建议的那样,我得到了一个位于点旁边的值,我会视觉上检测到它是交点。
我的问题很简单:有人能告诉我如何计算这两个函数的相交点,从而得到R中的“最佳”截断点吗?
图1:作为概率截止函数的灵敏度和特异性的示例图。这条线表示“最佳”截止值偏离视觉检测到的最佳阈值。“最优”截止值的计算已按照先前堆栈溢出线程中的建议进行。
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发布于 2016-03-02 19:56:26
如果你想找出最大的金额,你可以
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.5380422https://stackoverflow.com/questions/35731526
复制相似问题