sensitivity {caret}R Documentation

Calculate Sensitivity, Specificity and predictive values

Description

These functions calculate the sensitivity, specificity or predictive values of a measurement system compared to a reference results (the truth or a gold standard). The measurement and "truth" data must have the same two possible outcomes and one of the outcomes must be thought of as a "positive" results.

The sensitivity is defined as the proportion of positive results out of the number of samples which were actually positive. When there are no positive results, sensitivity is not defined and a value of NA is returned. Similarly, when there are no negative results, specificity is not defined and a value of NA is returned. Similar statements are true for predictive values.

The positive predictive value is defined as the percent of predicted positives that are actually positive while the negative predictive value is defined as the percent of negative positives that are actually negative.

Usage

sensitivity(data, reference, positive = levels(reference)[1])
specificity(data, reference, negative = levels(reference)[2])
posPredValue(data, reference, positive = levels(reference)[1])
negPredValue(data, reference, negative = levels(reference)[2])

Arguments

data a factor containing the discrete measurements
reference a factor containing the reference values
positive a character string that defines the factor level corresponding to the "positive" results
negative a character string that defines the factor level corresponding to the "negative" results

Value

A number between 0 and 1 (or NA).

Author(s)

Max Kuhn

Examples

data01 <- factor(c("A", "B", "B", "B"))
data02 <- factor(c("A", "B", "B", "B"))

ref01 <- factor(c("B", "B", "B", "B"))
ref02 <- factor(c("B", "A", "B", "B"))

table(data01, ref01)
sensitivity(data01, ref01)
posPredValue(data01, ref01)

table(data02, ref02)
sensitivity(data02, ref02)
posPredValue(data02, ref02)

data03 <- factor(c("A", "B", "B", "B"))
data04 <- factor(c("B", "B", "B", "B"))

ref03 <- factor(c("B", "B", "B", "B"), levels = c("A", "B"))
ref04 <- factor(c("B", "A", "B", "B"))

table(data03, ref03)
specificity(data03, ref03)
negPredValue(data03, ref03)

table(data04, ref04)
specificity(data04, ref04)
negPredValue(data04, ref04)




[Package caret version 3.51 Index]