Skip to content

BPower & sample size · power.correlation

Power analysis — correlation

How many observations does a test of a correlation need?

Sample size, power or smallest detectable correlation for the test of ρ = 0, with Fisher's z and the critical correlation from the t distribution (as pwr::pwr.r.test).

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

A real result

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

Power analysis: correlationRecorded · Python and R agreeRecorded 2026-11-09 · 7 values compared
R

N = 85, r = 0.30, α = 0.05, 1 − β = 0.804

Sample size
85
Power
0.8044
Correlation
0.3000
Critical r
0.2133

Plots

Power by sample sizeHow does power grow with sample size (or effect size), and where does it reach the target?
View data
PowerCorrelationSample size
0.0767r = 0.224
0.0911r = 0.229.213
0.1246r = 0.2214.425
0.1584r = 0.2219.637
0.1924r = 0.2224.850
0.2264r = 0.2230.063
0.2601r = 0.2235.275
0.2935r = 0.2240.487
0.3264r = 0.2245.700
0.3587r = 0.2250.913
0.3903r = 0.2256.125
0.4210r = 0.2261.337
0.4510r = 0.2266.550
0.4799r = 0.2271.763
0.5080r = 0.2276.975
0.5350r = 0.2282.188
0.5610r = 0.2287.400
0.5860r = 0.2292.612
0.6099r = 0.2297.825
0.6328r = 0.22103.04
0.6547r = 0.22108.25
0.6756r = 0.22113.46
0.6954r = 0.22118.67
0.7143r = 0.22123.89
0.7322r = 0.22129.10
0.7492r = 0.22134.31
0.7653r = 0.22139.53
0.7805r = 0.22144.74
0.7948r = 0.22149.95
0.8084r = 0.22155.16
0.8212r = 0.22160.38
0.8332r = 0.22165.59
0.8445r = 0.22170.80
0.8551r = 0.22176.01
0.8651r = 0.22181.22
0.8745r = 0.22186.44
0.8833r = 0.22191.65
0.8915r = 0.22196.86
0.8992r = 0.22202.07
0.9064r = 0.22207.29
0.9132r = 0.22212.50
0.0847r = 0.304
0.1271r = 0.309.213
0.1894r = 0.3014.425
0.2516r = 0.3019.637
0.3127r = 0.3024.850
0.3719r = 0.3030.063
0.4285r = 0.3035.275
0.4821r = 0.3040.487
0.5325r = 0.3045.700
0.5795r = 0.3050.913
0.6230r = 0.3056.125
0.6631r = 0.3061.337
0.6998r = 0.3066.550
0.7331r = 0.3071.763
0.7634r = 0.3076.975
0.7908r = 0.3082.188
0.8154r = 0.3087.400
0.8375r = 0.3092.612
0.8572r = 0.3097.825

First 60 of 123 rows.

Required sample size by power

Correlation70% power80% power90% power95% power
r = 0.22120152203251
r = 0.306785112138
r = 0.3842537086
  • Fisher z with the critical r from the t distribution (pwr::pwr.r.test). Required sizes are rounded up and the power is recomputed at the rounded size.
Python

N = 85, r = 0.30, α = 0.05, 1 − β = 0.804

Sample size
85
Power
0.8044
Correlation
0.3000
Critical r
0.2133

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

Required sample size by power

Correlation70% power80% power90% power95% power
r = 0.22120152203251
r = 0.306785112138
r = 0.3842537086
  • Fisher z with the critical r from the t distribution (pwr::pwr.r.test). 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

  • Medium nNo data needed
  • Small one sidedNo data needed
  • Power at nNo data needed
  • Detectable rNo data needed

In the guides

Where it sits in the decision guides

  • Sample-size planning · Statistics Guide · Step 0 — Prepare your data
  • Continuous–continuous: Pearson / Spearman / Kendall · Statistics Guide · C — Test association
  • 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 correlation — Finds the smallest correlation this sample can detect; pick it when the sample size is fixed.
Expected correlation (|r|)default 0.3

0.1 small, 0.3 medium, 0.5 large (Cohen 1988).

Sample sizedefault 50

Sample size 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.

Testdefault two-sided

Two-sided unless the direction was fixed before collecting data. One-sided needs fewer rows but ignores effects the other way.

  • Two-sided(default) — Plans for a test in either direction; the usual choice, though it needs more data than one-sided.
  • One-sided (correlation in the expected direction) — Plans for a test in the expected direction only; needs less data, but can't claim an effect the other way.

What it reports

n
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.
r
A number from −1 to 1 for how closely two variables move together; Pearson measures straight-line association.
r_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-9). Python uses scipy, codesplash; R uses stats, codesplashr.

Default traps between the two languages

  • Closed-form power; solved sizes and correlations come from Brent root finding (brentq ↔ uniroot, tol 1e-12) on identical brackets.
Python

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

# Power analysis — correlation
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.correlation 1.0.0 · spec 395fb998847c3ac9
# 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  # Fisher-z power and Brent solvers (twin of R cs_power_*)

# %% Inputs
solve_for = "n"  # n | power | effect
r = 0.3
n_given = 50
target = 0.8
alpha = 0.05
alternative = "two-sided"
warnings = []
lo = 4.0  # Fisher z needs n > 3


def power_at(n, rho):
    return pw.corr_power(rho, n, alpha, alternative)  # as pwr::pwr.r.test


# %% Solve
n_exact = None
target_power = None
if solve_for == "n":
    target_power = target
    n_exact = pw.solve_increasing(lambda n: power_at(n, r), target, lo, 10.0, 1e7)
    if math.isnan(n_exact):
        warnings.append("The target power is not reached below 10,000,000 observations.")
    n = pw.ceil_n(n_exact)
elif solve_for == "power":
    n = n_given
else:
    target_power = target
    n = n_given
    r = pw.solve_on(lambda x: power_at(n, x), target, 1e-6, 1.0 - 1e-6)
    if math.isnan(r):
        warnings.append("No correlation below 1 reaches the target power with this sample.")
power = power_at(n, r)
tc = stats.t.isf(alpha / (2 if alternative == "two-sided" else 1), n - 2.0)
r_crit = math.sqrt(tc * tc / (tc * tc + n - 2.0))

# %% Curves and sensitivity
n_ref = n if math.isfinite(n) else 100.0
xs = pw.grid(lo, max(2.5 * n_ref, lo + 10.0))
effects = [min(s * r, 0.999) for s in (0.75, 1.0, 1.25)] if math.isfinite(r) else [0.3]
curve = [(float(x), power_at(float(x), e), f"r = {e:.2f}") for e in effects for x in xs]
tables = []
if solve_for == "n" and math.isfinite(r):
    rows = [{"effect": f"r = {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 sample size by power",
        "columns": [{"key": "effect", "label": "Correlation", "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.correlation",
    "methodVersion": "1.0.0",
    "title": "Power analysis: correlation",
    "engine": cs.engine_info("scipy"),
    "summary": f"Correlation test: n = {n:,.0f}, r = {r:.3f}, power = {power:.3f} at {alternative} α = {alpha}.",
    "apa": f"N = {n:,.0f}, r = {cs.fmt_num(r)}, α = {alpha}, 1 − β = {power:.3f}",
    "statistics": [
        {"key": "n", "label": "Sample size", "value": n, "format": "integer"},
        {"key": "power", "label": "Power", "value": power},
        {"key": "r", "label": "Correlation", "value": r},
        {"key": "r_crit", "label": "Critical r", "value": r_crit},
    ],
    "tables": tables,
    "warnings": warnings,
    "notes": ["Fisher z with the critical r from the t distribution (pwr::pwr.r.test). Required sizes are rounded up and the power is recomputed at the rounded size."],
    "charts": [cs.chart(
        "power", "power-curve", "Power by sample size",
        {"x": cs.col("Sample size", [c[0] for c in curve]), "power": cs.col("Power", [c[1] for c in curve]),
         "series": cs.col("Correlation", [c[2] for c in curve])},
        controls={"target": target if target_power is not None else 0.8},
    )],
    "values": {"n": n, "n_exact": n_exact, "power": power, "target_power": target_power, "r": r, "r_crit": r_crit, "alpha": alpha},
})
R

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

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

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

# %% Inputs
solve_for <- "n" # n | power | effect
r <- 0.3
n_given <- 50
target <- 0.8
alpha <- 0.05
alternative <- "two-sided"
warnings <- list()
lo <- 4 # Fisher z needs n > 3

power_at <- function(n, rho) cs_power_corr(rho, n, alpha, alternative) # as pwr::pwr.r.test

# %% 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, r), target, lo, 10, 1e7)
  if (is.nan(n_exact)) warnings <- c(warnings, "The target power is not reached below 10,000,000 observations.")
  n <- cs_power_ceil(n_exact)
} else if (solve_for == "power") {
  n <- n_given
} else {
  target_power <- target
  n <- n_given
  r <- cs_power_solve_on(function(x) power_at(n, x), target, 1e-6, 1 - 1e-6)
  if (is.nan(r)) warnings <- c(warnings, "No correlation below 1 reaches the target power with this sample.")
}
power <- power_at(n, r)
tc <- stats::qt(alpha / (if (alternative == "two-sided") 2 else 1), n - 2, lower.tail = FALSE)
r_crit <- sqrt(tc^2 / (tc^2 + n - 2))

# %% Curves and sensitivity
n_ref <- if (is.finite(n)) n else 100
xs <- cs_power_grid(lo, max(2.5 * n_ref, lo + 10))
effects <- if (is.finite(r)) pmin(c(0.75, 1, 1.25) * r, 0.999) else 0.3
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("r = %.2f", e))
}))
tables <- list()
if (solve_for == "n" && is.finite(r)) {
  rows <- lapply(effects, function(e) {
    row <- list(effect = sprintf("r = %.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 sample size by power",
    columns = c(list(list(key = "effect", label = "Correlation", 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.correlation",
  methodVersion = "1.0.0",
  title = "Power analysis: correlation",
  engine = cs_engine_info("stats"),
  summary = sprintf("Correlation test: n = %s, r = %.3f, power = %.3f at %s alpha = %s.", format(n, big.mark = ","), r, power, alternative, format(alpha)),
  apa = sprintf("N = %s, r = %s, α = %s, 1 − β = %.3f", format(n, big.mark = ","), cs_fmt_num(r), format(alpha), power),
  statistics = list(
    list(key = "n", label = "Sample size", value = n, format = "integer"),
    list(key = "power", label = "Power", value = power),
    list(key = "r", label = "Correlation", value = r),
    list(key = "r_crit", label = "Critical r", value = r_crit)
  ),
  tables = tables,
  warnings = warnings,
  notes = "Fisher z with the critical r from the t distribution (pwr::pwr.r.test). 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",
    list(x = cs_col("Sample size", curve$x), power = cs_col("Power", curve$power), series = cs_col("Correlation", curve$series)),
    controls = list(target = if (is.na(target_power)) 0.8 else target)
  )),
  values = list(n = n, n_exact = n_exact, power = power, target_power = target_power, r = r, r_crit = r_crit, alpha = alpha)
))

Sources

  • Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.), chapter 3.
  • Champely, S. (2020). pwr: Basic functions for power analysis (pwr.r.test).

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