A function to calculate various ROC curve performance metrics given model predictions and the oberved samples
rocr_ens(predictions, samples)
Random Forest predictions (or any probability)
The original observations (must be a factor)
A list containing all the various ROC curve performance metrics
predictions <- rbeta(100, 4, 4)
samples <- rbinom(100, 1, 0.5)
rocr <- rocr_ens(predictions, samples)
rocr$auc
#> [1] 0.5305958
str(rocr)
#> List of 11
#> $ tpr :Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "True positive rate"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 0 0.0185 0.0185 0.0185 0.0185 ...
#> .. ..@ alpha.values: list()
#> $ tnr :Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "True negative rate"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 1 1 0.978 0.957 0.935 ...
#> .. ..@ alpha.values: list()
#> $ auc : num 0.531
#> $ phi :Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "Phi correlation coefficient"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] NaN 0.0928 -0.0115 -0.0729 -0.1188 ...
#> .. ..@ alpha.values: list()
#> $ acc :Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "Accuracy"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 0.46 0.47 0.46 0.45 0.44 0.45 0.44 0.45 0.46 0.45 ...
#> .. ..@ alpha.values: list()
#> $ err :Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "Error Rate"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 0.54 0.53 0.54 0.55 0.56 0.55 0.56 0.55 0.54 0.55 ...
#> .. ..@ alpha.values: list()
#> $ fpr :Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "False positive rate"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 0 0 0.0217 0.0435 0.0652 ...
#> .. ..@ alpha.values: list()
#> $ sens:Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "Sensitivity"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 0 0.0185 0.0185 0.0185 0.0185 ...
#> .. ..@ alpha.values: list()
#> $ spec:Formal class 'performance' [package "ROCR"] with 6 slots
#> .. ..@ x.name : chr "Cutoff"
#> .. ..@ y.name : chr "Specificity"
#> .. ..@ alpha.name : chr "none"
#> .. ..@ x.values :List of 1
#> .. .. ..$ : num [1:101] Inf 0.842 0.816 0.796 0.776 ...
#> .. ..@ y.values :List of 1
#> .. .. ..$ : num [1:101] 1 1 0.978 0.957 0.935 ...
#> .. ..@ alpha.values: list()
#> $ tss : num 0.136
#> $ rmse: num 0.52