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).
A real result
Example “Three groups n”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
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
View data
| Power | Effect | Sample size per group |
|---|---|---|
| 0.0569 | f = 0.19 | 2 |
| 0.0848 | f = 0.19 | 5.263 |
| 0.1141 | f = 0.19 | 8.525 |
| 0.1447 | f = 0.19 | 11.787 |
| 0.1764 | f = 0.19 | 15.050 |
| 0.2088 | f = 0.19 | 18.313 |
| 0.2416 | f = 0.19 | 21.575 |
| 0.2747 | f = 0.19 | 24.837 |
| 0.3078 | f = 0.19 | 28.100 |
| 0.3407 | f = 0.19 | 31.363 |
| 0.3732 | f = 0.19 | 34.625 |
| 0.4052 | f = 0.19 | 37.888 |
| 0.4366 | f = 0.19 | 41.150 |
| 0.4672 | f = 0.19 | 44.413 |
| 0.4970 | f = 0.19 | 47.675 |
| 0.5259 | f = 0.19 | 50.938 |
| 0.5537 | f = 0.19 | 54.200 |
| 0.5805 | f = 0.19 | 57.462 |
| 0.6063 | f = 0.19 | 60.725 |
| 0.6310 | f = 0.19 | 63.987 |
| 0.6545 | f = 0.19 | 67.250 |
| 0.6770 | f = 0.19 | 70.513 |
| 0.6984 | f = 0.19 | 73.775 |
| 0.7186 | f = 0.19 | 77.037 |
| 0.7379 | f = 0.19 | 80.300 |
| 0.7560 | f = 0.19 | 83.563 |
| 0.7732 | f = 0.19 | 86.825 |
| 0.7893 | f = 0.19 | 90.088 |
| 0.8045 | f = 0.19 | 93.350 |
| 0.8188 | f = 0.19 | 96.612 |
| 0.8322 | f = 0.19 | 99.875 |
| 0.8447 | f = 0.19 | 103.14 |
| 0.8565 | f = 0.19 | 106.40 |
| 0.8674 | f = 0.19 | 109.66 |
| 0.8777 | f = 0.19 | 112.92 |
| 0.8872 | f = 0.19 | 116.19 |
| 0.8961 | f = 0.19 | 119.45 |
| 0.9043 | f = 0.19 | 122.71 |
| 0.9120 | f = 0.19 | 125.97 |
| 0.9191 | f = 0.19 | 129.24 |
| 0.9256 | f = 0.19 | 132.50 |
| 0.0622 | f = 0.25 | 2 |
| 0.1138 | f = 0.25 | 5.263 |
| 0.1692 | f = 0.25 | 8.525 |
| 0.2270 | f = 0.25 | 11.787 |
| 0.2859 | f = 0.25 | 15.050 |
| 0.3445 | f = 0.25 | 18.313 |
| 0.4020 | f = 0.25 | 21.575 |
| 0.4574 | f = 0.25 | 24.837 |
| 0.5102 | f = 0.25 | 28.100 |
| 0.5600 | f = 0.25 | 31.363 |
| 0.6066 | f = 0.25 | 34.625 |
| 0.6496 | f = 0.25 | 37.888 |
| 0.6892 | f = 0.25 | 41.150 |
| 0.7254 | f = 0.25 | 44.413 |
| 0.7582 | f = 0.25 | 47.675 |
| 0.7878 | f = 0.25 | 50.938 |
| 0.8143 | f = 0.25 | 54.200 |
| 0.8380 | f = 0.25 | 57.462 |
| 0.8591 | f = 0.25 | 60.725 |
First 60 of 123 rows.
Required size per group by power
| Effect | 70% power | 80% power | 90% power | 95% power |
|---|---|---|---|---|
| f = 0.19 | 75 | 93 | 121 | 148 |
| f = 0.25 | 43 | 53 | 69 | 84 |
| f = 0.31 | 28 | 34 | 45 | 54 |
- Noncentral F with λ = f²·k·n; equal group sizes. Required sizes are rounded up and the power is recomputed at the rounded size.
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
| Effect | 70% power | 80% power | 90% power | 95% power |
|---|---|---|---|---|
| f = 0.19 | 75 | 93 | 121 | 148 |
| f = 0.25 | 43 | 53 | 69 | 84 |
| f = 0.31 | 28 | 34 | 45 | 54 |
- 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.
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,
},
})
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.