2016-07-23 45 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"默認。