Independent study guide

Chi-Square Tests: Goodness of Fit or Independence?

Build expected counts, choose the right degrees of freedom and interpret the p-value. Three worked examples and six explained exercises.

Nablio · 6 questionsPublished

1. Choose the test before calculating

Suppose a library wants to know whether borrowers choose its three pickup points in a planned split. Count one categorical variable and compare it with stated probabilities: use goodness of fit. If the library instead records both pickup point and membership type for each borrower, ask whether two categorical variables are associated: use independence.

Use counts, not percentages, and assign each independent observation to exactly one category or one cell. In both tests compare observed counts OO with expected counts EE under H0H_0:

χ2=∑(O−E)2E.\chi^2=\sum\frac{(O-E)^2}{E}.

The square treats excesses and shortfalls alike. Dividing by EE means a gap of five counts does not have the same weight in a cell expected to have ten as in one expected to have a hundred. Large values count against H0H_0, so use the right tail. The p-value is the probability, under H0H_0 and the test assumptions, of a statistic at least as large as the observed one. It is not the probability that H0H_0 is true.

2. Worked example: compare counts with a planned split

A workshop offered three pickup days and planned for 40%,35%,25%40\%,35\%,25\%. In a random sample of 100100 independent orders, the counts were 54,26,2054,26,20. At α=0.05\alpha=0.05, do the data disagree with the plan?

  1. Under H0H_0, the three population probabilities are those specified in the plan. The alternative is that at least one differs.
  2. Multiply the sample size by each probability: E=(40,35,25)E=(40,35,25). Check that these counts sum to 100100. None is small.
  3. Compute χ2=14240+(−9)235+(−5)225≈8.214.\chi^2=\frac{14^2}{40}+\frac{(-9)^2}{35}+\frac{(-5)^2}{25}\approx8.214. There are 3−1=23-1=2 degrees of freedom because the three counts share a fixed total and no probabilities were fitted from the sample.
  4. The right-tail p-value is about 0.01650.0165. Reject H0H_0 at 5%5\%. The sample provides evidence against the stated split. The first category contributes 4.94.9, the most of the three, but the overall test does not separately establish which probabilities differ.

3. Worked example: are pickup choice and membership related?

For 100100 independently sampled borrowers, record membership and weekday versus weekend pickup. In the table, parentheses show the expected counts under independence.

Observed and expected counts for pickup choices
MembershipWeekdayWeekendTotal
Individual36 (30)14 (20)50
Family24 (30)26 (20)50
Total6040100
  1. Under H0H_0, the pickup proportions are the same for the two membership types in the population. Under the alternative, they are not.
  2. Each row has 5050 people; 6060 of the 100100 picked a weekday. Under independence the first expected count is 50(60/100)=3050(60/100)=30. In general, use the row total times the column total divided by the grand total. The expected counts preserve both margins.
  3. Sum the four contributions: χ2=6230+(−6)220+(−6)230+6220=6.\chi^2=\frac{6^2}{30}+\frac{(-6)^2}{20}+\frac{(-6)^2}{30}+\frac{6^2}{20}=6. The degrees of freedom are (2−1)(2−1)=1(2-1)(2-1)=1. Once the row and column totals and one cell are fixed, the other cells are determined.
  4. The right-tail p-value is about 0.01430.0143. At 5%5\%, there is evidence of association in the population represented by this sample. In the sample, weekday pickup is 36/50=72%36/50=72\% versus 24/50=48%24/50=48\%. This comparison describes the direction; it does not establish that membership causes the choice.

4. Worked example: when the approximation is not reliable

A mailroom expects 90%,8%,2%90\%,8\%,2\% of packages to fall in three weight bands. In 5050 independent packages it observes 42,6,242,6,2. The expected counts are 45,4,145,4,1. The arithmetic formula gives a statistic, but two low expected counts make the usual chi-square approximation questionable. Do not use a standard chi-square table as if the assumptions held. For this specified model, a simulation can repeatedly draw 5050 packages under the stated probabilities and compare the simulated statistics with the observed one.

As a conservative classroom rule, check that each expected count is at least five; follow your course’s convention. Which threshold to use depends on the design and test. Do not remove a cell because its observed count is zero or pool categories after seeing which gives a preferred conclusion. For a sparse 2×22\times2 table, Fisher’s exact test can be an option when appropriate to the sampling design. Repeated observations on the same person are a separate problem not fixed by larger counts. If goodness-of-fit probabilities were estimated from the data, the simple k−1k-1 rule used here may not apply; verify the test and degrees of freedom for the fitted model.

Six practice exercises

1. Identify the test

An instructor compares counts for multiple-choice responses with probabilities stated before sampling. She then asks whether the response category is related to which of two course sections the student attends. Which test answers each question?

Show a hint

Count how many categorical variables are recorded per observation.

Show the explained solution

The first question concerns one response distribution and prescribed probabilities: goodness of fit. The second tests association between response category and course group: independence, assuming a joint sample of independent students. With group sample sizes fixed by design, the related test is called homogeneity.

2. Find expectations and degrees of freedom

An expected distribution for 8080 observations is 25%,25%,50%25\%,25\%,50\%. Observed counts are 18,26,3618,26,36. Find the expected counts, degrees of freedom and the statistic.

Show a hint

Check that the expected counts sum to the sample size.

Show the explained solution

The expectations are 20,20,4020,20,40. The differences are −2,6,−4-2,6,-4. Therefore χ2=4/20+36/20+16/40=2.4\chi^2=4/20+36/20+16/40=2.4, with 3−1=23-1=2 degrees of freedom.

3. Make a decision from the right tail

With three equally probable categories and 6060 independent observations, the counts are 14,16,3014,16,30. Compute the statistic and decide at 5%5\% and 1%1\%. The right-tail cutoffs for two degrees of freedom are 5.9915.991 and 9.2109.210, respectively.

Show a hint

Reject only if the test statistic exceeds the specified cutoff.

Show the explained solution

The expected count in each category is 2020. The statistic is 36/20+16/20+100/20=7.636/20+16/20+100/20=7.6. Reject at 5%5\%, but not at 1%1\%. In fact, the p-value is about 0.02240.0224; the data give the same p-value for both decisions.

4. Check an independence table

A sample of 6060 independent students records whether they prefer morning or afternoon review and whether they come by bus or otherwise. The two rows of counts are (18,12)(18,12) and (12,18)(12,18). Find all expected counts and decide at 5%5\%; the one-degree cutoff is 3.8413.841.

Show a hint

Both row totals and both column totals are equal.

Show the explained solution

Each expectation is 30⋅30/60=1530\cdot30/60=15. For one degree of freedom, χ2=4(9/15)=2.4\chi^2=4(9/15)=2.4. Do not reject at 5%5\%; there is insufficient evidence of association, not proof of independence.

5. Challenge the small-count shortcut

In an independent sample of 4040 days, a model predicts 95%,5%95\%,5\% for two event types. The observed counts are 32,832,8. Can the observed count of eight rescue the usual chi-square approximation?

Show a hint

Apply the small-count check under the null, not to the observed counts.

Show the explained solution

No. Expected counts are 38,238,2. Here the count of the rarer event under the null has an exact binomial model with n=40n=40 and p=0.05p=0.05. Use an exact procedure matched to the alternative instead of trusting the approximate chi-square p-value.

6. Compare the test with the story

The library example has p≈0.0143p\approx0.0143. A friend says, “There’s about a one-in-seventy chance the variables are independent, and membership changes behaviour.” Fix both claims.

Show a hint

Identify the assumption used to calculate the p-value and what the sampling design permits.

Show the explained solution

Assuming independence and the test conditions, a chi-square statistic at least as large as the observed one occurs with probability about 1.43%. This is evidence against independence, not a probability of the hypothesis. Observing an association does not establish causality.

The UQAM MAT2082 course description includes chi-square tests. These are original practice problems, not an official exam. Follow the conventions taught in your course.

Useful for

Work on the step you’re missing.

Tell us the subject and your preferred time. Nablio confirms the details by text or email.

Request a lesson