Sample size calculator for a two-arm trial
This sample size calculator gives the number of people a two-arm randomized trial needs to detect a difference between two proportions or two means, with the power and significance level you choose. For means it’s roughly n = 2σ²(z₁₋α/₂ + z₁₋β)² ÷ Δ² a group, refined with the exact t test, and each group is then divided by one minus the dropout rate.
Updated
Runs in your browser. Nothing you enter is uploaded, stored or sent anywhere.
How the sample size is calculated
The calculator finds the smallest trial whose test would reject “no difference” with the power you ask for, if the true difference were the one you enter. It uses the same power equations as R’s power.t.test and power.prop.test, set out with unequal groups in the PASS documentation for two means and two proportions. Here r is the allocation ratio n₂ ÷ n₁, and s is 2 for a two-sided test and 1 for a one-sided one.
| Outcome | Formula |
|---|---|
| Two means: power | P(T′ > t₁₋α/s), with T′ a noncentral t on n₁ + n₂ − 2 df and noncentrality λ = Δ ÷ (σ√(1/n₁ + 1/n₂)) |
| Two means: normal approximation | n₁ = (1 + 1/r) σ² (z₁₋α/s + z₁₋β)² ÷ Δ² |
| Two proportions: power | Φ((|p₁ − p₂| − z₁₋α/s σ₀) ÷ σ₁), with σ₀ = √(p̄q̄(1/n₁ + 1/n₂)), σ₁ = √(p₁q₁/n₁ + p₂q₂/n₂) and p̄ = (n₁p₁ + n₂p₂) ÷ (n₁ + n₂) |
| With the continuity correction | Subtract ½(1/n₁ + 1/n₂) from |p₁ − p₂| |
| Whole numbers | The smallest whole n₁, with n₂ = ⌈r × n₁⌉, that reaches the power |
| Dropout, d | ⌈n ÷ (1 − d)⌉ enrolled in each group |
Exact t, not just the normal formula
Textbook formulas for two means use the normal distribution, as if σ were known. The trial will be analysed with a t test, so the calculator solves the t test’s own power equation, with the noncentral t computed by Lenth’s algorithm as R does, and shows the normal answer beside it. The difference is a person or two a group, and it matters most for small trials. As in R’s default, a two-sided test counts only rejections in the direction of the effect.
Proportions: the chi-squared test
For proportions the test is the pooled z test, which is the chi-squared test for a 2 × 2 table. With equal groups this is exactly R’s power.prop.test. The continuity-corrected version reproduces the sample sizes Fleiss, Levin and Paik publish, but the PASS documentation adds that “in practice, this adjustment is not recommended because it reduces the power and the actual alpha of the test procedure”.
Dropout
People lost before the outcome is measured don’t count toward the power, so each group is divided by one minus the dropout rate (Althubaiti 2023; PASS), and rounded up.
Worked example: 50% against 75%
The calculator opens on the example in R’s documentation for power.prop.test: 50% of group 1 and 75% of group 2 with the outcome, 90% power and a two-sided α of 0.05, plus a 10% dropout rate, which is about what Althubaiti says to expect in clinical research.
Example: Working it through
With z₁₋α/₂ = 1.960 and z₁₋β = 1.282, solving the power equation gives n = 76.71 a group, the 76.7 that R reports.
Rounded up, that’s 77 a group, 154 in all, with an actual power of 90.1%.
Allowing for 10% dropout, 77 ÷ 0.9 = 85.6, so enrol 86 a group, 172 in all.
Two means: where the t test adds people
Machin and colleagues’ example, as the PASS documentation reproduces it, is a difference of 5 with an SD of 10 (a standardized difference of 0.5), 90% power and a two-sided α of 0.05. The normal formula gives 2 × 10² × (1.960 + 1.282)² ÷ 5² = 84.06, so 85 a group. The noncentral t gives 86 a group (power 0.903), the 86 that Machin and colleagues and PASS give.
Checked against R and PASS
The tests for this page reproduce every example that R’s power.prop.test documents, the noncentral t that power.t.test uses, and the validation examples in the PASS documentation:
| Example | Published | This calculator |
|---|---|---|
| R: p = 0.50 and 0.75, n = 50 a group | power 0.740 | 0.740 |
| R: p = 0.50 and 0.75, 90% power | n = 76.7 | 76.71 |
| R: p = 0.90 and 1.0, 80% power | n = 73.37 | 73.37 |
| PASS (Ryan): p = 0.65 and 0.55, one-sided, 80% power | 296 a group | 296 |
| PASS (Fleiss et al), continuity corrected: p = 0.25 and 0.40, α = 0.01, 95% power, r = 0.5 | 531 and 266 | 531 and 266 |
| PASS (Zar): Δ = 1, σ = 0.7206, 15 a group | power 0.95611 | 0.95611 |
| PASS (Julious): Δ = 0.05, σ = 1, 90% power | 8,407 a group | 8,407 |
Published results the calculator reproduces.
R: p = 0.50 and 0.75, n = 50 a group
- Published
- power 0.740
- This calculator
- 0.740
R: p = 0.50 and 0.75, 90% power
- Published
- n = 76.7
- This calculator
- 76.71
R: p = 0.90 and 1.0, 80% power
- Published
- n = 73.37
- This calculator
- 73.37
PASS (Ryan): p = 0.65 and 0.55, one-sided, 80% power
- Published
- 296 a group
- This calculator
- 296
PASS (Fleiss et al), continuity corrected: p = 0.25 and 0.40, α = 0.01, 95% power, r = 0.5
- Published
- 531 and 266
- This calculator
- 531 and 266
PASS (Zar): Δ = 1, σ = 0.7206, 15 a group
- Published
- power 0.95611
- This calculator
- 0.95611
PASS (Julious): Δ = 0.05, σ = 1, 90% power
- Published
- 8,407 a group
- This calculator
- 8,407
Before you rely on the number
- A test of no difference. These are superiority designs that test for any difference. PASS notes that powering for a difference of Δ means you can reject “no difference” if Δ is true, not that you’ll show the difference is at least Δ. Non-inferiority and equivalence trials need other formulas.
- The inputs are guesses. The SD and the control group’s rate come from earlier studies. PASS suggests trying a range of SDs to see how much the answer moves, and taking the upper confidence limit of a pilot study’s SD for a conservative plan.
- Two independent groups. One measurement per person, randomized individually. Cluster, crossover and repeated-measures designs need their own formulas.
- Dropout at random. Dividing by one minus the dropout rate keeps the power only if the people lost are like those who stay.
What to report
What to report: Give enough for someone to repeat the calculation
State the outcome, the difference the trial is powered to detect and where it came from, the control rate or SD, α and whether it’s one- or two-sided, the power, the allocation ratio, the dropout allowance and the method. The summary under the result is a starting point.
Systematic reviewers use the same sum the other way round. The Cochrane Handbook describes the optimal information size, “calculated on the basis of the number of participants required for an adequately powered individual study”, as one way to judge imprecision in GRADE.
Frequently asked questions
How do I calculate the sample size for comparing two proportions?
Enter the proportion you expect in each group, the power and α. The calculator solves the chi-squared test’s power equation for n, rounds up, and then allows for dropout. For 50% against 75% with 90% power at α = 0.05, it’s 77 a group before dropout.
Why is the answer for means bigger than the textbook formula?
The textbook formula uses the normal distribution, as if the SD were known exactly. The analysis will use a t test, which needs a little more data, so the calculator solves the t test’s power equation. In Machin and colleagues’ example that’s 86 a group against the formula’s 85.
How do I adjust the sample size for dropout?
Divide by one minus the dropout rate and round up. If you need 100 analysed and expect 20% to drop out, enrol 100 ÷ 0.8 = 125. Multiplying by 1.2 instead gives 120, and losing 20% of 120 leaves only 96.
Do unequal groups need more people?
Yes. For a difference of 5 with an SD of 10 and 90% power, equal groups need 172 in all; two to one needs 64 and 128, 192 in all; three to one needs 228.
Can I use this for the optimal information size in GRADE?
Yes. The optimal information size is the sample size of one adequately powered trial, so enter the control group’s risk from your review, the effect you’d consider important, and the usual 80% or 90% power. Then compare the total with the number of participants in your meta-analysis.
How to cite this tool
OtterSR. Sample size calculator for a two-arm trial. https://www.ottersr.com/tools/sample-size-calculator (accessed today’s date).
Please cite the method as well:
NCSS. Chapter 422: Two-sample t-tests assuming equal variance. PASS Sample Size Software documentation. NCSS, LLC.
NCSS. Chapter 200: Tests for two proportions. PASS Sample Size Software documentation. NCSS, LLC.
Related guides
- How to rate the certainty of evidence with GRADEHow GRADE rates the certainty of evidence per outcome: four levels, five reasons to rate down, three to rate up, and what goes in a summary of findings table.
- How to do a systematic review, step by stepHow to do a systematic review step by step, from the question and protocol to search, screening, extraction, risk of bias, synthesis, GRADE and PRISMA 2020.
Related tools
- Standard deviation from a confidence interval or standard errorUse this when a study gives a mean with its SE or CI, or a mean difference with its CI, t or P value, and you need the SD.
- Convert median and IQR to mean and SDUse this when a study reports a median with its IQR or range and your meta-analysis needs a mean and SD.
Sources
- R Core Team. power.t.test: power calculations for one and two sample t tests. R documentation, package stats version 4.6.2. https://search.r-project.org/R/refmans/stats/html/power.t.test.html
- R Core Team. power.prop.test: power calculations for two-sample test for proportions. R documentation, package stats version 4.6.2. https://search.r-project.org/R/refmans/stats/html/power.prop.test.html
- NCSS. Chapter 422: Two-sample t-tests assuming equal variance. PASS Sample Size Software documentation. NCSS, LLC. https://www.ncss.com/wp-content/themes/ncss/pdf/Procedures/PASS/Two-Sample_T-Tests_Assuming_Equal_Variance.pdf
- NCSS. Chapter 200: Tests for two proportions. PASS Sample Size Software documentation. NCSS, LLC. https://www.ncss.com/wp-content/themes/ncss/pdf/Procedures/PASS/Tests_for_Two_Proportions.pdf
- R Core Team. TDist: the Student t distribution, including the non-central t. R documentation, package stats version 4.6.2. https://search.r-project.org/R/refmans/stats/html/TDist.html
- Althubaiti A. Sample size determination: a practical guide for health researchers. Journal of General and Family Medicine 2023;24(2):72–78. https://doi.org/10.1002/jgf2.600
- Schünemann HJ, Higgins JP, Vist GE, et al. Chapter 14: Completing ‘Summary of findings’ tables and grading the certainty of the evidence [last updated August 2023]. In: Higgins JP, Thomas J, Chandler J, et al (editors). Cochrane Handbook for Systematic Reviews of Interventions version 6.5. Cochrane, 2024. https://www.cochrane.org/authors/handbooks-and-manuals/handbook/current/chapter-14