confmat: Confusion matrix

View source: R/classification.R

confmatR Documentation

Confusion matrix

Description

Organizes supplied values of true and false positives and negatives into a confusion matrix.

Usage

confmat(tp, tn, fp, fn, output = "freq")

Arguments

tp

The frequency or rate of true-positive classifications.

tn

The frequency or rate of true-negative classifications.

fp

The frequency or rate of false-positive classifications.

fn

The frequency or rate of false-negative classifications.

output

Whether the returned output reflects frequencies or proportions. Defaults to returning frequencies.

Value

A confusion matrix organizing the input values of true and false positive and negatives.

Examples

# Generate some true and observed conditions.
set.seed(1234)
true.ability <- rbeta(50, 4, 4)
true.category <- ifelse(true.ability < 0.5, 0, 1)
observed.score <- rbinom(50, 50, true.ability)
observed.category <- ifelse(observed.score < 25, 0, 1)
# Calculate the frequencies of true and false positives and negatives based on the true and
# observed conditions.
TP <- sum(ifelse(observed.category == 0 & true.category == 0, 1, 0))
FP <- sum(ifelse(observed.category == 0 & true.category != 0, 1, 0))
TN <- sum(ifelse(observed.category == 1 & true.category == 1, 1, 0))
FN <- sum(ifelse(observed.category == 1 & true.category != 1, 1, 0))
# Organize the above values in a confusion matrix using the confmat function:
confmat(tp = TP, fp = FP, tn = TN, fn = FN)

betafunctions documentation built on May 29, 2024, 1:13 a.m.