Skip to content

BPower & sample size · power.anova

Power analysis — one-way ANOVA

How many participants per group does a one-way ANOVA need?

Sample size per group, power or smallest detectable effect (Cohen's f) for the one-way ANOVA F test with equal groups, from the noncentral F distribution (λ = f²·k·n).

Verified in Python and R Python and R agree to 6 decimals

A real result

Example “Three groups n”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Power analysis: one-way ANOVARecorded · Python and R agreeRecorded 2026-11-09 · 13 values compared · largest relative difference 1.3e-10
R

n = 53 per group (N = 159), f = 0.25, α = 0.05, 1 − β = 0.805

Per group
53
Total
159
Power
0.8049
Effect size f
0.2500
η²
0.0588
Noncentrality λ
9.938

Plots

Power by sample size per groupHow does power grow with sample size (or effect size), and where does it reach the target?
View data
PowerEffectSample size per group
0.0569f = 0.192
0.0848f = 0.195.263
0.1141f = 0.198.525
0.1447f = 0.1911.787
0.1764f = 0.1915.050
0.2088f = 0.1918.313
0.2416f = 0.1921.575
0.2747f = 0.1924.837
0.3078f = 0.1928.100
0.3407f = 0.1931.363
0.3732f = 0.1934.625
0.4052f = 0.1937.888
0.4366f = 0.1941.150
0.4672f = 0.1944.413
0.4970f = 0.1947.675
0.5259f = 0.1950.938
0.5537f = 0.1954.200
0.5805f = 0.1957.462
0.6063f = 0.1960.725
0.6310f = 0.1963.987
0.6545f = 0.1967.250
0.6770f = 0.1970.513
0.6984f = 0.1973.775
0.7186f = 0.1977.037
0.7379f = 0.1980.300
0.7560f = 0.1983.563
0.7732f = 0.1986.825
0.7893f = 0.1990.088
0.8045f = 0.1993.350
0.8188f = 0.1996.612
0.8322f = 0.1999.875
0.8447f = 0.19103.14
0.8565f = 0.19106.40
0.8674f = 0.19109.66
0.8777f = 0.19112.92
0.8872f = 0.19116.19
0.8961f = 0.19119.45
0.9043f = 0.19122.71
0.9120f = 0.19125.97
0.9191f = 0.19129.24
0.9256f = 0.19132.50
0.0622f = 0.252
0.1138f = 0.255.263
0.1692f = 0.258.525
0.2270f = 0.2511.787
0.2859f = 0.2515.050
0.3445f = 0.2518.313
0.4020f = 0.2521.575
0.4574f = 0.2524.837
0.5102f = 0.2528.100
0.5600f = 0.2531.363
0.6066f = 0.2534.625
0.6496f = 0.2537.888
0.6892f = 0.2541.150
0.7254f = 0.2544.413
0.7582f = 0.2547.675
0.7878f = 0.2550.938
0.8143f = 0.2554.200
0.8380f = 0.2557.462
0.8591f = 0.2560.725

First 60 of 123 rows.

Required size per group by power

Effect70% power80% power90% power95% power
f = 0.197593121148
f = 0.2543536984
f = 0.3128344554
  • Noncentral F with λ = f²·k·n; equal group sizes. Required sizes are rounded up and the power is recomputed at the rounded size.
Python

n = 53 per group (N = 159), f = 0.25, α = 0.05, 1 − β = 0.805

Per group
53
Total
159
Power
0.8049
Effect size f
0.2500
η²
0.0588
Noncentrality λ
9.938

To keep this page light, the plots are shown once, under the R tab.

Required size per group by power

Effect70% power80% power90% power95% power
f = 0.197593121148
f = 0.2543536984
f = 0.3128344554
  • Noncentral F with λ = f²·k·n; equal group sizes. Required sizes are rounded up and the power is recomputed at the rounded size.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Three groups nNo data needed
  • Five groups powerNo data needed
  • Two groups effectNo data needed

In the guides

Where it sits in the decision guides

  • Sample-size planning · Statistics Guide · Step 0 — Prepare your data
  • More than two independent groups: one-way ANOVA, Kruskal–Wallis · Statistics Guide · B — Compare groups
  • Sample size and power · Statistics Guide · Additional considerations

Choices you make

hypothesis

Solve fordefault n

Which quantity to compute from the others: the sample size, the power, or the smallest effect you could detect.

  • Sample size(default) — Finds the sample size needed for your power and effect; the usual question before a study.
  • Power — Finds the chance of detecting your effect at this sample; pick it when the sample size is fixed.
  • Smallest detectable effect — Finds the smallest effect this sample can detect; pick it when the sample size is fixed.
Number of groupsdefault 3

Number of groups being compared.

Effect size (Cohen's f)default 0.25

f = SD of the group means / within-group SD; η² = f² / (1 + f²). 0.10 small, 0.25 medium, 0.40 large.

Sample size per groupdefault 20

Sample size per group to assume (ignored when you solve for it).

Target power (1 − β)default 0.8

Chance of detecting the effect if it is real. 0.8 is common; 0.9 is stricter and needs more data.

Significance level (α)default 0.05

The false-alarm rate you accept: the chance of a significant result when there is truly no effect. 0.05 is conventional.

What it reports

n
How many independent units the analysis used; it sets precision and power.
n_total
How many independent units the analysis used; it sets precision and power.
n_exact
How many independent units the analysis used; it sets precision and power.
power
The chance a test detects an effect of a given size, if that effect is real.
target_power
The chance a test detects an effect of a given size, if that effect is real.
f
The ratio of explained to unexplained variance, used by ANOVA and regression tests.
eta_sq
The share of total variance explained by an effect in ANOVA; biased upward in small samples.
k
How many groups, studies or clusters the analysis used. Many methods are less reliable when k is small.
df1
How much independent information is left to estimate variability after fitting the model.
df2
How much independent information is left to estimate variability after fitting the model.
lambda
Shrinks coefficients towards zero to reduce overfitting; lasso can drop predictors entirely.
crit
The value a statistic must pass for the test to reject at the chosen significance level.
alpha
The false-positive rate you accept before looking at the data, usually 0.05.

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-7). Python uses numpy, scipy, codesplash; R uses stats, codesplashr.

Default traps between the two languages

  • Noncentral F: scipy uses Boost; R's pf(ncp =) uses AS 226 with an error bound of 1e-9, so power agrees to ~1e-9 and solved sizes/effects to ~1e-8.
Python

The exact script CodeSplash ran for example “Three groups n” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Power analysis — one-way ANOVA
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.anova 1.0.0 · spec f0a00c9ce6ad5f8b
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import math

from scipy import stats

import codesplash as cs
from codesplash.stats import power as pw  # noncentral-F power and Brent solvers (twin of R cs_power_*)

# %% Inputs
solve_for = "n"  # n | power | effect
k = int(3)
f = 0.25  # Cohen's f
n_given = 20  # per group
target = 0.8
alpha = 0.05
warnings = []
lo = 2.0  # per group: within-group df = k(n − 1) > 0


def power_at(n, eff):
    return pw.anova_power(eff, n, k, alpha)  # λ = f²·k·n (statsmodels FTestAnovaPower with nobs = k·n)


# %% Solve
n_exact = None
target_power = None
if solve_for == "n":
    target_power = target
    n_exact = pw.solve_increasing(lambda n: power_at(n, f), target, lo, 10.0, 1e7)
    if math.isnan(n_exact):
        warnings.append("The target power is not reached below 10,000,000 per group.")
    n = pw.ceil_n(n_exact)
elif solve_for == "power":
    n = n_given
else:
    target_power = target
    n = n_given
    f = pw.solve_increasing(lambda e: power_at(n, e), target, 1e-6, 1.0, 100.0)
    if math.isnan(f):
        warnings.append("No effect size up to f = 100 reaches the target power with this sample.")
power = power_at(n, f)
df1, df2 = k - 1.0, k * (n - 1.0)
lam = f * f * k * n
crit = float(stats.f.isf(alpha, df1, df2))
eta_sq = f * f / (1.0 + f * f)

# %% Curves and sensitivity
n_ref = n if math.isfinite(n) else 50.0
xs = pw.grid(lo, max(2.5 * n_ref, lo + 10.0))
effects = [0.75 * f, f, 1.25 * f] if math.isfinite(f) else [0.25]
curve = [(float(x), power_at(float(x), e), f"f = {e:.2f}") for e in effects for x in xs]
tables = []
if solve_for == "n" and math.isfinite(f):
    rows = [{"effect": f"f = {e:.2f}", **{f"p{p}": pw.ceil_n(pw.solve_increasing(lambda m: power_at(m, e), p / 100, lo, 10.0, 1e7)) for p in (70, 80, 90, 95)}} for e in effects]
    tables.append({
        "key": "sensitivity", "title": "Required size per group by power",
        "columns": [{"key": "effect", "label": "Effect", "type": "string"}] + [{"key": f"p{p}", "label": f"{p}% power", "type": "integer"} for p in (70, 80, 90, 95)],
        "rows": rows,
    })

# %% Result
cs.publish({
    "method": "power.anova",
    "methodVersion": "1.0.0",
    "title": "Power analysis: one-way ANOVA",
    "engine": cs.engine_info("scipy"),
    "summary": f"One-way ANOVA with {k} groups: n = {n:,.0f} per group, f = {f:.3f}, power = {power:.3f} at α = {alpha}.",
    "apa": f"n = {n:,.0f} per group (N = {k * n:,.0f}), f = {cs.fmt_num(f)}, α = {alpha}, 1 − β = {power:.3f}",
    "statistics": [
        {"key": "n", "label": "Per group", "value": n, "format": "integer"},
        {"key": "n_total", "label": "Total", "value": k * n, "format": "integer"},
        {"key": "power", "label": "Power", "value": power},
        {"key": "f", "label": "Effect size f", "value": f},
        {"key": "eta_sq", "label": "η²", "value": eta_sq},
        {"key": "lambda", "label": "Noncentrality λ", "value": lam},
    ],
    "tables": tables,
    "warnings": warnings,
    "notes": ["Noncentral F with λ = f²·k·n; equal group sizes. Required sizes are rounded up and the power is recomputed at the rounded size."],
    "charts": [cs.chart(
        "power", "power-curve", "Power by sample size per group",
        {"x": cs.col("Sample size per group", [c[0] for c in curve]),
         "power": cs.col("Power", [c[1] for c in curve]),
         "series": cs.col("Effect", [c[2] for c in curve])},
        controls={"target": target if target_power is not None else 0.8},
    )],
    "values": {
        "n": n, "n_total": k * n, "n_exact": n_exact, "power": power, "target_power": target_power, "f": f,
        "eta_sq": eta_sq, "k": k, "df1": df1, "df2": df2, "lambda": lam, "crit": crit, "alpha": alpha,
    },
})
R

The exact script CodeSplash ran for example “Three groups n” · R version 4.5.1 (2025-06-13)

# Power analysis — one-way ANOVA
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.anova 1.0.0 · spec f0a00c9ce6ad5f8b
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_power_anova() and the Brent solvers (twin of codesplash.stats.power)

# %% Inputs
solve_for <- "n" # n | power | effect
k <- 3
f <- 0.25 # Cohen's f
n_given <- 20 # per group
target <- 0.8
alpha <- 0.05
warnings <- list()
lo <- 2 # per group: within-group df = k(n - 1) > 0

power_at <- function(n, eff) cs_power_anova(eff, n, k, alpha) # lambda = f^2 k n (power.anova.test convention)

# %% Solve
n_exact <- NA
target_power <- NA
if (solve_for == "n") {
  target_power <- target
  n_exact <- cs_power_solve_increasing(function(n) power_at(n, f), target, lo, 10, 1e7)
  if (is.nan(n_exact)) warnings <- c(warnings, "The target power is not reached below 10,000,000 per group.")
  n <- cs_power_ceil(n_exact)
} else if (solve_for == "power") {
  n <- n_given
} else {
  target_power <- target
  n <- n_given
  f <- cs_power_solve_increasing(function(e) power_at(n, e), target, 1e-6, 1, 100)
  if (is.nan(f)) warnings <- c(warnings, "No effect size up to f = 100 reaches the target power with this sample.")
}
power <- power_at(n, f)
df1 <- k - 1
df2 <- k * (n - 1)
lambda <- f * f * k * n
crit <- stats::qf(alpha, df1, df2, lower.tail = FALSE)
eta_sq <- f * f / (1 + f * f)

# %% Curves and sensitivity
n_ref <- if (is.finite(n)) n else 50
xs <- cs_power_grid(lo, max(2.5 * n_ref, lo + 10))
effects <- if (is.finite(f)) c(0.75 * f, f, 1.25 * f) else 0.25
curve <- do.call(rbind, lapply(effects, function(e) {
  data.frame(x = xs, power = vapply(xs, function(x) power_at(x, e), numeric(1)), series = sprintf("f = %.2f", e))
}))
tables <- list()
if (solve_for == "n" && is.finite(f)) {
  rows <- lapply(effects, function(e) {
    row <- list(effect = sprintf("f = %.2f", e))
    for (p in c(70, 80, 90, 95)) row[[sprintf("p%d", p)]] <- cs_power_ceil(cs_power_solve_increasing(function(m) power_at(m, e), p / 100, lo, 10, 1e7))
    row
  })
  tables <- list(list(
    key = "sensitivity", title = "Required size per group by power",
    columns = c(list(list(key = "effect", label = "Effect", type = "string")),
                lapply(c(70, 80, 90, 95), function(p) list(key = sprintf("p%d", p), label = sprintf("%d%% power", p), type = "integer"))),
    rows = rows
  ))
}

# %% Result
cs_publish(list(
  method = "power.anova",
  methodVersion = "1.0.0",
  title = "Power analysis: one-way ANOVA",
  engine = cs_engine_info("stats"),
  summary = sprintf("One-way ANOVA with %d groups: n = %s per group, f = %.3f, power = %.3f at alpha = %s.", as.integer(k), format(n, big.mark = ","), f, power, format(alpha)),
  apa = sprintf("n = %s per group (N = %s), f = %s, α = %s, 1 − β = %.3f", format(n, big.mark = ","), format(k * n, big.mark = ","), cs_fmt_num(f), format(alpha), power),
  statistics = list(
    list(key = "n", label = "Per group", value = n, format = "integer"),
    list(key = "n_total", label = "Total", value = k * n, format = "integer"),
    list(key = "power", label = "Power", value = power),
    list(key = "f", label = "Effect size f", value = f),
    list(key = "eta_sq", label = "η²", value = eta_sq),
    list(key = "lambda", label = "Noncentrality λ", value = lambda)
  ),
  tables = tables,
  warnings = warnings,
  notes = "Noncentral F with λ = f²·k·n; equal group sizes. Required sizes are rounded up and the power is recomputed at the rounded size.",
  charts = list(cs_chart(
    "power", "power-curve", "Power by sample size per group",
    list(x = cs_col("Sample size per group", curve$x), power = cs_col("Power", curve$power), series = cs_col("Effect", curve$series)),
    controls = list(target = if (is.na(target_power)) 0.8 else target)
  )),
  values = list(
    n = n, n_total = k * n, n_exact = n_exact, power = power, target_power = target_power, f = f,
    eta_sq = eta_sq, k = k, df1 = df1, df2 = df2, lambda = lambda, crit = crit, alpha = alpha
  )
))

Sources

  • Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.), chapter 8.

From the CodeSplash method registry · power.anova v1.0.0.