From Residuals to the Chi-Square Statistic
In “Observed Minus Expected: Computing Residuals,” you learned to find each cell’s residual by subtracting the expected count from the observed count. The next step is to use those differences to calculate the chi-square statistic. For a two-by-three table, there are six cells, so the calculation has six terms—one for every cell.
The statistic summarizes how far the observed counts are from the counts predicted by the null model. Each term squares a cell’s observed-minus-expected difference, then divides by that cell’s expected count. Squaring makes every term nonnegative, so differences above and below expectation both add to the overall statistic.
The formula uses the same residual \(O-E\) from the previous tutorial, but transforms it before adding it to the statistic. Keep the expected count matched to the observed count in the same cell. Do not add raw residuals, divide by the observed count, or leave out cells whose residual is zero.
A Reliable Hand-Calculation Routine
For a two-by-three table, organize the work so you can see all six cells and all six terms. If the expected counts are not already given, calculate them using the row total times the column total divided by the grand total, as in “Expected Count Formula: Row Total Times Column Total Over Grand Total” and “Building the Full Expected Counts Table.”
For each row and column combination, write down its observed count and its expected count.
Subtract expected from observed, \(O-E\), using the order established in “Observed Minus Expected: Computing Residuals.”
Square the residual and divide by that cell’s expected count: \((O-E)^2/E\).
The sum is the chi-square statistic. Keep extra digits during the calculation and round the final statistic sensibly.
A term is sometimes called a cell’s contribution to the statistic. The next tutorial examines those terms in more detail. For now, the important calculation is the complete sum: every cell contributes a term, even if its contribution is zero.
Worked Example: A Complete Calculation with Whole-Number Expected Counts
Worked Example: A Complete Calculation with Whole-Number Expected Counts
Suppose an invented study compares two community programs. Participants are asked which of three formats they would choose for a skills workshop. The table gives the observed counts. Consider the null model that program and preferred format are independent.
| Program | In person | Online | Self-paced | Total |
|---|---|---|---|---|
| Harbor | 24 | 20 | 16 | 60 |
| Ridge | 36 | 40 | 44 | 120 |
| Total | 60 | 60 | 60 | 180 |
Under independence, the expected count for each cell is its row total times its column total divided by the grand total. For example, the expected Harbor/in-person count is \((60)(60)/180=20\). Since all three column totals are 60, the expected counts are 20 in every Harbor cell and 40 in every Ridge cell.
| Program | In-person expected | Online expected | Self-paced expected |
|---|---|---|---|
| Harbor | 20 | 20 | 20 |
| Ridge | 40 | 40 | 40 |
Now calculate each of the six terms. The residual is shown inside each numerator, so the subtraction, squaring, and division are visible:
Add the six terms:
A useful arithmetic check is to add by row: Harbor’s terms sum to \(0.8+0+0.8=1.6\), and Ridge’s sum to \(0.4+0+0.4=0.8\). The row subtotals give \(1.6+0.8=2.4\), matching the direct sum. Both checks include all six cells.
The statistic \(X^2=2.4\) measures the overall discrepancy between the observed table and the counts expected under independence. It is evidence about how discrepant the observed counts are from that null model. To assess the strength of the evidence and find a p-value, use the appropriate degrees of freedom and chi-square distribution; the statistic alone is not a p-value or a test conclusion.
Worked Example: Keep Fractional Expected Counts
Worked Example: Keep Fractional Expected Counts
An invented survey asks users of two library branches which study area they prefer: quiet, group, or outdoor. The observed counts are shown below. Use the null model that branch and preference are independent. Fractional expected counts are valid; they represent counts predicted on average under the null model, not literal partial people.
| Branch | Quiet | Group | Outdoor | Total |
|---|---|---|---|---|
| East | 18 | 14 | 18 | 50 |
| West | 18 | 28 | 24 | 70 |
| Total | 36 | 42 | 42 | 120 |
Calculate expected counts from the margins. For example, East/quiet has expected count \((50)(36)/120=15\), while East/group has expected count \((50)(42)/120=17.5\). The full expected table is:
| Branch | Quiet expected | Group expected | Outdoor expected |
|---|---|---|---|
| East | 15 | 17.5 | 17.5 |
| West | 21 | 24.5 | 24.5 |
Use the expected count for the same cell in each denominator. In particular, do not round \(17.5\) or \(24.5\) to whole numbers before calculating:
Adding the unrounded terms gives:
The row-subtotal check gives \(0.6000+0.7000+0.0142857\approx1.3143\) for East and \(0.4285714+0.5000+0.0102041\approx0.9388\) for West. Together, \(1.3143+0.9388\approx2.2531\). Small differences in the last decimal can occur if intermediate terms are rounded earlier; retain the calculator values or more digits until the final sum.
Worked Example: A Larger Statistic from Six Terms
Worked Example: A Larger Statistic from Six Terms
Imagine an invented comparison of two recreation programs and three ways participants travel to activities. Each program has 90 participants. The observed table is:
| Program | Walk or bike | Public transit | Car | Total |
|---|---|---|---|---|
| Maple | 48 | 21 | 21 | 90 |
| Cedar | 24 | 33 | 33 | 90 |
| Total | 72 | 54 | 54 | 180 |
Under the null model that program and travel choice are independent, the expected Maple counts are \((90)(72)/180=36\), \((90)(54)/180=27\), and \((90)(54)/180=27\). Cedar has the same expected counts because its row total is also 90.
Calculate all six terms, including terms from cells where the observed count is below expectation:
Add the terms, keeping the repeated thirds together:
The row subtotals are \(4+1.3333+1.3333\approx6.6667\) for Maple and \(4+1.3333+1.3333\approx6.6667\) for Cedar. Their sum is approximately \(13.3333\), the same result. Notice that negative residuals do not create negative terms: the difference is squared in every cell.
This statistic describes the discrepancy in the table, but do not decide whether the evidence is convincing from its size alone. For a two-by-three table, the degrees of freedom are \((2-1)(3-1)=2\), as covered in “Degrees of Freedom for a Two-Way Table.” A test conclusion requires comparing the statistic with the appropriate chi-square distribution with those degrees of freedom to obtain a p-value, then interpreting that p-value in the test’s context.
Common Mistakes and AP Exam Tip
- Stopping after finding \(O-E\): Residuals are intermediate calculations. The statistic requires squaring each residual, dividing by its cell’s expected count, and summing all the terms.
- Using the wrong denominator: Divide by \(E\), not by \(O\), the row total, or the column total. Keep each denominator paired with the expected count for that same cell.
- Adding signed residuals: The formula adds \((O-E)^2/E\), not \(O-E\). Squaring is why both above-expected and below-expected counts increase \(X^2\).
- Leaving out a zero term: A cell with \(O=E\) contributes zero, but it still belongs in the six-cell calculation. Showing the term makes the work complete and easier to check.
- Rounding expected counts too soon: Keep fractional expected counts and full calculator precision through the calculations. Round the final statistic, not each input or intermediate result.
- Calling \(X^2\) a p-value: The statistic measures discrepancy and is evidence against the null model. Use the appropriate degrees of freedom and chi-square distribution to find the p-value and reach a conclusion.
- Giving a test conclusion without the design or context: If asked for a conclusion, name the null model and the variables or groups. A large statistic alone does not establish a particular relationship or cause.
For full-credit work, identify the observed and expected counts, show all six substitutions, add the terms accurately, and report the statistic with suitable rounding. If the question asks for inference too, continue with the degrees of freedom, p-value, and a contextual conclusion. Do not imply that the statistic by itself supplies the p-value or establishes convincing evidence.
Check Your Understanding
For each question, show the arithmetic clearly and keep the expected count matched to its cell.
- A cell has \(O=17\) and \(E=20\). Calculate its term \((O-E)^2/E\).
- A cell has \(O=12\) and \(E=12\). What term does it contribute, and why should the cell still be included in the full calculation?
- In a two-by-three table, the six terms are \(0.5\), \(1.2\), \(0\), \(0.3\), \(0.8\), and \(0.2\). Calculate \(X^2\).
- Why is it incorrect to divide \((O-E)^2\) by the observed count?
- A two-by-three table has \(X^2=6.1\). What additional information and procedure are needed before making a test conclusion?