1

我想使用 pROC 包计算不同的分类指标(敏感性、特异性)。为此,我可以将包中的coords函数pROC用作:

# Load library
library(pROC) 
# Load data
data(aSAH)
#Convert Good and Poor to 1 and 0
aSAH$outcome <- ifelse(aSAH$outcome=="Good", 1, 0)
# Calculate ROC
rocobj <- roc(aSAH$outcome, aSAH$s100b)
# Get sensitivity and specificity
coords(rocobj, 0.55)

在这里它被认为1是积极的类,即可能是最流行的类,但我不确定。我想知道,是否可以使用“0”作为正类。例如,您可以在caret包的confusionMatrix功能中这样做:

confusionMatrix(factor(as.numeric(aSAH$s100b<0.55),levels=c('0','1')),
                   factor(aSAH$outcome,levels=c('0','1')), positive='1')

因为1积极和

confusionMatrix(factor(as.numeric(aSAH$s100b<0.55),levels=c('0','1')),
                   factor(aSAH$outcome,levels=c('0','1')), positive='0')

作为0正类。我正在使用 pROC 包,因为它提供了其他功能,例如确定最佳截止值等,这在插入符号中是不可能的。但是,有没有办法在包中指定正负类pROC

4

1 回答 1

3

使用levels参数:

levels: the value of the response for controls and cases
          respectively.

这里的“控制”是消极的观察,“病例”是积极的观察。默认选择不是基于流行度,而是基于 的前两个值的顺序levels(as.factor(response))

要更改它,请传递一个长度为 2 的向量,例如:

rocobj <- roc(aSAH$outcome, aSAH$s100b, levels = c(1, 0))

请注意,在您设置默认情况下启用的direction参数之前,它不会对您的曲线产生影响。"auto"

于 2016-07-23T06:01:53.933 回答