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
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | depends on view | Title bar text. |
| view | string | "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). |
| views | string[] | the four test views (distributions, power-curve, oc-curve, power-vs-n) for a test view; otherwise only the starting view | Views the learner can switch between with a toggle. One entry hides the toggle. |
| statistic | string | "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). |
| alternative | string | "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. |
| mu0 | number | 100 | Null value of the mean (z, t). |
| mu1 | number | 106 | True mean under the alternative (z, t). Draggable in the densities and power-curve views. |
| sigma | number | 15 | Population (planning) standard deviation for z/t tests and the mean margin view. |
| n | number | 25 | Sample size. In the margin view it is the learner's n on the curve (default: the required n). |
| alpha | number | 0.05 | Significance level. Dragging the critical value changes it. |
| df1 | number | 3 | Numerator df (F) or df (chi-squared). |
| df2 | number | 20 | Denominator df (F). |
| nc | number | 5 | Noncentrality under the alternative for F / chi-squared, scipy convention (noncentral chi-squared mean = df + nc). |
| targetPower | number | null | 0.8 | Target power: shows the smallest n reaching it (exact power) and a target line in power vs n. null hides it. |
| showAlternative | boolean | true | Start with the alternative density shown (false: only the null and alpha, for Type I error); the learner can toggle it. |
| simulate | boolean | true | Densities view: 'Run 1 / 10 / 100 studies' buttons that draw test statistics under the chosen truth and count rejections against the theoretical rate. |
| truth | string | "alternative" | Which hypothesis is true in simulated studies at start: alternative or null (forced to null when showAlternative is false). |
| seed | number | string | 1 | Seed for the simulated studies. |
| outcome | string | "mean" | Margin view: mean (planning sigma) or proportion (planning p*). |
| E | number | 2 (mean), 0.03 (proportion), 3 (allocation-ratio) | Target margin of error. |
| level | number | 0.95 | Confidence level giving z* in the planning views. |
| pStar | number | 0.5 | Planning value of a proportion (margin view with outcome proportion; draggable in proportion-planning). |
| trueSigma | number | null | null | Margin view: an actual sigma that differs from the planning sigma; adds its margin curve and the achieved margin at the planned n. |
| sigma1 | number | 10 | Group 1 standard deviation (allocation views). |
| sigma2 | number | 20 | Group 2 standard deviation (allocation views). |
| N | number | 90 | Total sample size n1 + n2 (allocation view). |
| n1 | number | N/2 | Starting group 1 size in the allocation view (draggable). |
| k | number | 1 | Allocation ratio n2/n1 (allocation-ratio view, draggable). |
| xRange | [number, number] | auto | x-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 defaults | Which 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. |
| controls | string[] | all controls shown | Registry 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. |