Tutorials › Introduction to Statistics › Decomposing the Chi-Square Statistic by Category

Chi-Square Goodness of Fit · Tutorial 806 of 996

Decomposing the Chi-Square Statistic by Category

Calculate each category’s contribution to a Pearson goodness-of-fit statistic and see how the contributions combine into the overall measure.

Intermediate 9 min read

What You'll Learn

  • Calculate a category’s contribution using its observed and expected counts
  • Assemble category contributions into the Pearson chi-square statistic
  • Interpret what a large contribution says about a category’s role in the total
  • Compare contributions while accounting for differences in expected counts
  • Check calculations by summing the contributions

Why Break the Statistic Into Categories?

A Pearson goodness-of-fit test compresses a set of observed category counts into one statistic. That total helps assess whether the data are compatible with a proposed probability model, but it does not show how much each category adds to the total. Decomposing the statistic fills in that arithmetic: calculate one contribution per category, then add the contributions.

This breakdown is useful for checking a calculation and seeing which categories account for more of the statistic. Each contribution compares an observed count with its expected count under the null model. The comparison is scaled by the expected count, so raw differences alone do not determine the contribution.

Category Contributions and the Pearson Statistic

Definition: For category \(i\), let \(O_i\) be its observed count and \(E_i\) its expected count under the null model. Its Pearson chi-square contribution is $$ \frac{(O_i-E_i)^2}{E_i}. $$ For \(k\) categories, the overall Pearson goodness-of-fit statistic is the sum of the category contributions: $$ X^2=\sum_{i=1}^{k}\frac{(O_i-E_i)^2}{E_i}. $$

The observed count \(O_i\) is the number of sampled individuals in category \(i\). If the null model assigns category \(i\) probability \(p_i\), then its expected count is \(E_i=np_i\), where \(n\) is the total sample size. Expected counts need not be whole numbers.

The square makes every contribution nonnegative: a category contributes whether its observed count is above or below its expected count. A contribution of zero means the counts match exactly. A larger contribution means that the category accounts for more of the overall statistic, after scaling the discrepancy by its expected count. It does not, by itself, tell whether the observed count was higher or lower than expected.

Why the Contributions Add

The additivity is not an additional approximation or a separate statistical result. It follows directly from how the Pearson statistic is defined. Each category supplies one term, and the statistic is the sum of those terms.

1
Write each category’s discrepancy.
For category \(i\), subtract its expected count from its observed count: \(O_i-E_i\).
2
Scale that discrepancy.
Square it and divide by the category’s expected count, giving \((O_i-E_i)^2/E_i\).
3
Add across categories.
Summing those \(k\) terms gives the Pearson statistic \(X^2\), with no category omitted or counted twice.

In symbols, the calculation is simply

$$ \text{category 1 contribution}+\cdots+\text{category }k\text{ contribution}=X^2. $$

This identity is also a practical arithmetic check. If the separately calculated contributions do not sum to the reported statistic, at least one term or the final addition needs to be checked.

Worked Calculations

Worked Example: Three Categories With Equal Expected Counts

Suppose a hypothetical random sample of 90 people is classified into three mutually exclusive and exhaustive categories. Under the stated null model, each category has probability \(1/3\). The observations are independent, and each expected count is 30, so the expected counts are large enough for the usual chi-square approximation in this example.

The expected count in each category is \(E_i=np_i=90(1/3)=30\). Suppose the observed counts are 42, 33, and 15. They sum to 90, as they must.

CategoryObserved \(O_i\)Expected \(E_i\)Contribution
A4230\((42-30)^2/30=144/30=4.800\)
B3330\((33-30)^2/30=9/30=0.3000\)
C1530\((15-30)^2/30=225/30=7.500\)

Adding the terms gives

$$ X^2=4.800+0.3000+7.500=12.60. $$

Category C has the largest contribution, 7.500, and category A contributes 4.800. Category B contributes relatively little because its observed count, 33, is close to its expected count of 30. These are statements about the components of the statistic; by themselves, they are not a conclusion about a p-value or whether to reject a null hypothesis.

Worked Example: Unequal Expected Counts

Imagine a hypothetical random sample of 120 independent observations, each assigned to exactly one of three exhaustive categories. The null model specifies probabilities 0.20, 0.30, and 0.50. The expected counts are therefore 24, 36, and 60. All exceed 5, so the expected-count condition for the usual chi-square approximation is satisfied.

Suppose the observed counts are 30, 30, and 60. They also sum to 120. Calculate each term separately:

$$ \begin{aligned} \text{Category 1 contribution}&=\frac{(30-24)^2}{24}=\frac{36}{24}=1.500,\\ \text{Category 2 contribution}&=\frac{(30-36)^2}{36}=\frac{36}{36}=1.000,\\ \text{Category 3 contribution}&=\frac{(60-60)^2}{60}=\frac{0}{60}=0. \end{aligned} $$

The overall statistic is

$$ X^2=1.500+1.000+0=2.500. $$

The first two categories have the same absolute discrepancy of 6 observations, but their contributions differ. The discrepancy is divided by the expected count: \(36/24=1.500\) for the first category and \(36/36=1.000\) for the second. Thus, comparing raw differences alone would miss the scaling built into the Pearson statistic.

Worked Example: Expected Counts That Are Not All Equal

Consider a hypothetical random sample of 80 independent observations classified into three exhaustive categories. The null probabilities are 0.50, 0.30, and 0.20, giving expected counts of \(80(0.50)=40\), \(80(0.30)=24\), and \(80(0.20)=16\). Each expected count is at least 5, so the usual expected-count check is met. Suppose the observed counts are 34, 30, and 16.

The three contributions are

$$ \begin{aligned} \text{Category 1 contribution}&=\frac{(34-40)^2}{40}=\frac{36}{40}=0.9000,\\ \text{Category 2 contribution}&=\frac{(30-24)^2}{24}=\frac{36}{24}=1.500,\\ \text{Category 3 contribution}&=\frac{(16-16)^2}{16}=0. \end{aligned} $$

The sample total is \(34+30+16=80\), consistent with the stated sample size. Adding the contributions gives

$$ X^2=0.9000+1.500+0=2.400. $$

Categories 1 and 2 each differ from expectation by 6 observations, yet category 2 contributes more because its expected count is smaller. Category 3 contributes zero because its observed and expected counts are identical. The total 2.400 is the Pearson statistic formed from all three categories.

What the Decomposition Tells You

A contribution is a portion of the total statistic, not a separate test statistic with its own goodness-of-fit p-value. The overall test uses the sum and its appropriate reference distribution. Looking at the components can describe where the total comes from, but inferential conclusions still depend on the complete test and its assumptions.

Contributions can also be expressed as a share of the total when \(X^2>0\). For a category with contribution \(c_i\), that share is \(c_i/X^2\). For example, in the first worked example, category C accounts for \(7.500/12.60\), or about 59.5%, of the total. This is a descriptive share of the computed statistic, not the percentage of observations in that category and not a probability.

A large contribution indicates a category that accounts for a relatively large part of the statistic. The squared difference hides direction, however: both an excess and a deficit of the same size yield the same squared numerator. To say whether a category is above or below its expected count, inspect \(O_i\) and \(E_i\) themselves.

Common Mistakes

  • Using the raw difference as the contribution. The difference \(O_i-E_i\) may be positive or negative and is not the Pearson contribution. Square the difference and divide by \(E_i\).
  • Forgetting the denominator. The contribution is \((O_i-E_i)^2/E_i\), not merely \((O_i-E_i)^2\). The expected count scales the discrepancy.
  • Adding counts instead of contributions. The observed counts already sum to \(n\). The Pearson statistic is found by adding the category contributions, not the counts or the expected counts.
  • Reading direction from a contribution. A squared difference is nonnegative whether the observed count is above or below expectation. Compare \(O_i\) with \(E_i\) to determine the direction.
  • Rounding too early. Keep extra digits for intermediate contributions, add them, and round the final statistic. Early rounding can cause small discrepancies in the reported sum.

A reliable calculation therefore follows a consistent sequence: list the observed and expected counts, compute every \((O_i-E_i)^2/E_i\) term, and sum the unrounded terms. Confirm that the observed counts total \(n\), that each expected count matches the null model, and that the contributions add to the reported \(X^2\).

Check Your Understanding

For each question, focus on the category contributions and how they make up the overall statistic.

  1. A category has \(O_i=18\) and \(E_i=15\). Calculate its Pearson contribution.
  2. Two categories have the same absolute difference between observed and expected counts. Must their contributions be equal? Explain using the contribution formula.
  3. What does a contribution of zero tell you about that category’s observed and expected counts?
  4. Why can a category contribution not reveal, by itself, whether the observed count is above or below expectation?
  5. If the four contributions are 0.8, 1.2, 0, and 2.0, calculate the overall Pearson statistic and identify the largest contributor.