Controls
Presets
Parameters
Model checks
The science
Question. Are K category counts consistent with a fair generator, i.e. equal expected counts E = N/K? Pearson's statistic is X² = Σ (Ok - E)² / E, with df = K - 1 degrees of freedom. The terms of the sum are what the bars (3D) and the rose sectors (2D) show.
p-value. If H0 is true, X² follows (approximately) a chi-square distribution, so p = Q(df/2, X²/2) with Q the regularised upper incomplete gamma function. It is computed exactly (series and continued fraction), not with the Wilson-Hilferty normal approximation. You reject H0 when p < α, i.e. when X² exceeds the critical value; by construction a fair generator is rejected in a fraction α of experiments (false alarms).
Power. If the generator is loaded with Cohen effect size w = √(Σ (pk - p0)²/p0), X² becomes non-central chi-square with λ = N w². The power is Σj Poisson(j; λ/2) Q(df/2 + j, crit/2). Doubling N doubles λ: small effects need large samples.
Simplifications. The chi-square law is an asymptotic approximation, valid when every expected count is at least about 5, which is why N is at least 50 and K at most 10 here. The loaded generator is a linear tilt of the probabilities, one of many possible alternatives. Each completed batch of N samples is one experiment; the histogram collects their X² values and is compared with the exact density. Checks: closed-form values of Q, inverse critical value, Monte-Carlo mean and variance under H0, simulated false-alarm rate, simulated power against the exact non-central formula, and validity of the loaded generator.