在pROC包中指定正类

在pROC包中指定正类,r,classification,roc,auc,proc-r-package,R,Classification,Roc,Auc,Proc R Package,我想使用pROC包计算不同的分类指标(敏感性、特异性)。为此,我可以在pROC包中使用coords函数,如下所示: # 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

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

# 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
为正值和

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

confusionMatrix(因子(如数字)(aSAH$s100b使用
级别
参数:

levels: the value of the response for controls and cases
          respectively.
这里的“控制”是指负面观察,“病例”是正面观察。默认选择不是基于患病率,只是基于
水平的前两个值(as.factor(response))
的顺序

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

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