The ‘*confusionLabel*‘ function below labels the predictions of a binary response model according to their confusion matrix categories, i.e., it classifies each prediction into a false positive, false negative, true positive or true negative, given a user-defined threshold value:

```
confusionLabel <- function(model, # placeholder, not yet implemented
obs, # vector of observed 0 and 1 values
pred, # vector of predicted probabilities
thresh) # threshold to separate predictions
{
if (length(obs) != length(pred)) stop("'obs' and 'pred' must be of the same length (and in the same order)")
res <- rep("", length(obs))
res[pred >= thresh & obs == 1] <- "TruePos"
res[pred < thresh & obs == 0] <- "TrueNeg"
res[pred >= thresh & obs == 0] <- "FalsePos"
res[pred < thresh & obs == 1] <- "FalseNeg"
res
}
```

Usage example:

`confusionLabel(obs = myspecies_presabs, pred = myspecies_P, thresh = 0.23)`

The result is a vector with the same length as ‘obs’ and ‘pred’, containing the label for each value. This allows you to then map the confusion matrix, like this:

This function will be included in the next version of the ‘*modEvA*‘ package, which is soon to be released.

Pingback: Package modEvA 3.0 is now on CRAN! | modTools

Pingback: Mapping the confusion matrix | R-bloggers

Pingback: Mapping the confusion matrix – Data Science Austria