*! version 3.0.1 05OCt2023

*! version 3.0.0 01Sep2022

*! version 2.0.1 12Jul2018

*! version 2.0.0 03Oct2017

*! version 1.0.1 29May2016

*! version 1.0.0 29Dec2015

Title

classtab -- Diagnostic accuracy statistics and classification table

Syntax

Using data stored in memory

classtab refvar classvar [, level(#)]

Immediate form of classtab

classtabi #a #b #c #d [, level(#)]

Immediate form of classtab referring to a saved 2 X 2 matrix

classtabi matname [, level(#)]

#a is the true positive (disease=1 and test=1); #b is the false negative (disease=1 and test=0);
#c is the false positive (disease=0 and test=1); #d is the true negative (disease=0 and test=0).
#a, #b, #c, and #d must be positive integers.

level(#) set confidence level; default is level(95)

by is allowed with classtab; see [D] by.

Description

classtab reports various classification statistics and their exact confidence intervals
(also known in the literature as Clopper-Pearson [1934] binomial confidence intervals) and
provides a 2 x 2 classification table.

classtabi is the immediate form of classtab; see immed.

Remarks

For classtabi, row values indicate the true (binary) state of the observation ( refvar), such as diseased and nondiseased, or normal and abnormal. Column values represent
the binary rating or outcome of the diagnostic test (classvar), or predicted class from a classification algorithm. As such, when manually entering the four values (syntax 1),
the data should be entered as follows (for example, we use disease as the reference [row] variable, and diagnostic test outcome as the classifier [column] variable):

--------------------------------------------------------------------------------------

#a -- disease=1, test=1 (true positive) | #b -- disease=1, test=0 (false negative)

--------------------------------------------------------------------------------------

#c -- disease=0, test=1 (false positive)| #d -- disease=0, test=0 (true negative)

--------------------------------------------------------------------------------------

To use the second classtabi syntax (syntax 2), the four values must be saved in a 2 X 2 matrix (see example below).

Options

level(#) specifies the confidence level, as a percentage, for confidence intervals; default level is level(95).

Examples

Using data stored in memory

. use example.dta

. classtab disease test

Entering values manually using classtabi

. classtabi 324 50 397 1231

. classtabi 324 50 397 1231, level(99)

Referring to a matrix using classtabi

. matrix input B = (324 50\397 1231)

. classtabi B, level(99)

Stored results

classtab and classtabi store the following in r():

Scalars

r(sens) sensitivity

r(senslb) sensitivity - lower bound of confidence interval

r(sensub) sensitivity - upper bound of confidence interval

r(spec) specificity

r(speclb) specificity - lower bound of confidence interval

r(specub) specificity - upper bound of confidence interval

r(fpr) false-positive rate

r(fprlb) false-positive rate - lower bound of confidence interval

r(fprub) false-positive rate - upper bound of confidence interval

r(fnr) false-negative rate

r(fnrlb) false-negative rate - lower bound of confidence interval

r(fnrub) false-negative rate - upper bound of confidence interval

r(ppv) positive predictive value

r(ppvlb) positive predictive value - lower bound of confidence interval

r(ppvub) positive predictive value - upper bound of confidence interval

r(npv) negative predictive value

r(npvlb) negative predictive value - lower bound of confidence interval

r(npvub) negative predictive value - upper bound of confidence interval

r(all) overall correctly classified

r(alllb) overall correctly classified - lower bound of confidence interval

r(allub) overall correctly classified - upper bound of confidence interval

r(roc) ROC curve

r(roclb) ROC curve - lower bound of confidence interval

r(rocub) ROC curve - upper bound of confidence interval

References

Clopper, C. J., and E. S. Pearson. 1934. The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika 26: 404-413.

Linden A. 2006. Measuring diagnostic and predictive accuracy in disease management: an introduction to receiver operating characteristic (ROC) analysis.
Journal of Evaluation in Clinical Practice 12: 132-139.

Citation of classtab

classtab is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden, Ariel (2022). classtab: Stata module for computing diagnostic accuracy statistics and classification table

Author

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org

Also see

Online: estat classification, roccomp, roctabi (if installed), rmclass (if installed),
looclass (if installed), kfoldclass (if installed)