Formula and interpretation
The Pearson goodness-of-fit statistic is χ² = Σ(Oᵢ−Eᵢ)²/Eᵢ, summing across categories. With k categories and p model parameters estimated from the observed counts, the usual degrees of freedom are k − 1 − p. The chi-square approximation depends on sufficiently large expected counts and a suitable sampling model.
Worked goodness-of-fit example
Let observed counts be [20,30,50] and expected counts be [25,25,50]. The statistic is (20−25)²/25 + (30−25)²/25 + (50−50)²/50 = 1 + 1 + 0 = 2. With three categories and no fitted parameters, df = 2; the upper-tail p-value is about 0.368.