Skip to content
svgpower-curve

Power curve

How does power grow with sample size (or effect size), and where does it reach the target?

Demo data · seed 20261101 · 120 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each curve as power at each sample size or effect size.
  2. Find where a curve crosses the target line.
  3. Read the dropped line for the sample size needed.
  1. Callout 1: Where this curve crosses the target.
  2. Callout 2: A smaller effect needs far more data.
  3. Callout 3: The target power.

Watch out

  • Power from the effect you observed (“observed power”) adds nothing beyond the p-value. Choose an effect worth detecting.

Defaults

Target power
0.8
The chance of detecting the effect that you want the study to have, often 0.8 or 0.9.
Range 0.5 to 0.99, step 0.05
Log x axis
Off
Space the x axis by ratios, which suits values spanning orders of magnitude.

Pinned in the code

  • Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing statistical.
  • The crossing is interpolated linearly between the supplied points; the engine's solved n (rounded up) is the number to report.
  • Demo: two-sample, two-sided z approximation Φ(d√(n/2) − z₁₋α/₂) + Φ(−d√(n/2) − z₁₋α/₂); the power module uses exact noncentral t.
# Power curve — Codesplash Chart Lab (recipe "power-curve")
# controls: target=0.8, xLog=false
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("power-curve-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["effect"] = pd.Categorical(df["effect"].astype("string"), categories=["d = 0.3", "d = 0.5", "d = 0.8"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
X = "n per group"
P = "power"
S = "effect"
TARGET, XLOG = 0.8, False
groups = levels_of(df[S]) if S else [None]
series = []
for name in groups:
    d = df if name is None else df[df[S].astype(str) == str(name)]
    series.append((name if name is not None else "", d.dropna(subset=[X]).sort_values([X], kind="mergesort")))
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axhline(TARGET, color="grey", linestyle="--", linewidth=1)
for i, (name, d) in enumerate(series):
    col = PALETTE[i % len(PALETTE)]
    ax.plot(d[X], d[P], color=col, linewidth=2, label=name or P)
    hit = d[d[P] >= TARGET]
    if len(hit):  # first x reaching the target
        x0 = hit[X].iloc[0]
        ax.plot([x0, x0], [0, TARGET], color=col, linestyle=":", linewidth=1)
        ax.scatter([x0], [TARGET], color=col, zorder=3)
        ax.annotate(f"{x0:g}", (x0, 0), textcoords="offset points", xytext=(3, 4), fontsize=8, color=col)
if XLOG:
    ax.set_xscale("log")
ax.set_ylim(0, 1)
ax.set_xlabel(X)
ax.set_ylabel(P)
if S:
    ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads power-curve-demo.csv · app theme from the optional codesplash helper