The function computes the confusion matrix of a binary classification.
confMatrix(pred, pred.group, truth, namePos, cutoff = 0.5, relative = TRUE)
matrix
or list
of matrices with respective numbers of true
and false predictions.
numeric values that shall be used for classification; e.g. probabilities to belong to the positive group.
vector or factor including the predicted group. If missing,
pred.group
is computed from pred
, where pred >= cutoff
is
classified as positive.
true grouping vector or factor.
value representing the positive group.
cutoff value used for classification.
logical: absolute and relative values.
Matthias Kohl Matthias.Kohl@stamats.de
The function computes the confusion matrix of a binary classification consisting of the number of true positive (TP), false negative (FN), false positive (FP) and true negative (TN) predictions.
In addition, their relative counterparts true positive rate (TPR), false negative rate (FNR), false positive rate (FPR) and true negative rate (TNR) can be computed.
Wikipedia contributors. (2019, July 18). Confusion matrix. In Wikipedia, The Free Encyclopedia. Retrieved 06:00, August 21, 2019, from https://en.wikipedia.org/w/index.php?title=Confusion_matrix&oldid=906886050
## example from dataset infert
fit <- glm(case ~ spontaneous+induced, data = infert, family = binomial())
pred <- predict(fit, type = "response")
## with group numbers
confMatrix(pred, truth = infert$case, namePos = 1)
## with group names
my.case <- factor(infert$case, labels = c("control", "case"))
confMatrix(pred, truth = my.case, namePos = "case")
## on the scale of the linear predictors
pred2 <- predict(fit)
confMatrix(pred2, truth = infert$case, namePos = 1, cutoff = 0)
## only absolute numbers
confMatrix(pred, truth = infert$case, namePos = 1, relative = FALSE)
Run the code above in your browser using DataLab