Learn R Programming

WGCNA (version 1.10-2)

accuracyMeasures: Accuracy measures for a 2x2 confusion matrix.

Description

The function calculates the error rate, accuracy, sensitivity, specificity, positive predictive value, and other accuracy measures for a 2x2 confusion matrix. The input tab must be a 2x2 dimensional matrix which contains count data.

Usage

accuracyMeasures(tab)

Arguments

tab
2x2 dimensional matrix (i.e. table) whose entries contain non-negative integers. The function also works if the table contains non-negative real numbers but outputs a warning if non-integers are detected.

Value

  • data frame with two columns:
  • Measurethis column contais character strings that specify the name of the accuracy measure
  • Valuethis column contains the numeric estimates of the corresponding accuracy measures

Details

The rows of the 2x2 table tab may correspond to a test (or predicted) outcome and the columns to a true outcome ("gold standard"). A table that relates a predicted outcome to a true test outcome is also known as confusion matrix. Warning: When it comes to estimating the sensitivity and specificity, the order of rows and columns matters. The first row corresponds to a *positive* outcome while the second row corresponds to a negative outcome. Same holds for the columns. Reversing the order of the rows (and accordingly the order of the columns) swaps the estimates of the sensitivity and specificity but has no effect on the error rate or accuracy. Specifically, the funcdtion assumes: number of true positives=TP=tab[1,1], no.false positives =FP=tab[1,2], no.false negatives=FN=tab[2,1], no.true negatives=TN=tab[2,2]. Then Specificity= TN/(FP+TN) Sensitivity= TP/(TP+FN) NegativePredictiveValue= TN/(FN + TN) PositivePredictiveValue= TP/(TP + FP) FalsePositiveRate = 1-Specificity FalseNegativeRate = 1-Sensitivity Power = Sensitivity LikelihoodRatioPositive = Sensitivity / (1-Specificity) LikelihoodRatioNegative = (1-Sensitivity)/Specificity

References

http://en.wikipedia.org/wiki/Sensitivity_and_specificity

Examples

Run this code
m=100
trueOutcome=sample( c(1,2),m,replace=TRUE)
predictedOutcome=trueOutcome
# now we noise half of the entries of the predicted outcome
predictedOutcome[ 1:(m/2)] =sample(predictedOutcome[ 1:(m/2)] )
tab=table(predictedOutcome, trueOutcome) 
accuracyMeasures(tab)

Run the code above in your browser using DataLab