← All guides

Sample Size and Power Analysis Explained: What It Is and How to Do It in R, Python, G*Power and SPSS

StatFas · Updated 5 November 2026

Sample size and power analysis answers one planning question before you collect any data: how many participants do I need so that, if the effect I care about is real, my study will detect it with high probability? This guide explains what power is, the four quantities that are linked in every power analysis, the three main types (a priori, post hoc and sensitivity), worked examples, and how to run the calculation in R, Python, G*Power, SPSS and a free online calculator, with the original sources linked so you can check them.

Try it free: Run sample size and power analysis with the StatFas calculator or follow the step-by-step tutorial.

What is sample size and power analysis?

Statistical power is the probability that a test rejects the null hypothesis when the null hypothesis is false. It equals 1 − β, where β is the Type II error rate (missing a real effect). A power analysis connects power to three other quantities, and a sample size determination is the special case where you solve for the number of participants. Power of .80 is the usual minimum, which means a 20% risk of missing a true effect of the size you specified; .90 or .95 is common in clinical trials. The framework goes back to Cohen (1992) and his 1988 handbook, and it is the reason a sample size justification is now expected in most research proposals and journals.

Why it matters

An underpowered study has a reduced chance of finding a true effect, and it also makes a significant result less likely to reflect a true effect and more likely to overestimate it. Button et al. (2013) estimated that the median power of the neuroscience studies they reviewed was only about 21%. An overpowered study wastes participants, money and time, and can flag trivially small effects as significant. Planning the sample size is therefore both a scientific and an ethical step. Lakens (2022) gives a clear overview of how to justify a sample size.

The four ingredients: fix three, solve for the fourth

QuantitySymbolTypical valueMeaning
Significance levelα.05Accepted Type I error rate (false positive)
Power1 − β.80 to .95Probability of detecting the effect if it is real
Effect sized, f, r, w, f², hSmallest effect worth detectingStandardised size of the difference or association
Sample sizen or NSolved forParticipants per group or in total

Give any three and the fourth is determined. The design also matters: one-tailed or two-tailed, the number of groups or predictors, and whether the groups are independent or paired.

Types of power analysis

G*Power also offers compromise and criterion analyses, which solve for α instead.

Choosing the effect size

The effect size is the hardest input. The best choice is the smallest effect size of interest: the smallest effect that would still matter in practice. Next best is an estimate from a meta-analysis or a closely related study (published estimates from single small studies tend to be inflated). Cohen's conventional benchmarks are a last resort.

TestEffect sizeSmallMediumLarge
t test (means)Cohen's d0.200.500.80
One-way ANOVACohen's f0.100.250.40
Correlationr.10.30.50
Multiple regressionf²0.020.150.35
Chi-squarew0.100.300.50

The formula behind it

For two independent means with equal group sizes, a normal-approximation shortcut for the sample size per group is

n = 2 (z(1 - α/2) + z(1 - β))² / d²

For α = .05 (two-tailed), power = .80 and d = 0.50, z(.975) = 1.96 and z(.80) = 0.84, so n = 2 × (2.80)² / 0.25 ≈ 62.8. Software uses the exact noncentral t distribution instead, which gives 63.77, so you round up to 64 per group (N = 128). The shortcut slightly understates the answer for small samples, which is why you should use software for the final number. Always round up to a whole participant.

Worked examples (α = .05, two-tailed, power = .80)

DesignAssumed effectRequired sample size
Independent-samples t testd = 0.5064 per group (N = 128)
Paired-samples t testd = 0.5034 pairs
One-way ANOVA, 3 groupsf = 0.2553 per group (N = 159)
Pearson correlationr = .3084 to 85, depending on the method
Multiple regression, 5 predictorsf² = 0.15N = 92
Chi-square, df = 2w = 0.30N = 108
Two proportions, 40% vs 25%Cohen's h = 0.32152 per group

The correlation result differs by one because exact methods (G*Power) and the Fisher z approximation (R's pwr) round slightly differently. The two-proportion row uses the arcsine (Cohen's h) method; other methods can differ by a few participants.

Allow for dropout. Divide the required number by the proportion you expect to keep. With 15% expected attrition, 64 per group becomes 64 ÷ 0.85 = 75.3, so recruit 76 per group (N = 152).

How to do it: a step-by-step checklist

  1. Write down your primary hypothesis and the statistical test that will answer it.
  2. Set α (usually .05) and the number of tails.
  3. Set the target power (at least .80).
  4. Choose the smallest effect size of interest, or a defensible published estimate.
  5. Calculate the sample size, then round up and add an allowance for dropout and unusable data.
  6. Check feasibility. If the number is out of reach, run a sensitivity analysis to see which effect you can detect, rather than inflating the assumed effect.
  7. Report the inputs, the result and the software in your methods section.

Sample size and power analysis in R

The pwr package (Champely) implements Cohen's power functions. Each function takes the effect size, α, power and n, and solves for whichever one you leave out.

install.packages("pwr")
library(pwr)

# Independent-samples t test: d = 0.50
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.80,
           type = "two.sample", alternative = "two.sided")
#   n = 63.77 per group  -> round up to 64

# Paired t test
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.80, type = "paired")
#   n = 33.37 pairs      -> 34

# One-way ANOVA, 3 groups, f = 0.25
pwr.anova.test(k = 3, f = 0.25, sig.level = 0.05, power = 0.80)
#   n = 52.40 per group  -> 53 (N = 159)

# Correlation, r = .30
pwr.r.test(r = 0.30, sig.level = 0.05, power = 0.80)
#   n = 84.07            -> 85

# Multiple regression, 5 predictors, f2 = 0.15
res <- pwr.f2.test(u = 5, f2 = 0.15, sig.level = 0.05, power = 0.80)
ceiling(res$v + 5 + 1)   # N = u + v + 1 = 91.21 -> 92

# Chi-square, w = 0.30, df = 2
pwr.chisq.test(w = 0.30, df = 2, sig.level = 0.05, power = 0.80)
#   N = 107.05           -> 108

# Two proportions, 40% vs 25%
pwr.2p.test(h = ES.h(0.40, 0.25), sig.level = 0.05, power = 0.80)
#   n = 151.17 per group -> 152

# Power for a given n, and sensitivity analysis
pwr.t.test(d = 0.5, n = 30, sig.level = 0.05, type = "two.sample")   # power = 0.48
pwr.t.test(n = 50, sig.level = 0.05, power = 0.80, type = "two.sample")  # d = 0.57

For mixed models and complex factorial designs, simulation-based tools such as the simr and Superpower packages are the usual choice.

Sample size and power analysis in Python

The statsmodels package (Seabold and Perktold, 2010) provides power classes in statsmodels.stats.power. Leave one argument out and solve_power returns it.

# pip install statsmodels scipy
import numpy as np
from scipy import stats
from statsmodels.stats.power import TTestIndPower, TTestPower, FTestAnovaPower

# Independent-samples t test
print(TTestIndPower().solve_power(effect_size=0.5, alpha=0.05, power=0.80,
                                  ratio=1.0, alternative="two-sided"))
# 63.77 per group -> 64

# Paired t test
print(TTestPower().solve_power(effect_size=0.5, alpha=0.05, power=0.80))
# 33.37 pairs -> 34

# One-way ANOVA (statsmodels returns the TOTAL N)
print(FTestAnovaPower().solve_power(effect_size=0.25, alpha=0.05,
                                    power=0.80, k_groups=3))
# 157.19 total = 52.4 per group -> 53 per group (N = 159)

# Power for a given n, and sensitivity analysis
print(TTestIndPower().power(effect_size=0.5, nobs1=30, alpha=0.05, ratio=1.0))  # 0.478
print(TTestIndPower().solve_power(nobs1=50, alpha=0.05, power=0.80, ratio=1.0)) # d = 0.566

# Correlation (Fisher z approximation), r = .30
n = ((stats.norm.ppf(0.975) + stats.norm.ppf(0.80)) / np.arctanh(0.30))**2 + 3
print(n)   # 84.93 -> 85

# Multiple regression: 5 predictors, f2 = 0.15, noncentral F
def reg_power(N, u=5, f2=0.15, alpha=0.05):
    v = N - u - 1
    crit = stats.f.ppf(1 - alpha, u, v)
    return 1 - stats.ncf.cdf(crit, u, v, f2 * N)

N = 10
while reg_power(N) < 0.80:
    N += 1
print(N)   # 92

G*Power

G*Power is the most widely used free desktop tool, for Windows and macOS. It covers t, F, χ² and z tests and some exact tests, and it draws the central and noncentral distributions. To reproduce the t test example: choose Test family = t tests, Statistical test = Means: Difference between two independent means (two groups), and Type of power analysis = A priori. Enter tails = two, effect size d = 0.5, α = .05, power = .80 and allocation ratio = 1, then press Calculate. It reports 64 per group, a total of 128 and an actual power of about .80. The Determine button converts means and standard deviations into d. Cite Faul et al. (2007) and, for correlation and regression, Faul et al. (2009).

SPSS, SAS, Stata and other tools

Recent versions of IBM SPSS Statistics Base include Analyze > Power Analysis, with procedures for one-sample, paired and independent t tests, one-way ANOVA, proportions and univariate linear regression. Older versions have no power module. SAS offers PROC POWER, Stata has the power command family, and PASS is a commercial package dedicated to sample size work.

ToolCostGood for
R pwrFreeStandard designs, scripted and reproducible
Python statsmodelsFreet tests and ANOVA inside a Python workflow
G*PowerFreePoint-and-click work with many tests and graphs
SPSS Power AnalysisCommercialResearchers already working in SPSS
StatFas calculatorFree, in the browser12 test types, APA 7 text, power figure, no install

Sample size and power analysis in StatFas

The free StatFas sample size and power analysis calculator runs in your browser and supports independent, paired and one-sample t tests, one-way and repeated-measures ANOVA, correlation, chi-square, two proportions, logistic regression, multiple regression (R² and R² change), mediation and SEM/CFA. Pick the test, choose a priori, post hoc or sensitivity, enter α, power and the effect size, optionally add an expected attrition percentage, and press Calculate. You get APA 7 input and result tables, a sample-size-by-power table, a written power analysis paragraph and a figure of the null and alternative distributions. It includes a validation panel that recomputes benchmark cases against G*Power. The tutorial walks through every step.

Special cases

Questionnaires and surveys. Power does not depend on the number of items. It depends on the test you run on the scores (for example a t test on a scale total or a regression on several predictors), the effect size, α and power. Logistic regression needs the event rate and an odds ratio, and a common method is Hsieh et al. (1998). Mediation power is usually simulated because the indirect effect has no simple closed form. SEM and CFA often use the RMSEA approach of MacCallum et al. (1996), where the model degrees of freedom matter. For rank-based tests, a common rule adds about 5% to the t test sample size.

Common mistakes

How to report it (APA 7)

State the test, α, tails, target power, effect size and its justification, the result, the software and the attrition allowance. For example:

An a priori power analysis for an independent-samples t test was
conducted using StatFas. With α = .05 (two-tailed), power = .80 and a
smallest effect size of interest of d = 0.50, 64 participants per group
(N = 128) were required. Allowing for 15% attrition, 76 participants per
group (N = 152) were recruited.

Frequently asked questions

What is a good power?

.80 is the usual minimum; .90 or .95 is common in clinical trials.

How many participants do I need?

It depends on the test and the effect size. A two-group comparison with a medium effect (d = 0.50) needs 64 per group at .80 power, but a small effect (d = 0.20) needs about 394 per group.

What if I do not know the effect size?

Use the smallest effect size of interest or published estimates, ideally from a meta-analysis. Use Cohen's benchmarks only as a fallback and say so.

Can I calculate power after the study?

You can compute the power to detect a planned or meaningful effect, but not from the effect you observed. For interpretation, report the effect size with a confidence interval.

References

Worked sample sizes were checked by recomputing them with the noncentral t, F and χ² distributions. Cohen (1988) and Hsieh et al. (1998) are cited from their publication records; the other references are linked through their DOIs.