Functions & Formulae

Each applied formula has its own function page, with a signature, implementations, and tests.

Diagnostic test accuracy measures and the expected value of test results

Se = TP / (TP + FN); Sp = TN / (TN + FP); NMB = p * Se * G - (1 - p) * (1 - Sp) * L - c

Maps the cross-classification of index test results against a reference standard to the measures of accuracy, conditional on disease status (sensitivity, specificity) or on the test result (predictive values), and combines accuracy with prevalence and the consequences of true and false results into the expected net monetary benefit of testing. The notation follows the Diagnostic Accuracy article and its two triage tests.

  • Sensitivity, specificity and predictive values from a diagnostic two-by-two table

    Se = TP / (TP + FN); Sp = TN / (TN + FP); PPV = TP / (TP + FP); NPV = TN / (TN + FN)

    Sensitivity and specificity are proportions of the people with and without the target condition who receive the correct index test result, so they are conditional on disease status (the columns of the table). The predictive values are proportions of the positive and negative results that are correct, so they are conditional on the test result (the rows) and carry the prevalence of the study sample. Likelihood ratios are HE-FM-DXA-002 and predictive values at another prevalence HE-FM-DXA-003.

  • Likelihood ratios and diagnostic odds ratio from sensitivity and specificity

    LR_pos = Se / (1 - Sp); LR_neg = (1 - Se) / Sp; DOR = LR_pos / LR_neg

    The positive likelihood ratio says how many times more likely a positive result is in people with the condition than in people without it, and the negative likelihood ratio the same for a negative result. Multiplying pre-test odds by a likelihood ratio gives post-test odds. The diagnostic odds ratio is their ratio, equal to TP times TN over FP times FN.

  • Positive and negative predictive values at a given prevalence by Bayes' theorem

    PPV = Se * p / (Se * p + (1 - Sp) * (1 - p)); NPV = Sp * (1 - p) / (Sp * (1 - p) + (1 - Se) * p)

    Recomputes the predictive values for the population where the test will be used from sensitivity, specificity and the prevalence (pre-test probability) there. As prevalence falls, false positives from the larger disease-free group make up more of the positive results, so PPV falls and NPV rises. The odds form, post-test odds equal pre-test odds times the likelihood ratio (HE-FM-DXA-002), gives the same result.

  • Proportion of correct test results as a prevalence-weighted average

    Acc = p * Se + (1 - p) * Sp

    The share of results that are correct, often reported simply as accuracy, weights sensitivity by prevalence and specificity by its complement. At low prevalence it is dominated by specificity, and it counts a missed case and an unnecessary referral as equally bad.

  • Net monetary benefit per person of a triage test against no testing

    NMB = p * Se * G - (1 - p) * (1 - Sp) * L - c

    Values each true positive at its net gain G and each false positive at its cost L, both in money at a stated value of health, and subtracts the cost of the test. False negatives and true negatives fare as they would without testing, so they add nothing. Divided by G and with the test cost removed, the expression is decision-curve net benefit (HE-FM-DCA-001) at the threshold L / (G + L) (HE-FM-DCA-004).