Tutorials › Introduction to Statistics › The Pearson Chi-Square Statistic

Chi-Square Tests of Independence and Homogeneity · Tutorial 828 of 996

The Pearson Chi-Square Statistic

Calculate the Pearson chi-square statistic from a two-way table and interpret what its cell contributions say about observed and expected counts.

Intermediate 9 min read

What You'll Learn

  • Define the observed and expected counts used in the Pearson chi-square statistic
  • Calculate expected counts from a two-way table’s margins
  • Compute each cell’s squared discrepancy divided by its expected count
  • Add the cell contributions to obtain the Pearson chi-square statistic
  • Interpret large contributions as substantial discrepancies from the null model
  • Recognize what the statistic does and does not reveal by itself

Why Summarize Differences Across a Table?

A two-way table records counts for combinations of categories. To assess a null model of independence or homogeneity, we compare each observed count with the count expected under that model. Some cells may be above their expected counts and others below. A useful summary must combine these differences across the table while giving discrepancies on different count scales a comparable weight.

The Pearson chi-square statistic does this by squaring each observed-minus-expected difference, dividing by the corresponding expected count, and summing across all cells. Squaring prevents positive and negative differences from cancelling. Dividing by the expected count scales the discrepancy: an absolute difference of five counts is more notable when 10 were expected than when 100 were expected.

Definition: For a two-way table with observed count \(O_{ij}\) and null-expected count \(E_{ij}\) in row \(i\), column \(j\), the Pearson chi-square statistic is $$ X^2=\sum_i\sum_j\frac{(O_{ij}-E_{ij})^2}{E_{ij}}. $$ The quantity \((O_{ij}-E_{ij})^2/E_{ij}\) is that cell’s contribution to \(X^2\). Each contribution is nonnegative, and the statistic is their sum.

Here \(O_{ij}\) is the count actually recorded in the cell. The expected count \(E_{ij}\) is the count specified by the null model, not a second observed value. For a null model of independence, or a homogeneity model with the same category proportions across groups, the expected count is calculated from the margins:

$$ E_{ij}=\frac{(\text{row }i\text{ total})(\text{column }j\text{ total})}{n}. $$

This expected-count formula is a brief reminder of Calculating Expected Cell Counts. The statistic’s calculation is then mechanical: find each difference, square it, divide by its expected count, and add. Keep enough digits during the calculation, and round the final result to a sensible number of significant figures.

What the Formula Measures

The cell contribution can also be written as the square of a scaled difference:

$$ \frac{(O_{ij}-E_{ij})^2}{E_{ij}} = \left(\frac{O_{ij}-E_{ij}}{\sqrt{E_{ij}}}\right)^2. $$

This identity gives a useful justification for the formula’s structure. The raw difference \(O_{ij}-E_{ij}\) is measured in counts, but a difference of a given size has different significance as a discrepancy when the expected counts differ. Scaling by \(\sqrt{E_{ij}}\) makes the squared contribution sensitive to the size of the difference relative to the expected count’s scale. The formula then adds these nonnegative, scaled discrepancies across the table.

This is a construction of a single summary, not a claim that cells vary independently or that each cell term alone is an inferential test. The row and column totals connect the cells. The table-level statistic reflects the collection of differences together.

1
Identify the null-expected counts.
Use the stated null model and the table margins to obtain \(E_{ij}\) for every cell.
2
Find each cell’s discrepancy.
Calculate \(O_{ij}-E_{ij}\). The sign tells whether the observed count is above or below expectation.
3
Calculate each contribution.
Square the discrepancy and divide by that cell’s expected count.
4
Add the contributions.
The sum is \(X^2\), a nonnegative summary of the table’s discrepancies from its null model.

Worked Calculations

Worked Example: A Two-by-Two Table

Suppose a hypothetical survey records whether 100 students prefer Option A or Option B and whether they commute by bus or another method. The null model is that preference and commute method are independent. The observed counts are:

Option AOption BTotal
Bus302050
Other method203050
Total5050100

Under independence, the expected count in each cell is its row total multiplied by its column total and divided by 100. For example, the expected number who both take the bus and prefer Option A is \(E_{11}=(50)(50)/100=25\). The margins are equal, so the four expected counts are all 25.

Now calculate the cell contributions:

  • Bus and Option A: \((30-25)^2/25=25/25=1\).
  • Bus and Option B: \((20-25)^2/25=25/25=1\).
  • Other method and Option A: \((20-25)^2/25=25/25=1\).
  • Other method and Option B: \((30-25)^2/25=25/25=1\).

Therefore, \(X^2=1+1+1+1=4.000\). Every observed count differs from its expected count by five, and each cell contributes equally because the expected counts are equal. The statistic summarizes the overall discrepancy; it does not retain which cells were above expectation unless their original differences are also examined.

Worked Example: Unequal Expected Counts

Consider a hypothetical table of 100 respondents classified by one of two groups and one of two preferences. Assume the null model says group and preference are independent. The observed table has row totals 20 and 80, and column totals 30 and 70:

Preference 1Preference 2Total
Group 1101020
Group 2206080
Total3070100

The expected counts are \((20)(30)/100=6\), \((20)(70)/100=14\), \((80)(30)/100=24\), and \((80)(70)/100=56\). Each observed count differs from its expected count by four, but the contributions are not equal:

  • Group 1, Preference 1: \((10-6)^2/6=16/6=2.667\).
  • Group 1, Preference 2: \((10-14)^2/14=16/14=1.143\).
  • Group 2, Preference 1: \((20-24)^2/24=16/24=0.6667\).
  • Group 2, Preference 2: \((60-56)^2/56=16/56=0.2857\).

Adding the unrounded terms gives \(X^2=16/6+16/14+16/24+16/56=4.762\), to three decimal places. The same absolute discrepancy contributes more when the expected count is smaller. In particular, the first cell contributes most to this sum. This describes its share of the statistic, not a separate conclusion about that cell.

Worked Example: A Homogeneity Table

Suppose a hypothetical comparison records a binary outcome in three independently sampled groups, with 40 observations per group. The null model of homogeneity says that the outcome proportions are the same in all three groups. The observed counts are:

GroupOutcome YesOutcome NoTotal
Group 1281240
Group 2202040
Group 3122840
Total6060120

For each group, the expected count for either outcome is \((40)(60)/120=20\). The six contributions are \(64/20=3.2\), \(64/20=3.2\), \(0/20=0\), \(0/20=0\), \(64/20=3.2\), and \(64/20=3.2\). Thus \(X^2=3.2+3.2+0+0+3.2+3.2=12.80\).

The statistic’s contributions show that the nonzero discrepancies come from the Yes and No counts in Groups 1 and 3; Group 2 matches its expected counts. The signs of the original differences show the pattern: Group 1 has more Yes counts than expected, while Group 3 has fewer. The statistic itself adds squared differences, so it records their size without preserving those directions.

Reading the Statistic Carefully

A larger \(X^2\) means that, in aggregate, the observed counts lie farther from the counts specified by the null model on the formula’s scaled discrepancy measure. It is not a percentage, a count, or a measure with the units of the original observations. It is also not enough, by itself, to identify a particular pattern: different tables can produce the same value while having different cells above and below expectation.

Individual contributions help explain how the sum was assembled. A large contribution means that cell’s squared observed-minus-expected discrepancy is large relative to its expected count. To describe direction, look separately at \(O_{ij}-E_{ij}\): a positive difference means more observations than expected, and a negative difference means fewer. The contribution alone cannot distinguish these directions because the difference is squared.

The Pearson chi-square statistic is used in both tests of independence and tests of homogeneity. In an independence setting, the categories are recorded on the same observational units; in a homogeneity setting, category distributions are compared across groups. In either case, the expected counts are calculated under the relevant null model, and the same sum-of-contributions formula applies. The interpretation must still name that null model: the statistic summarizes discrepancies from the particular expectations used to calculate it.

Common Mistakes

  • Adding raw differences. Positive and negative differences can cancel. The Pearson statistic squares each difference before adding.
  • Dividing by the observed count. The denominator is \(E_{ij}\), the expected count under the null model, not \(O_{ij}\).
  • Comparing only absolute differences. A difference of four does not contribute equally in every cell; divide its square by that cell’s expected count.
  • Calling a large contribution proof of a real effect. It describes a cell’s contribution to the computed statistic. A statistical conclusion requires the appropriate inferential comparison and context.
  • Interpreting the statistic as directional. Since the differences are squared, \(X^2\) does not say which cells are above or below expectation. Check the signed differences for that description.
Key takeaway: For each cell, calculate \((O_{ij}-E_{ij})^2/E_{ij}\), then add all the contributions to obtain \(X^2\). Large contributions mark cells with relatively substantial discrepancies from the null model; the signed differences are needed to describe whether counts are higher or lower than expected.

Check Your Understanding

Use the Pearson chi-square formula and the distinctions among observed counts, expected counts, and contributions to answer these questions.

  1. In one cell, \(O_{ij}=18\) and \(E_{ij}=12\). What is its contribution to \(X^2\)?
  2. Two cells each have an absolute difference of five. One has expected count 10 and the other expected count 50. Which contributes more, and what are the two contributions?
  3. Why can’t the Pearson chi-square statistic by itself tell you whether a particular cell is above or below its expected count?
  4. If a table’s cell contributions are 0.5, 1.2, 0.0, and 2.3, what is its Pearson chi-square statistic?
  5. In a two-way table, what information is needed to calculate the expected count for one cell under independence?