From documentation of caret package:

The functions requires that the factors have exactly the same levels.

For two class problems, the sensitivity, specificity, positive predictive value and negative predictive

value is calculated using the positive argument. Also, the prevalence of the "event" is computed

from the data (unless passed in as an argument), the detection rate (the rate of true events also

predicted to be events) and the detection prevalence (the prevalence of predicted events).

Suppose a 2x2 table with notation

referenceEvent referenceNo Event

predicted Event A B

predicted No Event C D

The formulas used here are:

Sensitivity = A/(A + C)

Specif icity = D/(B + D)

P revalence = (A + C)/(A + B + C + D)

P P V = (sensitivity∗prevalence)/((sensitivity∗prevalence)+((1−specif icity)∗(1−prevalence)))

NP V = (specif icity∗(1−prevalence))/(((1−sensitivity)∗prevalence)+(specificity)∗(1−prevalence)))

DetectionRate = A/(A + B + C + D)

DetectionP revalence = (A + B)/(A + B + C + D)

BalancedAccuracy = (sensitivity + specif icity)/2

P recision = A/(A + B)

Recall = A/(A + C)

F1 = (1 + beta2) ∗ precision ∗ recall/((beta2∗ precision) + recall)