Try
A synthetic random sample of 120 residents from a population exceeding 1200 records each person’s commute category and preferred opening schedule. The resulting two-by-three table has first row 30,20,10 and second row 15,25,20. Each person contributes once to exactly one cell. The null says the two categorical variables are independent in the represented population.
Now imagine the identical numbers came from independently taking a random sample of 60 residents in each of two districts, each with more than 600 residents, then recording one schedule preference. The numerical statistic would be the same, but the design question is homogeneity: whether the district populations share the same category distribution. Choose the study interpretation from recruitment, not from which label sounds more impressive.
Predict
Both row totals are 60. Column totals are 45,45,30. Under independence or equal distributions, predict the expected count in the first row’s third cell. It is not 10 just because that was observed. With half the sample in the first row and a quarter in the third column, the expected count is 120·(1/2)·(1/4)=15.
Predict whether chi-square should add signed discrepancies or squared standardized discrepancies. Positive and negative raw deviations cancel because the margins match; cancellation would hide the pattern the test is intended to detect.
Experiment
Enter two rows of counts, using commas or spaces within each row and a new line between rows:
30,20,10
15,25,20
Choose independence for the single-sample, two-variable design. Calculate and inspect every expected cell before interpreting the reference probability.
| Cell | Observed O | Expected E | Contribution (O−E)²/E |
|---|
| Row 1, column 1 | 30 | 22.5 | 2.5 |
| Row 1, column 2 | 20 | 22.5 | 0.2777778 |
| Row 1, column 3 | 10 | 15 | 1.6666667 |
| Row 2, column 1 | 15 | 22.5 | 2.5 |
| Row 2, column 2 | 25 | 22.5 | 0.2777778 |
| Row 2, column 3 | 20 | 15 | 1.6666667 |
The contributions sum to χ²=8.8888889. Degrees of freedom are (rows−1)(columns−1)=(2−1)(3−1)=2. The upper-tail probability is approximately 0.01174363. A chi-square discrepancy statistic is nonnegative; larger discrepancies supply evidence against the null, so the reference tail is upper, not a directional “greater category” hypothesis.
At a prespecified α=0.05, reject independence in the first study. State evidence of association, not proof that commute category causes preference. In the separately sampled district study, reject equal preference distributions. Switching the interpretation control should not change the numerical statistic for an unchanged table; it changes which population statement the design supports.
Understand
For row i and column j, expected count equals row total times column total divided by the grand total. This is the count implied by combining marginal proportions under the null. Pearson’s statistic sums (observed−expected)²/expected over every cell. Although expected counts may be nonintegers, observed entries here must be nonnegative whole counts of units.
All six expected counts in the worked example exceed 5, satisfying this workflow’s usual large-expected-count check. Also verify independent units, a defensible sampling or assignment mechanism, and a suitably small sampling fraction where observations are sampled without replacement. These checks do different jobs. A random-looking table cannot establish random recruitment, and a large total does not guarantee adequate expected counts in every cell.
When expected cells are sparse, the statistic can still be computed but its usual chi-square reference may be inappropriate. Consider an appropriate exact method or a revised data-collection plan. Do not merge categories solely to manufacture significance or to conceal a rare but substantively distinct outcome. If categories are combined for a defensible reason, explain the changed question.
Percentages are not substitute counts. Entering 60 and 40 from a 60%/40% report invents a sample size of 100 unless that was the actual denominator. Likewise, duplicating each record doubles the table but adds no independent evidence. The formal statistic would increase while its independence assumption failed. Ask what one row of the underlying dataset represents before trusting a small p-value.
The test is omnibus. Rejection means the entire independence or equal-distributions model is inconsistent with the evidence at the chosen threshold; it does not identify every differing category or population pair. Further comparisons require a plan that addresses multiplicity. Nonrejection is not proof of exact independence or practical equivalence.
Apply
Change the worked table to two rows 15,15,15 and 15,15,15. Predict its statistic before calculating. Then change to 5,0 and 0,5. Explain why the second table can look more dramatic while being less suitable for this reference approximation.
Compare numerical results with validity checks
In the equal-row table, every expected count is 15 and every contribution is zero. Thus χ²=0 and the chi-square upper-tail probability is 1. This is consistency with the null for these data, not proof that the null is true. In the small two-by-two table, every expected count is 2.5 and the statistic is 10. The sparse expected cells fail the usual approximation check; a displayed reference p-value is not a justified conclusion just because it is small. For an appropriate independent-unit two-by-two design, an exact conditional analysis is one possible alternative outside this workflow.
Before continuing, write a short report distinguishing an association test on one sampled population from a homogeneity test on separately sampled populations. Include the same numbers but different sampling descriptions so the distinction cannot be inferred from the table alone.
Continue
The earlier lessons on independence and homogeneity develop these null models. Here the practice requires an actual calculated reference probability, expected-cell audit and contextual conclusion. A calculator can evaluate a count table; it cannot certify that the counts came from the design described.