Editverse Free Calculator
Diagnostic Accuracy Study Sample Size Calculator
Work out how many participants a diagnostic accuracy study needs. Choose sensitivity and specificity precision (Buderer), an AUC against a null value, or a comparison of two correlated AUCs.
In Simple Words
A diagnostic study needs enough participants for its estimates to be useful. For sensitivity and specificity, that means a confidence interval narrow enough to act on. For an ROC curve, it means enough cases and non-cases to show that the AUC is better than a reference value, or that one test beats another.
Enter your expected values and the precision or power you want. The calculator returns the number of people with and without the condition, and the total you must recruit. The results use normal approximations, so treat them as planning figures and confirm them with a statistician for the final protocol.
When to Use This Diagnostic Study Sample Size Calculator
Use it when you are planning a study of a new test against a reference standard and need a defensible sample size for a protocol, grant or ethics application. Pick Buderer when the aim is a confidence interval of a given width around sensitivity and specificity. Pick AUC against a null when the test gives a continuous or ordinal score and you want to show it discriminates better than a stated AUC. Pick the correlated AUC option when the same participants receive two tests.
Disease prevalence matters because sensitivity is estimated only from people with the condition and specificity only from people without it. A rare condition means you must screen many people to find enough cases. The calculator shows the total for each measure and reports the larger one as the number you need.
AUC: Var(A) = [A(1−A) + (n1−1)(Q1−A2) + (n0−1)(Q2−A2)] / (n1n0), Q1 = A/(2−A), Q2 = 2A2/(1+A). Smallest n1 (n0 = ceiling(ratio·n1)) with A−A0 ≥ z1−α/2√Var0 + zpower√Var1; precision-only: z1−α/2√Var(A) ≤ d. Paired: Var(A1−A2) = Var(A1) + Var(A2) − 2r√(Var(A1)Var(A2)).
# Sample size for diagnostic accuracy studies (base R, no packages)
goal <- "{goal}"; alpha <- {alpha}
za <- qnorm(1 - alpha / 2)
if (grepl("Buderer", goal)) {
# Buderer 1996 / Flahault 2005: n = z^2 P (1 - P) / d^2, then divide by prevalence or 1 - prevalence
se <- {se} / 100; sp <- {sp} / 100; prev <- {prev} / 100; d <- {d} / 100
n_dis <- za^2 * se * (1 - se) / d^2 # diseased needed for sensitivity (unrounded)
n_non <- za^2 * sp * (1 - sp) / d^2 # non-diseased needed for specificity (unrounded)
tot_se <- ceiling(n_dis / prev); tot_sp <- ceiling(n_non / (1 - prev))
c(diseased = ceiling(n_dis), nondiseased = ceiling(n_non),
total_sensitivity = tot_se, total_specificity = tot_sp, required_total = max(tot_se, tot_sp))
} else {
# Hanley & McNeil (1982) variance of an AUC; n0 = ceiling(ratio * n1)
A <- {auc}; A0 <- {auc0}; A2 <- {auc2}; r <- {rho}; ratio <- {ratio}
pw <- {power} / 100; dd <- {d} / 100; zb <- qnorm(pw)
hmvar <- function(A, n1, n0) {
Q1 <- A / (2 - A); Q2 <- 2 * A^2 / (1 + A)
(A * (1 - A) + (n1 - 1) * (Q1 - A^2) + (n0 - 1) * (Q2 - A^2)) / (n1 * n0)
}
# Hanley & McNeil (1983): Var(A1 - A2) = Var(A1) + Var(A2) - 2 r SE1 SE2
vd <- function(A1, A2, n1, n0) {
v1 <- hmvar(A1, n1, n0); v2 <- hmvar(A2, n1, n0); v1 + v2 - 2 * r * sqrt(v1 * v2)
}
if (grepl("correlated", goal)) {
Ab <- (A + A2) / 2; D <- abs(A - A2)
ok <- function(n1) { n0 <- ceiling(ratio * n1); D >= za * sqrt(vd(Ab, Ab, n1, n0)) + zb * sqrt(vd(A, A2, n1, n0)) }
okp <- function(n1) { n0 <- ceiling(ratio * n1); za * sqrt(vd(A, A2, n1, n0)) <= dd }
} else {
ok <- function(n1) { n0 <- ceiling(ratio * n1); A - A0 >= za * sqrt(hmvar(A0, n1, n0)) + zb * sqrt(hmvar(A, n1, n0)) }
okp <- function(n1) { n0 <- ceiling(ratio * n1); za * sqrt(hmvar(A, n1, n0)) <= dd }
}
n1 <- 2; while (!ok(n1)) n1 <- n1 + 1
p1 <- 2; while (!okp(p1)) p1 <- p1 + 1
c(positives = n1, negatives = ceiling(ratio * n1), total = n1 + ceiling(ratio * n1),
precision_only_total = p1 + ceiling(ratio * p1))
}User guide
When to use. Plan how many participants a diagnostic accuracy study needs: to estimate sensitivity and specificity with a chosen precision (Buderer), to show that an AUC exceeds a null value, or to compare the AUCs of two tests read on the same subjects.
Assumptions. Buderer: Wald (normal-approximation) intervals, so d should be small enough that the interval stays inside 0 to 100%; prevalence is the prevalence in the recruited sample. AUC: the Hanley-McNeil variance is a smooth approximation that assumes roughly binormal-like score distributions; results are for the empirical (Mann-Whitney) AUC and a normal test statistic. Paired comparison: r is the correlation between the two AUC estimates, taken as entered, and it must come from pilot data or the literature.
Common mistakes. Do not read the Buderer result as a power calculation for a hypothesis test (it targets CI width only). Do not use the AUC results for tiny samples (a few diseased cases), for partial AUC, or for clustered/multi-reader data. For an exact or very high/low sensitivity use exact-binomial planning or a dedicated package.
Worked example
Click Load example data above, then Run Analysis to see a fully worked result with figure, formula and interpretation for this test.
References
- Buderer NMF. Statistical methodology: I. Incorporating the prevalence of disease into the sample size calculation for sensitivity and specificity. Acad Emerg Med. 1996;3(9):895-900.
- Flahault A, Cadilhac M, Thomas G. Sample size calculation should be performed for design accuracy in diagnostic test studies. J Clin Epidemiol. 2005;58(8):859-862.
- Hanley JA, McNeil BJ. The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology. 1982;143(1):29-36.
- Hanley JA, McNeil BJ. A method of comparing the areas under receiver operating characteristic curves derived from the same cases. Radiology. 1983;148(3):839-843.
- Obuchowski NA. Sample size calculations in studies of test accuracy. Stat Methods Med Res. 1998;7(4):371-392.
Worked Example
Suppose you expect a sensitivity of 90% and a specificity of 85%, with a disease prevalence of 20%. You want each confidence interval to have a half-width of 5 percentage points at a 5% significance level.
Sensitivity needs 139 people with the condition, which means 692 participants in total at 20% prevalence. Specificity needs 196 people without the condition, which means 245 in total. The larger figure governs, so the required sample is 692 participants.
A second setting shows the effect of low prevalence: sensitivity 80%, specificity 95%, prevalence 10%, half-width 7.5 points and a 1% significance level. Sensitivity needs 189 cases (1888 in total) and specificity needs 57 non-cases (63 in total), so you need 1888 participants.
For an AUC test, an expected AUC of 0.80 against a null of 0.5, equal group sizes, 80% power and a 5% significance level needs 14 people in each group, 28 in total. If you would rather report the AUC with a confidence interval of plus or minus 0.05, the same inputs give 151 in each group, 302 in total. For an AUC of 0.70 against 0.6 with twice as many non-diseased as diseased participants and 90% power, the answer is 126 and 252, a total of 378.
For two tests on the same participants, AUCs of 0.80 and 0.90 with a correlation of 0.5 between the estimates, 80% power and equal groups need 61 in each group, 122 in total. A precision-only target of plus or minus 0.05 on the difference needs 242.
Assumptions to Check
- The methods are normal approximations: the Wald interval for Buderer, and the Hanley and McNeil variance formulas for AUC. They work best with moderate AUC values and adequate group sizes.
- Sensitivity and specificity near 0% or 100%, or very small samples, make the Wald interval optimistic. If the interval would cross 0 or 100%, the calculator adds a note.
- The total for Buderer assumes the prevalence in your sample equals the prevalence you entered. The other measure will then have a narrower interval than the target.
- For two AUCs, the correlation entered is used directly as the correlation between the two AUC estimates. The Hanley and McNeil lookup table that converts score correlation into this value is not implemented. The result is very sensitive to this input.
- There is no adjustment for dropout, non-evaluable results, multiple readers, clustered data or partial AUC. Inflate the final number for expected losses.
Common Mistakes
Ignoring prevalence
Calculating the number of cases and non-cases but forgetting to divide by prevalence understates the recruitment target. The totals above show how quickly it grows when prevalence is low.
Using the smaller total
Sensitivity and specificity each give a total. You need the larger of the two, otherwise one of the estimates will be less precise than planned.
Entering a score correlation as the AUC correlation
The correlation between two AUC estimates is generally lower than the correlation between the raw test scores. Entering the score correlation can understate the sample size. Use a lower, pilot-based value to be conservative.
Treating a significance test as a precision target
Showing that an AUC differs from a null value needs far fewer people than estimating the AUC precisely. In the example above, 28 participants can show AUC 0.80 against 0.5 (the approximation is poor at such small sizes, so treat 28 as a lower bound), but 302 are needed for an interval of plus or minus 0.05. Decide which question the study must answer.
Frequently Asked Questions
Which sample size method should I choose?
Use Buderer for sensitivity and specificity at a chosen threshold. Use the AUC options when the test produces a score and you want to judge it across thresholds.
Why is the total much larger than the number of cases?
Only a fraction of participants have the condition. With 20% prevalence, 139 cases require 692 participants in total.
Does the calculator include power for sensitivity and specificity?
No. The Buderer option targets confidence interval width only and does not use power. Power applies to the AUC options.
Can I use these numbers as final?
Use them for planning. The methods are approximations, so check the final figure with a statistician, especially for small samples, extreme values or complex designs.
What does the group ratio do?
It sets how many non-diseased participants you enrol for each diseased participant in the AUC options. A ratio of 2 gave 126 and 252 in the example above.
Related Calculators
ROC Curve and AUC CalculatorDiagnostic Accuracy CalculatorSample Size and Power CalculatorPrevalence CalculatorConfidence Interval CalculatorSTARD and Diagnostic Accuracy Studies
References
- Buderer NM. Statistical methodology: I. Incorporating the prevalence of disease into the sample size calculation for sensitivity and specificity. Acad Emerg Med. 1996;3(9):895-900. PMID 8870764
- Hanley JA, McNeil BJ. The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology. 1982. PMID 7063747
- Hanley JA, McNeil BJ. A method of comparing the areas under receiver operating characteristic curves derived from the same cases. Radiology. 1983. PMID 6878708
- Flahault A, Cadilhac M, Thomas G. Sample size calculation should be performed for design accuracy in diagnostic test studies. J Clin Epidemiol. 2005. PMID 16018921
Need This Analysis Done for Your Manuscript?
Need the sample size section of your protocol written, checked or justified for a funder or ethics board? Editverse statisticians can prepare and review it with you.
