Power Analysis and Sample Size Calculation in R

Before you run a study, find the sample size you need — or the power you’ll get — with the pwr package: t-tests, ANOVA, correlation, proportions and chi-square, the practical way

Biostatistics

Perform power analysis and sample size calculation in R with the pwr package. Understand the four interrelated components (sample size, effect size, significance level, power), use Cohen’s conventional effect sizes, and compute the required n — or the achieved power — for t-tests, ANOVA, correlation, proportion and chi-square tests.

Published

June 23, 2026

Modified

July 7, 2026

TipKey takeaways
  • Power analysis links four quantities — sample size, effect size, significance level (α) and power (1 − β) — give any three and R computes the fourth.
  • Use the pwr package: pwr.t.test(), pwr.anova.test(), pwr.r.test(), pwr.2p.test(), pwr.chisq.test(), pwr.f2.test().
  • Power is the probability of detecting a real effect; the usual targets are power = 0.80–0.90 and α = 0.05.
  • Effect size is the degree to which the null is false; Cohen’s conventional small/medium/large values differ per test (e.g. d = 0.2/0.5/0.8 for means).
  • Do it before the study: too few subjects → underpowered (you miss real effects); too many → wasted resources.

Introduction

Choosing the sample size is one of the most important design decisions in a study. Too few participants and a real effect goes undetected (the study is underpowered); too many and you waste time, money and participants. Power analysis answers the question precisely — how many subjects do I need? — before you collect any data.

The scenario: you’re planning an experiment and need to know the sample size to reliably detect the effect you care about — or, given a fixed budget, the power you’ll actually have.

The four components

Power analysis ties together four quantities — specify any three, solve for the fourth:

  1. Sample size — the number of observations.
  2. Effect size — how far from the null the truth is (bigger effects are easier to detect).
  3. Significance level (α) — the Type-I error rate (false positive); usually 0.05.
  4. Power (1 − β) — the probability of detecting a real effect (avoiding a false negative); usually targeted at 0.80–0.90.
Note

Type I vs Type II. α (Type I) is finding an effect that isn’t there; β (Type II) is missing an effect that is there. Power = 1 − β. Targeting 90% power means accepting a 10% Type-II error rate.

We use the pwr package throughout:

library(pwr)

Conventional effect sizes

If you can’t estimate the effect size from pilot data, Cohen’s conventional small/medium/large values are a starting point — and they differ per test:

Test small medium large
means (t) 0.2 0.5 0.8
proportions (p) 0.2 0.5 0.8
correlation (r) 0.1 0.3 0.5
chi-square (chisq) 0.1 0.3 0.5
ANOVA (anov) 0.1 0.25 0.4
linear model (f2) 0.02 0.15 0.35

cohen.ES() returns these:

library(pwr)
cohen.ES(test = "t", size = "medium")

     Conventional effect size from Cohen (1982) 

           test = t
           size = medium
    effect.size = 0.5

T-tests (comparing two means)

pwr.t.test() — give three of n (per group), d (Cohen’s d), sig.level, power. What power do I get with 30 per group for a medium effect (d = 0.5)?

library(pwr)
pwr.t.test(n = 30, d = 0.5, sig.level = 0.05, type = "two.sample")

     Two-sample t test power calculation 

              n = 30
              d = 0.5
      sig.level = 0.05
          power = 0.4778965
    alternative = two.sided

NOTE: n is number in *each* group

Only 48% power — a coin-flip chance of detecting the effect. So how many do I need for 90% power?

library(pwr)
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.9, type = "two.sample")

     Two-sample t test power calculation 

              n = 85.03128
              d = 0.5
      sig.level = 0.05
          power = 0.9
    alternative = two.sided

NOTE: n is number in *each* group

We need ~85 subjects per group. (Use type = "one.sample" or "paired" for those designs, and pwr.t2n.test() for unequal group sizes.)

One-way ANOVA

pwr.anova.test()k groups, n per group, effect size f. Sample size for 5 groups, a medium effect (f = 0.25), 90% power:

library(pwr)
pwr.anova.test(k = 5, f = 0.25, sig.level = 0.05, power = 0.9)

     Balanced one-way analysis of variance power calculation 

              k = 5
              n = 50.25498
              f = 0.25
      sig.level = 0.05
          power = 0.9

NOTE: n is number in each group

About 50 per group (~250 total).

Correlation

pwr.r.test() — sample size to detect a correlation of r = 0.3 with 90% power:

library(pwr)
pwr.r.test(r = 0.3, sig.level = 0.05, power = 0.9)

     approximate correlation power calculation (arctangh transformation) 

              n = 111.8068
              r = 0.3
      sig.level = 0.05
          power = 0.9
    alternative = two.sided

We need ~112 observations.

Proportions

For two proportions, convert them to an effect size with ES.h() first. Researchers expect 55% vs 50% — how many per group for 80% power to detect that 5-point difference?

library(pwr)
pwr.2p.test(h = ES.h(p1 = 0.55, p2 = 0.50), sig.level = 0.05, power = 0.80)

     Difference of proportion power calculation for binomial distribution (arcsine transformation) 

              h = 0.1001674
              n = 1564.529
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: same sample sizes

~1565 per group — small differences in proportions need large samples. (Use pwr.p.test() for one proportion, pwr.2p2n.test() for unequal groups.)

Chi-square tests

For a chi-square test, the effect size is w (use ES.w1() for goodness-of-fit, ES.w2() for a contingency table). Sample size to detect a given colour distribution against equal proportions, 90% power:

library(pwr)
expected <- c(1/3, 1/3, 1/3)
observed <- c(0.51, 0.32, 0.17)

pwr.chisq.test(w = ES.w1(expected, observed), df = (3 - 1),
               sig.level = 0.05, power = 0.9)

     Chi squared power calculation 

              w = 0.4173727
              N = 72.64029
             df = 2
      sig.level = 0.05
          power = 0.9

NOTE: N is the number of observations

We need ~73 records to detect that departure from equal colours with 90% power.

Linear models (regression)

For a linear regression, pwr.f2.test() uses the effect size f² = R²/(1 − R²). The arguments are u (numerator df = number of predictors) and v (denominator df = n − u − 1). What power does a model explaining 42% of the variance with 2 predictors have at n = 47?

library(pwr)
pwr.f2.test(u = 2, v = 44, f2 = 0.42 / (1 - 0.42), sig.level = 0.001)

     Multiple regression power calculation 

              u = 2
              v = 44
             f2 = 0.7241379
      sig.level = 0.001
          power = 0.9616593

About 96% power. To solve for sample size, leave v = NULL and recall n = v + u + 1:

library(pwr)
pwr.f2.test(u = 2, f2 = 0.42 / (1 - 0.42), sig.level = 0.001, power = 0.99)

     Multiple regression power calculation 

              u = 2
              v = 52.79266
             f2 = 0.7241379
      sig.level = 0.001
          power = 0.99

A v of ~53 means n = 53 + 2 + 1 ≈ 56 observations for 99% power at this strict α.

Report

An a-priori power analysis (pwr package) was conducted for a two-sample t-test. To detect a medium effect (Cohen’s d = 0.5) with 90% power at α = 0.05, a sample size of 85 participants per group (170 total) is required.

Power is \(1 - \beta = P(\text{reject } H_0 \mid H_1 \text{ true})\). It increases with the sample size, the effect size, and a larger α; it decreases as you demand a smaller α. Each pwr function inverts the test’s non-central distribution: for the two-sample t-test, the test statistic under \(H_1\) follows a non-central \(t\) with non-centrality parameter \(\delta = d\sqrt{n/2}\), and pwr.t.test() solves \(P(|t| > t_{\alpha/2} \mid \delta) = \text{power}\) for whichever argument you leave NULL. Cohen’s effect sizes (d, f, h, w, r) standardise the effect so the same power machinery applies across tests.

Try it live

Change the effect size or target power and watch the required sample size move. The sandbox boots on first Run.

🟢 With an AI agent

Ask Prova “what sample size do I need to detect my effect with 90% power?” — it picks the right pwr function for your test and computes the sample size with code you can run. The runtime is the judge. Ask Prova →

Common issues

You ran the power analysis after the study. Power analysis is a design tool — do it before collecting data. Post-hoc “observed power” computed from your p-value is circular and uninformative; if you must report sensitivity, compute the effect size you could have detected, not power from the observed effect.

You guessed the effect size from the same data. Estimating the effect from a pilot is fine; estimating it from the very study you’re powering inflates it. When unsure, use Cohen’s conventional small/medium value — and remember small effects need large samples.

Your sample size is “per group,” not total. pwr.t.test, pwr.anova.test and pwr.2p.test return the size per group — multiply by the number of groups for the total enrolment.

Frequently asked questions

Use the pwr package: pick the function for your test (pwr.t.test, pwr.anova.test, pwr.r.test, pwr.2p.test, pwr.chisq.test), supply the effect size, significance level (0.05) and target power (0.80–0.90), and leave n = NULL — R returns the required sample size.

Power is the probability of detecting a real effect (1 − β, the complement of the Type-II error rate). The conventional targets are 0.80 (acceptable) or 0.90 (strong); below 0.80 a study is generally considered underpowered.

Use Cohen’s conventional values for your test — e.g. d = 0.2/0.5/0.8 (small/medium/large) for means, r = 0.1/0.3/0.5 for correlation, f = 0.1/0.25/0.4 for ANOVA. cohen.ES(test, size) returns them. A medium effect is a common default when nothing is known.

A-priori power analysis (the useful one) finds the sample size before the study, given an expected effect. Post-hoc power computed from the observed effect after the study is circular — it’s just a transformation of the p-value — and should be avoided. Report a-priori power or a sensitivity analysis instead.

Test your understanding

  1. Run it. In the live cell, compute the sample size for a two-sample t-test with a small effect (d = 0.2) at 80% power. How does it compare with the medium-effect n?
  2. Conceptual. Your power analysis says you need 1565 subjects per group, but you can only recruit 300. List two things you could change to make the study feasible.

Fill the blank with 0.2, then compare with d = 0.5. Smaller effects need much larger samples. For question 2, think about which of the four components you can move (effect size you’re powered to detect, α, or power).

A small effect (d = 0.2) needs ~394 per group versus ~64 for a medium effect (d = 0.5) at 80% power — the sample size scales roughly with \(1/d^2\). For question 2, with a fixed recruitable n you can: (a) power for a larger effect size (accept that you can only detect a bigger difference), (b) accept lower power (e.g. 0.70, raising the Type-II error), (c) relax α slightly, or (d) change the design (a paired/within-subject test, or a more precise measurement, raises the effective effect size). Recruiting more is the only way to keep both the small effect and high power.

Conclusion

You can now run a power analysis in R: use the pwr package to connect sample size, effect size, significance level and power — solving for whichever you don’t know — across t-tests, ANOVA, correlation, proportions and chi-square. Do it before the study to choose a sample size that’s large enough to detect what matters, without wasting resources.

Reuse

Citation

BibTeX citation:
@online{2026,
  author = {},
  title = {Power {Analysis} and {Sample} {Size} {Calculation} in {R}},
  date = {2026-06-23},
  url = {https://www.datanovia.com/learn/biostatistics/power-analysis-in-r},
  langid = {en}
}
For attribution, please cite this work as:
“Power Analysis and Sample Size Calculation in R.” 2026. June 23. https://www.datanovia.com/learn/biostatistics/power-analysis-in-r.