BiostatKit Tiếng Việt

BiostatKit / Sample size / Sample size for two groups

Sample Size Calculator for Two Groups

Find how many participants you need per group to compare two means or two proportions with the power you want. You get the number for each group, the expected 95% CI of the difference, a sentence for your methods section, and the R code.

Your data never leaves your browser. No sign-up, no ads.

Your study

Choose the outcome type first. Percentages here, not counts.

In the unit of the outcome. Use the smallest difference that matters clinically.
Assumed equal in both groups. Take it from a pilot or a published study.
1 means equal groups. 2 means group 2 is twice as large.
Leave empty for none. Each group is enlarged to allow for it.

Result

Participants needed to compare two independent groups.

Sentence for your manuscript

Written in AMA style from your numbers. Check it against your own study design before you submit.

Reporting checklist

  • CONSORT 2010 (trials): explain how the sample size was determined (item 7a). Give the difference, the standard deviation or event rate, the significance level, the power and the allocation ratio.
  • STROBE 2007 (observational studies): explain how the study size was arrived at (item 10).
  • Say where the assumed difference and standard deviation (or proportions) came from: a pilot, a cited study, or the smallest difference that matters clinically.

Methods wording. The sample size for comparing two independent groups was calculated with BiostatKit [1] using the normal-approximation formulas described by Lwanga and Lemeshow [2].
[1] BiostatKit. Sample size calculator for two groups. Accessed [date]. [URL]
[2] Lwanga SK, Lemeshow S. Sample Size Determination in Health Studies: A Practical Manual. Geneva, Switzerland: World Health Organization; 1991.

Reproduce it in R

The script is filled in with your numbers. Paste it into R or RStudio and compare.

R 4.x · base R only

    

This calculator was checked against SciPy and statsmodels on 2 reference cases and matched to 4 significant digits. See the verification log.

How the sample size is worked out

What it is

The sample size is the number of participants per group for which a 2-sided test at your significance level (usually 5%) has the power you chose (usually 80% or 90%) to detect the difference you planned for. Power is the chance of finding a difference that really exists.

How this page computes it

Two means: n1 = (1 + 1/k) x σ² x (Z1-α/2 + Z1-β)² / Δ² with σ the common standard deviation, Δ the difference to detect and k = n2 / n1.

Two proportions: n1 = [ Z1-α/2 x sqrt((1 + 1/k) x p̄ x (1 - p̄)) + Z1-β x sqrt(p1(1 - p1) + p2(1 - p2)/k) ]² / (p1 - p2)² with p̄ = (p1 + k x p2) / (1 + k).

Group 1 is rounded up, then group 2 is k times group 1, rounded up. With loss to follow-up each group is divided by (1 - loss). The expected CI of the difference uses the rounded group sizes: difference ± Z x SE.

Assumptions

  • Two independent groups, a 2-sided test, and a large enough sample for the normal approximation. For small groups or proportions near 0% or 100%, use an exact method.
  • For means, the same standard deviation in both groups.
  • The difference you enter is the true difference you hope to detect, not the one you expect to see by chance.

Common mistakes

  • Taking the difference seen in a small pilot as the planned difference. Pilot differences are often too large. Use the smallest difference that matters clinically.
  • Forgetting loss to follow-up or non-response.
  • Using this for paired data, clustered designs, or non-inferiority margins. They need different formulas.
  • Entering a relative risk. Convert it first: give the control proportion in group 2 and the treated proportion in group 1.

Frequently asked questions

Where do I get the standard deviation?

From a pilot study or a published study in a similar population. If you only have a range, a rough guide is the range divided by 4, but a published value is better.

Why does R's power.t.test give one more participant per group?

This page uses the normal approximation. power.t.test uses the t distribution, which asks for about Z squared over 4 more participants per group, roughly 1. For large groups the two agree. Report which method you used.

Which allocation ratio should I choose?

Equal groups (ratio 1) need the fewest participants in total for the same power. A 2:1 ratio needs roughly 12% more participants in total for the same power; choose it only when there is a reason, such as wanting more safety data on the new treatment.

Is the answer per group or in total?

Both are shown. The headline number is the total, and the line under it gives each group.

Is my data stored or sent anywhere?

No. All calculations run in your browser tab. Nothing is uploaded, and the page works offline once loaded.

Related calculators: Sample size for a proportion · Sample size: survival analysis