4.3 - Chi-squared goodness of fit
A fitted model will rarely reproduce every observed frequency exactly. You will measure the overall discrepancy, choose degrees of freedom after grouping and parameter estimation, and use an upper-tail chi-squared test to judge whether the data give evidence against the model.
Comparing observed and expected counts
How large must a difference between observed and expected counts be before we doubt a probability model? A difference of five is more striking against an expected count of five than against an expected count of five hundred.
The chi-squared statistic measures relative discrepancies across the whole table. Squaring stops positive and negative differences cancelling; dividing each squared difference by its expected count adjusts for the scale of that class.
Chi-squared statistic
After combining classes so that every expected frequency is at least , calculate
Use counts from independent observations, with the same exhaustive, non-overlapping classes for the observed and expected rows. Every is positive, and both rows total .
This statistic is not in the formula booklet: learn it. The booklet supplies chi-squared critical values.
The statistic is nonnegative. It is zero precisely when every observed count matches its expected count. A larger value indicates a greater discrepancy, but we need degrees of freedom before judging how unusual it is.
Worked example 1: small discrepancies
Question. Calculate the chi-squared statistic for the following complete table.
| Class | A | B | C |
|---|---|---|---|
| Observed | |||
| Expected |
Plan. Find each squared discrepancy divided by its expected count, then add.
Answer. .
Check. Expanding the numerator gives
Here , confirming the total by a different calculation.
Move five observations from C to B, keeping the expected counts and sample size fixed. This creates larger discrepancies without changing the model.
Worked example 2: larger discrepancies
Question. Calculate the chi-squared statistic when the observed row becomes , with expected row .
Plan. Recalculate all three contributions using the unchanged expected denominators.
Answer. to three significant figures.
Check. The alternative calculation gives . The larger result also agrees with the increased discrepancies in B and C.
Keep unrounded expected counts and contributions until the final sum. If classes were combined, calculate contributions from the combined table, rather than adding contributions calculated before grouping.
Watch out
The denominator is , not . An observed zero is allowed: if , its contribution is , provided the expected-count condition is satisfied.
Calculate a new table's total discrepancy.
Degrees of freedom
The same statistic can be unusual for one table and quite ordinary for another, because the number of independent discrepancies matters.
With three classes and a fixed sample size, choosing two observed counts determines the third: it must make the total . That leaves two independent counts. Fitting a model parameter from these same data uses further information, reducing the degrees of freedom again.
Goodness-of-fit degrees of freedom
For classes remaining after combining, with independent model parameters estimated from the sample being tested,
Under the null model, the statistic is approximately distributed as , subject to the expected-count and sampling conditions. A usable test needs .
The degrees-of-freedom rule is not in the formula booklet: learn it.
The subtraction of one accounts for the fixed total. A parameter given numerically in the hypothesis is not estimated from this sample, so it does not add to . Nor does the known sample size count as an estimated parameter.
Worked example 3: a fully specified model
Question. A goodness-of-fit test uses the specified model for independent observations. Its final classes are , with all expected counts at least . Find the degrees of freedom.
Plan. Count the final classes, then count parameters estimated from this sample.
The value was specified, so there is no fitted Poisson parameter to subtract.
Answer. Use .
Check. Once four of the five class counts are known, the fixed total determines the last. No sample estimate imposes an additional fitted-model constraint, leaving four degrees of freedom.
Keep the same final classes, but change the hypothesis so that its Poisson mean must be estimated. This changes the degrees of freedom even if the fitted numerical mean happens to be two.
Worked example 4: estimating the Poisson mean
Question. For a Poisson goodness-of-fit test, is estimated from the sample mean as . The final classes are again , with all expected counts at least . Find the degrees of freedom.
Plan. Subtract one for the total and one for the fitted mean.
Answer. Use .
Check. Compared with the fully specified model, one additional parameter has been chosen to agree with the sample. The degrees of freedom fall by exactly one, from four to three.
For with known and fitted , subtract one fitted parameter. For a normal model with both mean and standard deviation estimated from this sample, subtract two. If both were specified in advance, subtract neither. Count what has actually been estimated, rather than counting symbols in the distribution's name.
Watch out
Seven original classes reduced to five final classes give , not . If grouping leaves no positive degrees of freedom, the stated chi-squared procedure cannot give a valid test; do not restore small classes merely to obtain a positive number.
Use both grouping and parameter counting in this check.
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account