Topic contents

Lesson 4

Chi-square goodness-of-fit test

Do the observed counts of one categorical variable match prespecified hypothesized proportions?

Adjust survey results

Number of categories

Observed category counts

Sliders range from 0 to 110 people. Number fields can also display or accept larger counts.

Does the observed distribution of one categorical variable match the hypothesized distribution?

A school hypothesizes in advance that the proportions of students using three learning devices are 50%, 30%, and 20%. After randomly surveying students, do the observed counts deviate from these proportions beyond sampling variability?

H₀: The population category proportions equal the prespecified hypothesized proportions.
H₁: In the population, at least one category proportion differs from its hypothesized proportion.

Adjust survey results

Total number of people n=100; hypothesized proportions under H₀: 50.0%, 30.0%, 20.0%.

Observed and expected counts

0204060Laptop · Observed counts O: 56LaptopTablet · Observed counts O: 27TabletPhone · Observed counts O: 17Phone
  • Observed counts O
  • Expected counts E
Observed and expected counts

Bars show observed counts O; horizontal lines mark expected counts E calculated using the current sample size. Both update together when you drag the counts.

Adjust survey results

Observed category counts

Sliders range from 0 to 110 people. Number fields can also display or accept larger counts.

Expected counts E: hypothesized proportions times the observed sample size

Both the goodness-of-fit test and the test of independence in Lesson 03 compare O with E, but their expected counts come from different sources: here they come directly from the category proportions specified by H₀.

Ei=n×pi0{E}_{i}=n\times {p}_{i0}
n is the total number of people surveyed; pᵢ₀ is the hypothesized proportion for category i, specified before the test.
CategoryHypothesized proportionOE=n×p
Laptop50.0%5650.00
Tablet30.0%2730.00
Phone20.0%1720.00
Grand total100%100100.00

Substitute values term by term

  1. E1 = 100 × 0.5000 = 50.00 (Laptop)
  2. E2 = 100 × 0.3000 = 30.00 (Tablet)
  3. E3 = 100 × 0.2000 = 20.00 (Phone)
Class discussion: with hypothesized proportions held fixed, what happens to expected counts when only the total survey count changes?

Note: a goodness-of-fit test does not require equal sample counts in all categories. It compares observed counts with the proportions specified by H₀.

Adjust survey results

Observed category counts

Sliders range from 0 to 110 people. Number fields can also display or accept larger counts.

The χ² statistic: sum each category's deviation from its hypothesized expectation

χ2=∑i=1k(Oi−Ei)2Ei{\chi }^{2}={\sum }_{i=1}^{k}\frac{{({O}_{i}-{E}_{i})}^{2}}{{E}_{i}}
Each category has its own contribution to χ². Only the sum of all contributions is the χ² statistic for the entire sample.

Break down the statistic by category

CategoryHypothesized proportionOE=n×p(O−E)²/E
Laptop50.0%5650.000.720
Tablet30.0%2730.000.300
Phone20.0%1720.000.450
Grand total100%100100.001.470

From numerical substitution to the final result

  1. Category 1: (56 − 50.00)² / 50.00 ≈ 0.720
  2. Category 2: (27 − 30.00)² / 30.00 ≈ 0.300
  3. Category 3: (17 − 20.00)² / 20.00 ≈ 0.450
  4. χ² = 0.720 + 0.300 + 0.450 ≈ 1.470
1.470χ² statistic
2Degrees of freedom df = k−1
0.4795Right-tail p-value
Think about it: if all observed category counts exactly match the hypothesized proportions, what value will χ² approach?

Adjust survey results

Number of categories
Significance level α

Degrees of freedom for this test: 2

Degrees of freedom determine the χ² curve's shape; larger χ² values fall in the right tail

For a goodness-of-fit test with k categories, prespecified hypothesized proportions, and no parameters estimated from the sample, the degrees of freedom are df=k−1. Thus, three categories give df=2 and four give df=3.

024681012χ²Critical valueObserved χ²Right-tail p-value
  • χ² distribution (df=2)
  • Right-tail p-value
  • Critical value
χ² distribution (df=2)

The curve is the currently displayed χ² density. For this test, shading is the area to the right of the observed χ² statistic (the p-value); the critical line marks the critical value.

1.470Observed χ²
0.4795Right-tail p-value
5.991Critical value

P ≥ α=0.05. Fail to reject H₀.

Compare curve shapes only (without changing this test)

The displayed curve matches this test: df=2, χ²=1.470.

Compare df=1, 2, 5, and 10: as the degrees of freedom increase, why does the χ² distribution change from very high at the left endpoint to a right-skewed curve with an interior peak?

Adjust survey results

Number of categories

Observed category counts

Sliders range from 0 to 110 people. Number fields can also display or accept larger counts.

Significance level α

Complete a goodness-of-fit test in five steps and check its conditions

First specify the hypothesized proportions, then collect a sample, calculate χ², and find the right-tail p-value. Finally, check whether the χ² approximation can be used for a statistical decision.

CategoryHypothesized proportionOE=n×p(O−E)²/E
Laptop50.0%5650.000.720
Tablet30.0%2730.000.300
Phone20.0%1720.000.450
Grand total100%100100.001.470
① Hypotheses

H₀: category proportions are 50.0%, 30.0%, 20.0%; H₁: at least one category proportion differs.

② Expected counts and degrees of freedom

n=100; expected counts E in category order: 50.00, 30.00, 20.00; df=3−1=2.

③ Test statistic
χ2=∑(O−E)2E=1.470\chi^2=\sum\frac{(O-E)^2}{E}=1.470
④ p-value and decision

Right-tail p-value 0.4795; α=0.05; critical value≈5.991.

Fail to reject H₀. There is insufficient evidence against the prespecified population category proportions. This does not prove that the hypothesized proportions are exactly correct.

⑤ Conditions for use and research interpretation

Independent observations and appropriate sampling

Each student is counted in only one mutually exclusive category. Researchers must assess independence and sampling from the design; the program cannot verify them automatically.

Mutually exclusive and exhaustive categories

Every observation belongs to one and only one category. Hypothesized proportions should be specified in advance and sum to 100%.

Sufficiently large expected counts

This lesson uses a conservative classroom rule of thumb: expected count ≥5 in every category. Current minimum expected count: 20.00.

Dynamic check

All expected counts are ≥5, meeting this lesson's rule of thumb. Sampling and independence still need to be checked.

If the hypothesized proportions contain parameters estimated from the same data, the number of estimated parameters may need to be subtracted from the degrees of freedom; df=k−1 cannot be applied directly. If expected counts are too small, consider combining categories on theoretical grounds, increasing the sample size, or using exact/simulation methods. Do not combine categories arbitrarily after seeing the data to obtain significance.

Adjust survey results

Total number of people n=100; hypothesized proportions under H₀: 50.0%, 30.0%, 20.0%.