Skip to content

Predictive values and the base rate

Read across the rows. PPV and NPV answer the patient's question, and they belong to a test and a population together.

Introductory ~11 min9 steps

What runs in CodeSplash

You will be able to

  • Compute PPV and NPV from a table and from sensitivity, specificity and prevalence
  • Explain why a study's predictive values may not apply to your setting
  • Recalculate predictive values at the prevalence you care about

Read first

01

The other question

Read

Sensitivity starts from people whose disease status is known. A patient holding a positive scan asks the reverse: do I have the disease? For that, read across the row.

PPV=TPTP+FPNPV=TNTN+FN\text{PPV} = \frac{TP}{TP + FP} \qquad \text{NPV} = \frac{TN}{TN + FN}

In the liver-scan study the positive predictive valuePositive predictive valueOf those who test positive, the share who really are; it falls sharply when the condition is rare. is 0.878 and the negative predictive valueNegative predictive valueOf those who test negative, the share who really are negative. is 0.667.

02

From the lab to the clinic

Predict

Predict first

A lab tries a new test on 100 known cases and 100 healthy volunteers. Sensitivity and specificity are both 90%, and so is its PPV.

A clinic will use it where 1 patient in 100 has the disease. What PPV should the clinic expect?

About 90%About 50%About 8%
Reveal

About 8%. Among 10,000 clinic patients, 100 have the disease and 90 of them test positive. Of the 9,900 without it, 990 test positive. So 90/1080≈0.0890 / 1080 \approx 0.08. The lab's 90% came from its own half-and-half mix of patients.

03

Find the coin toss

Explore

Answer the prompt, then leave Sensitivity and Specificity where they are. Move Prevalence until PPV is near 0.5. Now lower Specificity and find the new point.

HExplorable · What a positive test means

If a good test comes back positive, how likely is the disease?

A person tests positive. What is the chance they have the disease?

0.50
How sure?
0.950
0.950
0.020
  • Disease, test +: 19
  • No disease, test + (false positive): 49
  • Disease, test − (missed): 1
  • No disease, test −: 931

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

With a sensitive test, a positive result becomes a coin toss roughly where prevalence meets the false-positive rate, 1−Sp1 - \text{Sp}. Below that point, most positives are false.

04

The formula behind the slider

Read

This is Bayes' rule, with prevalence π\pi as the prior:

PPV=Se πSe π+(1−Sp)(1−π)NPV=Sp (1−π)Sp (1−π)+(1−Se) π\text{PPV} = \frac{\text{Se}\,\pi}{\text{Se}\,\pi + (1 - \text{Sp})(1 - \pi)} \qquad \text{NPV} = \frac{\text{Sp}\,(1 - \pi)}{\text{Sp}\,(1 - \pi) + (1 - \text{Se})\,\pi}

As π\pi falls, PPV falls and NPV rises. So predictive values belong to a test and a population. If a study chose its mix of cases and controls, its sample prevalence means nothing, and neither do its raw predictive values.

05

Set your own prevalence

In the app

Turn on Predictive values at another prevalence and enter the Population prevalence. The card adds PPV and NPV rows for that setting.

Diagnostic accuracyRecorded · Python and R agreeRecorded 2026-11-17 · 49 values compared · largest relative difference 1.3e-15
R

sensitivity = .80, specificity = 1.00, LR+ = ∞, LR− = 0.20

Sensitivity
0.8000
Specificity
1
Positive predictive value
1
Negative predictive value
0.8696

Effect size

  • Diagnostic odds ratio 146.43 95% CI [6.966, 3078.06]
  • Youden's J 0.8000 95% CI [0.5976, 1.002]

Plots

Confusion matrix: rapid test against cultureHow often is each class predicted correctly, which errors does the model make, and what do sensitivity, specificity, precision and the other rates come to?

Positive: culture = true (reference) and rapid test = true (test).

View data
Reference: cultureCountTest: rapid test
Positive12Positive
Positive3Negative
Negative0Positive
Negative20Negative

Assumptions

  • No empty cells — Empty false positive cell: likelihood ratios can be infinite or undefined; 0.5 was added to every cell for the DOR.
  • Everyone verified by the reference — Rows missing either result were left out; if the reference was applied selectively, sensitivity and specificity are biased.

Test × reference

rapid test \ culturetrue (condition)false (no condition)Total
true (positive)12012
false (negative)32023
Total152035

Accuracy measures (95% CI; proportions Wilson)

MeasureEstimateCI lowCI high
Sensitivity0.80000.54810.9295
Specificity10.83891
Positive predictive value10.75751
Negative predictive value0.86960.67870.9546
Accuracy0.91430.77620.9704
Prevalence (sample)0.42860.27980.5914
Likelihood ratio +∞——
Likelihood ratio −0.20000.07270.5503
Diagnostic odds ratio146.436.9663078.06
Youden's J0.80000.59761.002
Balanced accuracy0.90000.79881.001
PPV at prevalence 0.051——
NPV at prevalence 0.050.9896——
F1 score0.8889——
Matthews correlation0.8341——
  • Positive test: rapid test = true; condition present: culture = true. Likelihood-ratio intervals: Simel et al. (1991). Prevalence-adjusted predictive values: Mercaldo et al. (2007) logit intervals.
The exact R script · R R version 4.5.1 (2025-06-13)
# Diagnostic accuracy (sensitivity, specificity, PPV, NPV)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method diagnostic.accuracy 1.0.2 · spec 94a11659571920b2
# Dataset: rapid_test (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_diag_accuracy (twin of codesplash.stats.diagnostic)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/rapid_test.parquet", col_select = c("rapid test", "culture")))
n_input <- nrow(df)
df[["rapid test"]] <- factor(df[["rapid test"]], levels = c("false", "true"))  # stored level order
df[["culture"]] <- factor(df[["culture"]], levels = c("false", "true"))  # stored level order
df <- df[stats::complete.cases(df[c("rapid test", "culture")]), , drop = FALSE]  # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
  warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("rapid test", "culture"))  # infinite values stop the run (registry/errors.yaml)

# %% Test
t <- "rapid test"
r <- "culture"
test_levels <- c("false", "true")  # stored level order
ref_levels <- c("false", "true")
test_pos <- test_levels[length(test_levels)]  # default: the last level ("true")
ref_pos <- ref_levels[length(ref_levels)]  # condition-present level
test_neg <- setdiff(test_levels, test_pos)[1]
ref_neg <- setdiff(ref_levels, ref_pos)[1]
is_tp <- as.character(df[[t]]) == test_pos
is_dp <- as.character(df[[r]]) == ref_pos
tp <- sum(is_tp & is_dp)
fp <- sum(is_tp & !is_dp)
fn <- sum(!is_tp & is_dp)
tn <- sum(!is_tp & !is_dp)
# Sensitivity and specificity need rows with and without the condition.
k_ref <- (tp + fn > 0) + (fp + tn > 0)
if (k_ref < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = r, min = 2, k = k_ref)
conf <- 0.95
ci_method <- "wilson"
prevalence <- 0.05  # population prevalence (optional)

acc <- cs_diag_accuracy(tp, fp, fn, tn, conf = conf, ci_method = ci_method, prevalence = prevalence)

# %% Assumptions
cell_names <- c("true positive", "false positive", "false negative", "true negative")
zero <- cell_names[c(tp, fp, fn, tn) == 0]
assumptions <- list(
  list(key = "cells", label = "No empty cells", status = if (length(zero)) "warn" else "pass",
       detail = if (length(zero)) paste0("Empty ", paste(zero, collapse = " and "), " cell: likelihood ratios can be infinite or undefined; 0.5 was added to every cell for the DOR.") else "Every cell has at least one subject."),
  list(key = "verification", label = "Everyone verified by the reference", status = "info",
       detail = "Rows missing either result were left out; if the reference was applied selectively, sensitivity and specificity are biased.")
)

# %% Result
ci_label <- c("clopper-pearson" = "Clopper–Pearson", wilson = "Wilson", jeffreys = "Jeffreys", "agresti-coull" = "Agresti–Coull")[[ci_method]]
measures <- list(
  c("sensitivity", "Sensitivity"), c("specificity", "Specificity"), c("ppv", "Positive predictive value"), c("npv", "Negative predictive value"),
  c("accuracy", "Accuracy"), c("prevalence", "Prevalence (sample)"), c("lr_pos", "Likelihood ratio +"), c("lr_neg", "Likelihood ratio −"),
  c("dor", "Diagnostic odds ratio"), c("youden", "Youden's J"), c("balanced_accuracy", "Balanced accuracy")
)
if (!is.null(prevalence)) {
  measures <- c(measures, list(c("ppv_adj", sprintf("PPV at prevalence %s", format(prevalence))), c("npv_adj", sprintf("NPV at prevalence %s", format(prevalence)))))
}
rows <- lapply(measures, function(m) list(measure = m[2], estimate = acc[[m[1]]], ci_low = acc[[paste0(m[1], "_ci_low")]], ci_high = acc[[paste0(m[1], "_ci_high")]]))
rows <- c(rows, list(list(measure = "F1 score", estimate = acc$f1, ci_low = NULL, ci_high = NULL),
                     list(measure = "Matthews correlation", estimate = acc$mcc, ci_low = NULL, ci_high = NULL)))
pct <- sprintf("%.0f%%", conf * 100)
summary <- sprintf("Sensitivity %.1f%% (%d/%d), specificity %.1f%% (%d/%d), PPV %.1f%%, NPV %.1f%%; LR+ %s, LR− %s.",
                   100 * acc$sensitivity, tp, tp + fn, 100 * acc$specificity, tn, tn + fp, 100 * acc$ppv, 100 * acc$npv,
                   cs_fmt_num(acc$lr_pos), cs_fmt_num(acc$lr_neg))
values <- acc
values$test_positive <- test_pos
values$reference_positive <- ref_pos
cs_publish(list(
  method = "diagnostic.accuracy",
  methodVersion = "1.0.2",
  title = "Diagnostic accuracy",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = tp + fp + fn + tn,
  summary = summary,
  apa = sprintf("sensitivity = %s, specificity = %s, LR+ = %s, LR− = %s", cs_fmt_num(acc$sensitivity, leading_zero = FALSE),
                cs_fmt_num(acc$specificity, leading_zero = FALSE), cs_fmt_num(acc$lr_pos), cs_fmt_num(acc$lr_neg)),
  statistics = lapply(measures[1:4], function(m) list(key = m[1], label = m[2], value = acc[[m[1]]])),
  tables = list(
    list(key = "confusion", title = "Test × reference",
         columns = list(list(key = "row", label = paste(t, "\\", r), type = "string"), list(key = "pos", label = paste(ref_pos, "(condition)"), type = "integer"),
                        list(key = "neg", label = paste(ref_neg, "(no condition)"), type = "integer"), list(key = "total", label = "Total", type = "integer")),
         rows = list(list(row = paste(test_pos, "(positive)"), pos = tp, neg = fp, total = tp + fp),
                     list(row = paste(test_neg, "(negative)"), pos = fn, neg = tn, total = fn + tn),
                     list(row = "Total", pos = tp + fn, neg = fp + tn, total = tp + fp + fn + tn))),
    list(key = "measures", title = sprintf("Accuracy measures (%s CI; proportions %s)", pct, ci_label),
         columns = list(list(key = "measure", label = "Measure", type = "string"), list(key = "estimate", label = "Estimate", type = "number"),
                        list(key = "ci_low", label = "CI low", type = "number"), list(key = "ci_high", label = "CI high", type = "number")),
         rows = rows)
  ),
  effectSizes = list(
    list(key = "dor", label = "Diagnostic odds ratio", value = acc$dor, ciLow = acc$dor_ci_low, ciHigh = acc$dor_ci_high, ciLevel = conf,
         method = paste0("Woolf log interval", if (acc$dor_corrected == 1) " (0.5 added to every cell)" else "")),
    list(key = "youden", label = "Youden's J", value = acc$youden, ciLow = acc$youden_ci_low, ciHigh = acc$youden_ci_high, ciLevel = conf,
         method = "Se + Sp − 1, Wald interval")
  ),
  assumptions = assumptions,
  warnings = warnings,
  notes = list(paste0(sprintf("Positive test: %s = %s; condition present: %s = %s. Likelihood-ratio intervals: Simel et al. (1991).", t, test_pos, r, ref_pos),
                      if (!is.null(prevalence)) " Prevalence-adjusted predictive values: Mercaldo et al. (2007) logit intervals." else "")),
  # Chart Lab `confusion-matrix`: reference in rows, test in columns, condition-present first (TP top left).
  # Its intervals are Wilson intervals, so they show only when the method's own interval is Wilson too.
  charts = list(cs_chart(
    "confusion", "confusion-matrix", sprintf("Confusion matrix: %s against %s", t, r),
    list(actual = cs_col(paste0("Reference: ", r), c("Positive", "Positive", "Negative", "Negative"), levels = c("Positive", "Negative")),
         predicted = cs_col(paste0("Test: ", t), c("Positive", "Negative", "Positive", "Negative"), levels = c("Positive", "Negative")),
         count = cs_col("Count", as.numeric(c(tp, fn, fp, tn)), kind = "numeric")),
    controls = list(positive = "first", view = "compact", intervals = identical(ci_method, "wilson")),
    note = sprintf("Positive: %s = %s (reference) and %s = %s (test).", r, ref_pos, t, test_pos)
  )),
  values = values
))
Python

sensitivity = .80, specificity = 1.00, LR+ = ∞, LR− = 0.20

Sensitivity
0.8000
Specificity
1
Positive predictive value
1
Negative predictive value
0.8696

Effect size

  • Diagnostic odds ratio 146.43 95% CI [6.966, 3078.06]
  • Youden's J 0.8000 95% CI [0.5976, 1.002]

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • No empty cells — Empty false positive cell: likelihood ratios can be infinite or undefined; 0.5 was added to every cell for the DOR.
  • Everyone verified by the reference — Rows missing either result were left out; if the reference was applied selectively, sensitivity and specificity are biased.

Test × reference

rapid test \ culturetrue (condition)false (no condition)Total
true (positive)12012
false (negative)32023
Total152035

Accuracy measures (95% CI; proportions Wilson)

MeasureEstimateCI lowCI high
Sensitivity0.80000.54810.9295
Specificity10.83891
Positive predictive value10.75751
Negative predictive value0.86960.67870.9546
Accuracy0.91430.77620.9704
Prevalence (sample)0.42860.27980.5914
Likelihood ratio +∞——
Likelihood ratio −0.20000.07270.5503
Diagnostic odds ratio146.436.9663078.06
Youden's J0.80000.59761.002
Balanced accuracy0.90000.79881.001
PPV at prevalence 0.051——
NPV at prevalence 0.050.9896——
F1 score0.8889——
Matthews correlation0.8341——
  • Positive test: rapid test = true; condition present: culture = true. Likelihood-ratio intervals: Simel et al. (1991). Prevalence-adjusted predictive values: Mercaldo et al. (2007) logit intervals.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Diagnostic accuracy (sensitivity, specificity, PPV, NPV)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method diagnostic.accuracy 1.0.2 · spec 94a11659571920b2
# Dataset: rapid_test (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import math

import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.stats import diagnostic as csd  # every accuracy measure (twin of codesplashr::cs_diag_accuracy)

# %% Data
df = pd.read_parquet("tests/parity/fixtures/rapid_test.parquet", columns=["rapid test", "culture"])
n_input = len(df)
df["rapid test"] = pd.Categorical(df["rapid test"], categories=["false", "true"])  # stored level order
df["culture"] = pd.Categorical(df["culture"], categories=["false", "true"])  # stored level order
df = df.dropna(subset=["rapid test", "culture"])  # listwise deletion over the analysis columns
df["rapid test"] = df["rapid test"].cat.remove_unused_categories()
df["culture"] = df["culture"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
    warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["rapid test", "culture"])  # infinite values stop the run (registry/errors.yaml)

# %% Test
t, r = "rapid test", "culture"
test_levels = ["false", "true"]  # stored level order
ref_levels = ["false", "true"]
test_pos = test_levels[-1]  # default: the last level ("true")
ref_pos = ref_levels[-1]  # condition-present level
test_neg = next(lv for lv in test_levels if lv != test_pos)
ref_neg = next(lv for lv in ref_levels if lv != ref_pos)
tp_ = df[t].astype(str) == test_pos
dp_ = df[r].astype(str) == ref_pos
tp, fp = int((tp_ & dp_).sum()), int((tp_ & ~dp_).sum())
fn, tn = int((~tp_ & dp_).sum()), int((~tp_ & ~dp_).sum())
# Sensitivity and specificity need rows with and without the condition.
k_ref = int(tp + fn > 0) + int(fp + tn > 0)
if k_ref < 2:
    cs.cs_error("CS_E_TOO_FEW_GROUPS", column=r, min=2, k=k_ref)
conf = 0.95
ci_method = "wilson"
prevalence = 0.05  # population prevalence (optional)

acc = csd.accuracy(tp, fp, fn, tn, conf=conf, ci_method=ci_method, prevalence=prevalence)

# %% Assumptions
zero = [name for name, x in (("true positive", tp), ("false positive", fp), ("false negative", fn), ("true negative", tn)) if x == 0]
assumptions = [
    {"key": "cells", "label": "No empty cells", "status": "warn" if zero else "pass",
     "detail": ("Empty " + " and ".join(zero) + " cell: likelihood ratios can be infinite or undefined; 0.5 was added to every cell for the DOR.") if zero else "Every cell has at least one subject."},
    {"key": "verification", "label": "Everyone verified by the reference", "status": "info",
     "detail": "Rows missing either result were left out; if the reference was applied selectively, sensitivity and specificity are biased."},
]

# %% Result
ci_label = {"clopper-pearson": "Clopper–Pearson", "wilson": "Wilson", "jeffreys": "Jeffreys", "agresti-coull": "Agresti–Coull"}[ci_method]
measures = [
    ("sensitivity", "Sensitivity"), ("specificity", "Specificity"), ("ppv", "Positive predictive value"), ("npv", "Negative predictive value"),
    ("accuracy", "Accuracy"), ("prevalence", "Prevalence (sample)"), ("lr_pos", "Likelihood ratio +"), ("lr_neg", "Likelihood ratio −"),
    ("dor", "Diagnostic odds ratio"), ("youden", "Youden's J"), ("balanced_accuracy", "Balanced accuracy"),
]
if prevalence is not None:
    measures += [("ppv_adj", f"PPV at prevalence {prevalence:g}"), ("npv_adj", f"NPV at prevalence {prevalence:g}")]
rows = [{"measure": label, "estimate": acc[k], "ci_low": acc.get(f"{k}_ci_low"), "ci_high": acc.get(f"{k}_ci_high")} for k, label in measures]
rows += [{"measure": "F1 score", "estimate": acc["f1"], "ci_low": None, "ci_high": None},
         {"measure": "Matthews correlation", "estimate": acc["mcc"], "ci_low": None, "ci_high": None}]
summary = (
    f"Sensitivity {acc['sensitivity']:.1%} ({tp}/{tp + fn}), specificity {acc['specificity']:.1%} ({tn}/{tn + fp}), "
    f"PPV {acc['ppv']:.1%}, NPV {acc['npv']:.1%}; LR+ {cs.fmt_num(acc['lr_pos'])}, LR− {cs.fmt_num(acc['lr_neg'])}."
)
values = {k: v for k, v in acc.items()}
values.update({"test_positive": test_pos, "reference_positive": ref_pos})
cs.publish({
    "method": "diagnostic.accuracy",
    "methodVersion": "1.0.2",
    "title": "Diagnostic accuracy",
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": tp + fp + fn + tn,
    "summary": summary,
    "apa": f"sensitivity = {cs.fmt_num(acc['sensitivity'], leading_zero=False)}, specificity = {cs.fmt_num(acc['specificity'], leading_zero=False)}, "
           f"LR+ = {cs.fmt_num(acc['lr_pos'])}, LR− = {cs.fmt_num(acc['lr_neg'])}",
    "statistics": [{"key": k, "label": label, "value": acc[k]} for k, label in measures[:4]],
    "tables": [
        {"key": "confusion", "title": "Test × reference",
         "columns": [{"key": "row", "label": f"{t} \\ {r}", "type": "string"}, {"key": "pos", "label": f"{ref_pos} (condition)", "type": "integer"},
                     {"key": "neg", "label": f"{ref_neg} (no condition)", "type": "integer"}, {"key": "total", "label": "Total", "type": "integer"}],
         "rows": [{"row": f"{test_pos} (positive)", "pos": tp, "neg": fp, "total": tp + fp},
                  {"row": f"{test_neg} (negative)", "pos": fn, "neg": tn, "total": fn + tn},
                  {"row": "Total", "pos": tp + fn, "neg": fp + tn, "total": tp + fp + fn + tn}]},
        {"key": "measures", "title": f"Accuracy measures ({conf:.0%} CI; proportions {ci_label})",
         "columns": [{"key": "measure", "label": "Measure", "type": "string"}, {"key": "estimate", "label": "Estimate", "type": "number"},
                     {"key": "ci_low", "label": "CI low", "type": "number"}, {"key": "ci_high", "label": "CI high", "type": "number"}],
         "rows": rows},
    ],
    "effectSizes": [
        {"key": "dor", "label": "Diagnostic odds ratio", "value": acc["dor"], "ciLow": acc["dor_ci_low"], "ciHigh": acc["dor_ci_high"], "ciLevel": conf,
         "method": "Woolf log interval" + (" (0.5 added to every cell)" if acc["dor_corrected"] else "")},
        {"key": "youden", "label": "Youden's J", "value": acc["youden"], "ciLow": acc["youden_ci_low"], "ciHigh": acc["youden_ci_high"], "ciLevel": conf,
         "method": "Se + Sp − 1, Wald interval"},
    ],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"Positive test: {t} = {test_pos}; condition present: {r} = {ref_pos}. Likelihood-ratio intervals: Simel et al. (1991)."
              + (f" Prevalence-adjusted predictive values: Mercaldo et al. (2007) logit intervals." if prevalence is not None else "")],
    # Chart Lab `confusion-matrix`: reference in rows, test in columns, condition-present first (TP top left).
    # Its intervals are Wilson intervals, so they show only when the method's own interval is Wilson too.
    "charts": [cs.chart(
        "confusion", "confusion-matrix", f"Confusion matrix: {t} against {r}",
        {"actual": cs.col(f"Reference: {r}", ["Positive", "Positive", "Negative", "Negative"], levels=["Positive", "Negative"]),
         "predicted": cs.col(f"Test: {t}", ["Positive", "Negative", "Positive", "Negative"], levels=["Positive", "Negative"]),
         "count": cs.col("Count", [tp, fn, fp, tn], kind="numeric")},
        controls={"positive": "first", "view": "compact", "intervals": ci_method == "wilson"},
        note=f"Positive: {r} = {ref_pos} (reference) and {t} = {test_pos} (test).",
    )],
    "values": values,
})

This illustrative rapid test has a sample prevalence of 42.9%, and NPV 0.870. At a prevalence of 5%, NPV becomes 0.990. PPV stays at 100%.

06

Don't trust that 100%

Predict

Predict first

PPV shows 100% because the test gave no false positives, among only 20 people without disease. Specificity's interval reaches down to 0.839.

If that lower limit were the truth, what would PPV be at a prevalence of 5%?

PPV stays above 80%PPV falls to about 50%PPV falls to about 20%
Reveal

About 20%:

0.80×0.050.80×0.05+0.161×0.95≈0.21\frac{0.80 \times 0.05}{0.80 \times 0.05 + 0.161 \times 0.95} \approx 0.21

At low prevalence, specificity controls PPV, and a small study can't pin specificity down.

07

Same formula, two dialects

Read
Python
def predictive_values(se, sp, prevalence):
    ppv = se * prevalence / (se * prevalence + (1 - sp) * (1 - prevalence))
    npv = sp * (1 - prevalence) / (sp * (1 - prevalence) + (1 - se) * prevalence)
    return ppv, npv


se, sp = 231 / 258, 54 / 86  # the liver scan
print(predictive_values(se, sp, 258 / 344))  # its own sample
print(predictive_values(se, sp, 0.10))  # a setting with 10% prevalence
R
predictive_values <- function(se, sp, prevalence) {
  c(ppv = se * prevalence / (se * prevalence + (1 - sp) * (1 - prevalence)),
    npv = sp * (1 - prevalence) / (sp * (1 - prevalence) + (1 - se) * prevalence))
}

se <- 231 / 258; sp <- 54 / 86  # the liver scan
predictive_values(se, sp, 258 / 344)  # its own sample
predictive_values(se, sp, 0.10)  # a setting with 10% prevalence
08

Check your understanding

Checkpoint

Check yourself

A test has sensitivity 80% and specificity 90%, and prevalence is 5%. What is the PPV? Give three decimals.

Show the answer

Answer: 0.296

True positives: 0.80 × 0.05 = 0.04. False positives: 0.10 × 0.95 = 0.095. PPV = 0.04 / 0.135.

Check yourself

You take the same test to a population where the condition is much rarer. If sensitivity and specificity hold, what happens?

Show the answer

Answer: c

With fewer true cases, more of the positives are false, and more of the negatives are right.

Check yourself

A study recruits 200 cases and 200 controls. What can you report directly from its table?

Show the answer

Answer: b

The researchers chose the half-and-half mix, so the sample prevalence isn't an estimate of anything. Sensitivity and specificity condition on case status and don't use that mix directly.

09

Recap

Recap
  • PPV and NPV read across the rows, and answer what a result means for a person.
  • They depend on prevalence: state which population you mean.
  • At low prevalence, specificity controls PPV, so its interval matters.
  • Use the prevalence option to report predictive values for your own setting.

Concepts in this lesson