Calculate the sample size using a power analysis
Power analysis and sample size: Determine the target size, expected effect, and desired statistical power before data collection.
How many people does your study need? This depends on the difference you are investigating, how much the measurements vary, and the test you plan. A power analysis translates these assumptions into a required sample size. Here we calculate a comparison of two independent groups completely: from the inputs to the R code and the reserve for dropouts.
The result of our example: Under the assumptions listed below, you need 64 evaluable people per group, a total of 128. If 15% of the endpoint measurements are likely to be missing, plan to recruit 76 people per group, a total of 152. These numbers apply to this example and are not a general minimum size for theses.
What the power of a test indicates
A power of 80% means: If the assumed effect actually exists and the model assumptions are correct, the planned test will yield a significant result in approximately 80% of cases when the study is repeated many times. Power is neither the probability that your hypothesis is true nor a guarantee of the result of a single study.
Planning takes place before data collection. For this, you determine the primary endpoint, the statistical test, the significance level, and the professionally relevant effect. You can find an introduction to the selection of these assumptions in the Guide to Power Analysis. Here, the concrete calculation is the focus.
Example: comparing two independent groups
Imagine a planned study in which two independently assembled groups take a knowledge test. The difference in their mean score is investigated. This is a freely chosen calculation example, not data from a client project.
- Primary endpoint: the score at a fixed measurement time, analyzed as a metric variable.
- Relevant difference: 5 points between the group means.
- Dispersion: a common standard deviation of 10 points.
- Analysis: two-sided t-test for two independent groups with equal variance.
- Planning: equal-sized groups, significance level α = 0.05, and power = 0.80.
The standardized mean difference is thus d = 5 / 10 = 0.5. In a real study, you must justify the 5 points and the standard deviation, for example using a relevant previous study, suitable pilot data, or a professionally defined minimum difference. The term "mean effect" alone does not provide this justification.
The calculation assumes independent observations and the chosen model. For highly skewed distributions, unequal variances, linked measurements, or clusters, you need a suitable plan. The following calculation is in particular not a general sample size calculation for the Welch test.
Calculate sample size with R
The function power.t.test() belongs to the R package stats, which comes with R. You do not need an additional package. Run this code in R or RStudio:
plan <- power.t.test(
delta = 5,
sd = 10,
sig.level = 0.05,
power = 0.80,
type = "two.sample",
alternative = "two.sided",
strict = TRUE
)
plan$n
# 63.76561
n_pro_gruppe <- ceiling(plan$n)
c(pro_gruppe = n_pro_gruppe, insgesamt = 2 * n_pro_gruppe)
# pro_gruppe insgesamt
# 64 128
delta is the difference of the means in points, sd the standard deviation in the same unit. R returns n per group. With ceiling(), you round up to the next whole number. In a two-sided test, strict = TRUE considers both rejection regions.
For checking, you can have the power for the rounded group size output:
power.t.test(
n = 64, delta = 5, sd = 10, sig.level = 0.05,
type = "two.sample", alternative = "two.sided", strict = TRUE
)$power
# 0.8014596
64 people per group achieve around 80.15% power under these assumptions. The calculation was checked with R 4.5.0; minor deviations in the last decimal places are irrelevant for the rounded sample size.
Correctly plan 15% dropouts
If on average only 85% of the recruited people provide an evaluable endpoint measurement, divide the required evaluable group size by 0.85:
64 / (1 − 0.15) = 75.29 → rounded 76 people per group.
ceiling(64 / (1 - 0.15))
# 76
2 * ceiling(64 / (1 - 0.15))
# 152
A mere 15% increase would be too small: 64 × 1.15 equals 73.6, so rounded 74. With 15% dropouts, only 62.9 evaluable people would remain calculated.
152 is a recruitment target based on an assumed dropout rate. It does not guarantee that there are actually at least 128 complete endpoint measurements. In addition, systematic dropout can distort the results; more participants alone do not solve this problem. Therefore, plan the handling of missing values together with the main analysis.
How other assumptions affect the sample size
The following table uses the same two-sided t-test, α = 0.05, and equal-sized groups. All sample sizes are rounded and refer to evaluable people without dropout reserve.
| Effect d | Power | Per group | Total |
|---|---|---|---|
| 0.3 | 80 % | 176 | 352 |
| 0.3 | 90 % | 235 | 470 |
| 0.5 | 80 % | 64 | 128 |
| 0.5 | 90 % | 86 | 172 |
| 0.8 | 80 % | 26 | 52 |
| 0.8 | 90 % | 34 | 68 |
To recalculate a table row, for example, enter delta = 0.3, sd = 1, and power = 0.90 in the first code block. This way you calculate the plan directly with the standardized effect d. R returns about 234.46; rounded, you need 235 per group.
The table shows why an uncertainly estimated effect size can strongly change the plan. Do not choose the largest effect just because it results in the smallest sample. If your recruitment is limited, you can calculate the other way around, which effect would be detectable with the available n at a fixed power target. This sensitivity analysis should be reported as such.
How to document the plan in the methods section
For the fictional example, the calculation can be summarized as follows:
The sample size was planned before data collection for a two-sided t-test of two independent, equal-sized groups assuming equal variances. With a relevant mean difference of 5 points, a standard deviation of 10 points (d = 0.5), α = 0.05, and a target power of 80%, R 4.5.0, stats::power.t.test (strict = TRUE) resulted in a required sample size of rounded 64 evaluable people per group. Assuming 15% missing endpoint measurements, a recruitment target of 76 people per group was set.
Be sure to add the professional justification and the sources for the mean difference, standard deviation, and dropout rate in your work. Do not adopt the example values or the statement "before data collection" if they do not apply to your project.
When this calculation does not fit your study
- Before-after measurements: With linked data, the dispersion of the differences affects the planning.
- Multiple primary hypotheses: Determine how you handle multiple tests. This can change the effective significance level and the sample size.
- Other target sizes: Proportions, event times, and regression models need different inputs and calculation methods.
- Clusters or unequal groups: Dependencies within groups and the allocation ratio must be considered.
- Already completed survey: A retrospective power calculated from the observed effect does not replace prior planning. Report the effect size, uncertainty, and the limitations of your sample.
If you would like to have your sample size plan checked, send us the research question, study design, primary endpoint, and the assumptions so far justified about the contact form for statistical consultation. You can find the possible scope in our service overview.
Sources for the calculation method
- R documentation: power.t.test. Parameters, interpretation of n, and two-sided power.
- R documentation: t-distribution. Basis for calculation with the non-central t-distribution.
Would you like to have your sample size plan professionally checked before data collection? Describe the design, target size, and your assumptions so far to us. Learn more about our statistical consultation and analysis.