This function calculates a confusion matrix from predicted probabilities, true outcomes, a threshold for classification, and a designated positive label. It calculates true positives, false negatives, true negatives, false positives, and several other useful metrics.
Arguments
- predprob
Numeric vector of predicted probabilities that the outcome is 1, between 0 and 1, with no missing values.
- truth
Vector of true binary class outcomes (0 and 1), the same length as
predprob, with no missing values.- threshold
A single number between 0 and 1. Predictions at or above it are classified as outcome 1.
- poslabel
The outcome class that is the event: 1 (default) or 0.
Value
A data frame of class "dx_cm" with one row, containing the components of the confusion matrix and additional metrics:
tp: True Positivesfn: False Negativestn: True Negativesfp: False Positivesdispos: Number of Actual Positivesdisneg: Number of Actual Negativesn: Total Number of Observationscorrect: Number of Correct Predictionstestpos: Number of Predicted Positivestestneg: Number of Predicted Negatives
Details
The function takes predicted probabilities and a threshold to create binary
predictions which are then compared to the true labels to create a confusion matrix.
It is useful for evaluating the performance of a binary classification model.
With poslabel = 0, outcome 0 is the event, so a prediction below the
threshold is a positive test.
