Running Average Simulator

The learner runs many independent sample paths of a running mean (or relative frequency, or centred sum) against n, plays the paths forward, drags an inspection line and an epsilon band, and reads off how many paths are outside the band, the run-to-run spread versus sigma/sqrt(n), and Chebyshev or required-n figures. Covers the law of large numbers, Monte Carlo error and laws with no mean (Cauchy, zeta) that never settle.

Used in: Introduction to Probability Theory, Introduction to Statistics

Props

PropTypeDefaultDescription
titlestringfrom the viewCard title.
experimentstring"coin" ("distribution" when `distribution` is given)What one trial is: coin (x = 1 with prob. p), die (x in 1..6), two-dice (d1, d2 and x = d1 + d2), point-in-square ((x, y) uniform in [0,1]^2) or distribution (x drawn from `distribution`).
distributionstring | {family, params}"Normal(0, 1)"Law of one draw for experiment "distribution": any spec the sampling core accepts ("Exp(rate=1)", "Cauchy(0, 1)", {family: "binomial", params: {n: 30, p: "1/12"}}), plus the local families "zeta" (P(X=k) proportional to k^-s, params {s}) and "signed-zeta".
pnumber0.5Success probability of the coin experiment.
successLabelstring"heads"Name of the outcome x = 1 in the coin experiment (plain text), e.g. "point-up".
eventstring | nullnullCondition on the trial's variables (x; d1, d2 for two-dice; x, y for point-in-square), e.g. "x == 6", "x >= 9", "d1 == d2", "x^2 + y^2 <= 1". The tracked value becomes its indicator, so the running mean is a relative frequency.
transformstring | nullnullExpression g of the trial's variables, e.g. "x^2" or "exp(x)"; the running mean then estimates E[g]. Ignored when `event` is set.
quantityLabelstringfrom the viewY-axis label for the plotted statistic (plain text with $...$ TeX).
targetnumber | nullcomputedValue the running mean should approach. Default: the exact mean of the tracked value when it can be computed (numerically for point-in-square and transformed continuous laws, marked approx.). Not shown when the mean does not exist.
targetLabelstring"p" for events, "\\mu" otherwiseTeX symbol for the target, e.g. "\\theta", "P(\\text{six})".
compareTargetnumber | nullnullA competing (wrong) model's value, drawn as a second dashed line in the running-mean view.
compareLabelstring"competing model"Legend text for `compareTarget`.
normalizerstring"n"Initial view: n (running mean S_n/n), none (centred sum S_n - n mu), sqrt ((S_n - n mu)/sqrt n), lil ((S_n - n mu)/sqrt(2 n log log n)).
normalizersstring[][]Views offered in a picker (values as for `normalizer`); empty or one entry hides the picker.
maxNnumber1000Horizon: number of trials per path (10 to 1,000,000; paths x maxN is capped at 4,000,000).
pathsnumber20Number of independent paths (1 to 1000; at most 60 are drawn, all are used in the readouts).
seednumber | string1Seed of the reproducible random stream; New sample moves to the next stream.
epsilonnumber | null0.1 (or `margin`)Half-width of the band around the target in the running-mean view, with a slider; null hides the band.
showEpsilonSliderbooleantrueShow the epsilon slider.
deviationBandnumber10Half-width c of the band around 0 in the centred-sum view (none).
showSEBandbooleanfalseDraw the envelope target +- z sigma/sqrt(n) (scaled to the current view).
confidencenumber0.95Level that sets z for the SE envelope and the required-n formula.
showChebyshevbooleanfalseShow the Chebyshev bound sigma^2/(n epsilon^2) next to the observed fraction outside the band (and as a checkpoint column).
showHistogrambooleanfalseHistogram of the plotted statistic across paths at the inspected n, with its normal approximation (and the one-draw density for Cauchy laws).
showErrorPlotbooleanfalseLog-log plot of the root-mean-square error over paths against n, with the sigma/sqrt(n) reference line.
showDrawsbooleanfalsePoint-in-square only: scatter of path 1's draws up to the inspected n, coloured by the event.
checkpointsnumber[] | nullnullValues of n marked on the plot and tabulated (mean, SD across paths, theory SD, fraction outside the band).
inspectNnumber | nullmaxN (the required n when `margin` is set)Initial position of the draggable inspect line (readouts and histogram use this n).
marginnumber | nullnullTarget margin of error E: shows required n = ceil((z sigma/E)^2) as a vertical line and readout, and sets the band to +-E unless `epsilon` is given.
planningSdnumber | nullnullPlanning sd for `margin` (e.g. 0.5, the worst case for a proportion). Default: the pilot estimate if `pilotN` is set, else the model sd.
pilotNnumber | nullnullEstimate the planning sd S_0 from the first pilotN draws of path 1.
exactHitValuenumber | nullnullMark the n at which a path's running mean equals this value exactly, and count such paths at the inspected n (with the exact probability for a coin).
logXbooleantrue when maxN >= 100Logarithmic n axis (learner can toggle).
yRange[number, number] | nullautoFixed y range for the running-mean view.
controlsstring[]all controls shownIds of the hideable readouts and legends to show (see the controls registry: readout.sd, readout.theory-sd, label.sample-mean, legend.normal-approximation, legend.law-density); core ones always show. Absent = everything. Fitted per page by tooling, not by hand.