How the χ² (chi-square) distribution is built

χ² Builder

Draw values one at a time from the standard normal distribution, square them, and stack them up. The distribution of that running total is the χ² distribution. Pick a degrees of freedom (df) below and start drawing.

Samples completed: 0 Current df: 2

1. Draw a Z

Draw a value from the standard normal distribution (mean 0, SD 1)

2. Square it and stack

Squaring a Z always gives a value ≥ 0; stacking the squares gives the χ² statistic

χ² = —

3. Growing histogram

Completed samples pile up and trace out the χ² distribution (solid line)

The math

This is the real-data version of the Z's you've been squaring and stacking above.

Expected count for row i, column j Eij=Ri×CjN R = row total, C = column total, N = grand total
Pearson residual rij=Oij−EijEij This is the piece that behaves like one of the Z's above, once N is reasonably large.
χ² statistic χ2=∑i,j(Oij−Eij)2Eijdf=(r−1)(c−1) Square and sum the residuals above, cell by cell — exactly the sum of squared Z's this page builds up one draw at a time.