2016-07-23 37 views
0

我想使用pROC包计算不同的分类指标(灵敏度,特异性)。对于这一点,我可以使用coords功能pROC包为:指定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包中是否有指定正面和负面类的方法?

回答

2

使用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"默认。