Calculator for Diagnostic Accuracy Measures

Theodora Chatzimichail, MD  
tc@hcsl.com

Hellenic Complex Systems Laboratory, Kostis Palamas 21, 66131 Drama, Greece.

Initialization Code

pop[tn_,fp_,fn_,tp_]:=tn+fp+fn+tp

dis[tn_,fp_,fn_,tp_]:=fn+tp

ndis[tn_,fp_,fn_,tp_]:=tn+fp

se[tn_,fp_,fn_,tp_]:=(tp/(fn+tp))

sp[tn_,fp_,fn_,tp_]:=(tn/(tn+fp))
pr[tn_,fp_,fn_,tp_]:=((fn+tp)/(tn+fp+fn+tp))

ppv[tn_,fp_,fn_,tp_]:=(tp/(tp+fp))

npv[tn_,fp_,fn_,tp_]:=(tn/(tn+fn))

or[tn_,fp_,fn_,tp_]:=(((se[tn,fp,fn,tp])/(1-se[tn,fp,fn,tp]))/((1-sp[tn,fp,fn,tp])/(sp[tn,fp,fn,tp])))

lrp[tn_,fp_,fn_,tp_]:=((se[tn,fp,fn,tp])/(1-sp[tn,fp,fn,tp]))

lrn[tn_,fp_,fn_,tp_]:=((1-se[tn,fp,fn,tp])/(sp[tn,fp,fn,tp]))

dam[tn_,fp_,fn_,tp_]:=Text@Grid[Transpose[
{
{Style["population statistics",Bold],"total population","nondiseased","diseased","prevalence of disease",Style["diagnostic accuracy measures of the test",Bold],"sensitivity","specificity","positive predictive value", "negative predictive value", "odds ratio", "likelihood ratio for a positive result","likelihood ratio for a negative result"},
{SpanFromLeft,
pop[tn,fp,fn,tp],
ndis[tn,fp,fn,tp],
dis[tn,fp,fn,tp],
NumberForm[N@pr[tn,fp,fn,tp],{8,6}],
SpanFromLeft,
NumberForm[N@se[tn,fp,fn,tp],{8,6}],
NumberForm[N@sp[tn,fp,fn,tp],{8,6}],
NumberForm[N@ppv[tn,fp,fn,tp],{8,6}],
NumberForm[N@npv[tn,fp,fn,tp],{8,6}],
NumberForm[N@or[tn,fp,fn,tp],{18,6}],
NumberForm[N@lrp[tn,fp,fn,tp],{8,6}],
NumberForm[N@lrn[tn,fp,fn,tp],{8,6}]}
}
],Frame->All, FrameStyle->Blend[{Blue,Cyan},0.35],Spacings->{1,1},ItemSize->{{20,10},Automatic}]

Manipulate[Pane[dam[tn,fp,fn,tp], 400,Alignment->Center],
Style["nondiseased population",Bold],
"",
"negative test result",
{{tn,8550,""},1,100000,1,Appearance->"Labeled",ImageSize->Small},
"",
"positive test result",
{{fp,950,""},1,100000,1,Appearance->"Labeled", ImageSize->Small} ,
"","",
Style["diseased population",Bold],
"",
"positive test result",
{{tp,450,""},1,100000,1,Appearance->"Labeled",ImageSize->Small},
"",
"negative test result",
{{fn,50,""},1,100000,1,Appearance->"Labeled", ImageSize->Small},
 ControlPlacement->Left,ContinuousAction->False,SaveDefinitions->True]

Description

This Demonstration calculates various accuracy measures of a diagnostic test for a disease. This is done for differing negative and positive test results of nondiseased and diseased populations. The measures calculated are the sensitivity, the specificity, the positive predictive value ("PPV"), the negative predictive value ("NPV"), the (diagnostic) odds ratio ("OR"), the likelihood ratio for a positive test result ("LR+"), and the likelihood ratio for a negative test result ("LR-"). The negative and positive test results of the nondiseased and diseased populations are selected using the sliders.

Snapshots

Details

Sensitivity is the fraction of the diseased population with a positive test result, while specificity is the fraction of the nondiseased population with a negative test result. Positive predictive value is the fraction of the population with a positive test result that is diseased, while negative predictive value is the fraction of the population with a negative test result that is nondiseased. Prevalence of the disease is the ratio of the diseased population to the total (nondiseased and diseased) population. If we denote by sens the sensitivity, spec the specificity, and pr the prevalence, we have:

OR=(sens/(1-sens))/((1-spec)/spec),

LR+ =(sens/(1-spec)),

LR- =((1-sens)/spec).

The Demonstration is appropriate as an educational tool for medical students.

Keywords

sensitivity
specificity
diagnostic test
clinical accuracy
diagnostic accuracy
positive predictive value
negative predictive value
likelihood ratio
odds ratio

Related Links

Analysis of Diagnostic Accuracy Measures

Disclaimer of Warranties

The notebook is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or Hellenic Complex Systems Laboratory or any of its members be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the notebook or the use or other dealings in the notebook.

About

Calculator for Diagnostic Accuracy Measures
Version Number 1.1.0
Hellenic Complex Systems Laboratory 2021
First published at Wolfram Demonstrations Project at: (HyperlinkURL["demonstrations.wolfram.com/CalculatorForDiagnosticAccuracyMeasures/", https://demonstrations.wolfram.com/CalculatorForDiagnosticAccuracyMeasures/])
The notebook is distributed under  an Attribution - NonCommercial - ShareAlike 4.0 International Creative Commons License.