Power and sample size explorer

The learner drags the critical value, the alternative mean and sliders for n, sigma and alpha, and sees the null and alternative sampling distributions with alpha, beta and power shaded. Other views show the power and OC curves, power against n with the n needed for a target power, simulated studies, margin-of-error planning (mean, proportion, planning value p*) and two-sample allocation trade-offs.

Used in: Introduction to Statistics

Props

PropTypeDefaultDescription
titlestringdepends on viewTitle bar text.
viewstring"distributions"Starting view: distributions (null vs alternative densities with alpha/beta/power shaded), power-curve, oc-curve, power-vs-n, margin (margin of error vs n), proportion-planning (achieved margin over true p for the n planned from p*), allocation (fixed total N, variance vs n1), allocation-ratio (target margin, total vs k = n2/n1).
viewsstring[]the four test views (distributions, power-curve, oc-curve, power-vs-n) for a test view; otherwise only the starting viewViews the learner can switch between with a toggle. One entry hides the toggle.
statisticstring"z"Test statistic: z (known sigma, plotted on the sample-mean scale), t (exact noncentral t power), F or chi-squared (noncentral, upper-tailed, driven by nc).
alternativestring"greater"Direction of H1 for z and t tests: greater (upper-tailed), less (lower-tailed) or two-sided. F and chi-squared tests are always upper-tailed.
mu0number100Null value of the mean (z, t).
mu1number106True mean under the alternative (z, t). Draggable in the densities and power-curve views.
sigmanumber15Population (planning) standard deviation for z/t tests and the mean margin view.
nnumber25Sample size. In the margin view it is the learner's n on the curve (default: the required n).
alphanumber0.05Significance level. Dragging the critical value changes it.
df1number3Numerator df (F) or df (chi-squared).
df2number20Denominator df (F).
ncnumber5Noncentrality under the alternative for F / chi-squared, scipy convention (noncentral chi-squared mean = df + nc).
targetPowernumber | null0.8Target power: shows the smallest n reaching it (exact power) and a target line in power vs n. null hides it.
showAlternativebooleantrueStart with the alternative density shown (false: only the null and alpha, for Type I error); the learner can toggle it.
simulatebooleantrueDensities view: 'Run 1 / 10 / 100 studies' buttons that draw test statistics under the chosen truth and count rejections against the theoretical rate.
truthstring"alternative"Which hypothesis is true in simulated studies at start: alternative or null (forced to null when showAlternative is false).
seednumber | string1Seed for the simulated studies.
outcomestring"mean"Margin view: mean (planning sigma) or proportion (planning p*).
Enumber2 (mean), 0.03 (proportion), 3 (allocation-ratio)Target margin of error.
levelnumber0.95Confidence level giving z* in the planning views.
pStarnumber0.5Planning value of a proportion (margin view with outcome proportion; draggable in proportion-planning).
trueSigmanumber | nullnullMargin view: an actual sigma that differs from the planning sigma; adds its margin curve and the achieved margin at the planned n.
sigma1number10Group 1 standard deviation (allocation views).
sigma2number20Group 2 standard deviation (allocation views).
Nnumber90Total sample size n1 + n2 (allocation view).
n1numberN/2Starting group 1 size in the allocation view (draggable).
knumber1Allocation ratio n2/n1 (allocation-ratio view, draggable).
xRange[number, number]autox-axis range of the starting view: mu or nc (power/OC curve), n (power vs n, margin), n1 (allocation), k (allocation-ratio).
parameters{name, min?, max?, step?, initial?, label?}[]per-view defaultsWhich sliders to show, in order, with optional ranges and starting values. Names: mu0, mu1, sigma, n, alpha, df1, df2, nc, targetPower, E, level, pStar, trueSigma, sigma1, sigma2, N, n1, k.
controlsstring[]all controls shownRegistry ids of the toggles, readouts and panels to show (core ones always show). Absent shows everything. Fitted by tooling from the props and what the lecture has taught; authors do not pick it by hand.