Dulranga's Notes
Semester 3MathematicsApplied Statistics

Chi Square Tests

Chi-square tests are hypothesis tests for categorical (count) data. They compare the frequencies you observed (OO) with the frequencies you would expect (EE) if the null hypothesis were true. Your Note 5 covers two types.

All chi-square tests use the same statistic:

χcal2=∑(Oi−Ei)2Ei\chi^2_{cal} = \sum \frac{(O_i - E_i)^2}{E_i}

If observed and expected counts are close, χ2\chi^2 is small. If they differ a lot, χ2\chi^2 is large, and you reject H0H_0 when it exceeds the critical value χdf, α2\chi^2_{df,\,\alpha}.

  1. Test of Association - Check if two random variables are significantly related
  2. Goodness of Fit test - Check if the chosen sample comes from a selected distribution

1. Test of association (independence)

Use it when: you have two categorical variables from the same population and want to know whether they are related.

Hypotheses:

  • H0H_0: there is no relationship between the variables.
  • H1H_1: there is a significant relationship between them.

Expected frequency under H0H_0:

E=Row total×Column totalGrand totalE = \frac{\text{Row total} \times \text{Column total}}{\text{Grand total}}

Degrees of freedom:

df=(r−1)(c−1)df = (r-1)(c-1)

2. Goodness-of-fit test

Use it when: you want to check whether data follow a specific distribution, such as Uniform or Poisson.

Hypotheses:

  • H1H_1: the data do not follow the stated distribution.
  • H0H_0: the data follow the stated distribution.

Here EE comes from the distribution you are testing. The degrees of freedom are

df=k−1−pdf = k - 1 - p
  • kk - No. of categories after merging
  • pp - number of parameters estimated from the data like λ\lambda for poisson distribution if a parameter is not stated in H0H_0 and its estimated from data, we lose a degree of freedom

Worked example (digits, Example 1 in your notes)

From a list of 500 digits the occurrence of each distinct digit is observed. Test at 5% significance level, whether the sequence is a random sample from the Uniform distribution. chi-sq-digit-frequency.png If the 500 digits are Uniform, each digit is expected 500/10=50500/10 = 50 times.

χcal2=∑(Oi−50)250=90850=18.16\chi^2_{cal}=\sum\frac{(O_i-50)^2}{50}=\frac{908}{50}=18.16

With df=9df = 9, the critical value is χ9,5%2=16.92\chi^2_{9,5\%}=16.92. Here we do not lose DoF to mm since no parameters are derived from data that's not stated in H0H_0

Since 18.16>16.9218.16 > 16.92, reject H0H_0. The digits do not appear to be a random sample from a Uniform distribution.

Steps for any chi-square test

  1. State H0H_0 and H1H_1.
  2. Compute the expected frequencies EE.
  3. Compute χcal2=∑(O−E)2/E\chi^2_{cal}=\sum (O-E)^2/E.
  4. Find dfdf and the critical value (or the p-value).
  5. Decide: reject H0H_0 if χcal2>χcrit2\chi^2_{cal}>\chi^2_{crit}.
  6. State the conclusion in context.
Important

The test is only reliable when expected counts aren't too small. A common rule of thumb is E≥5E \ge 5 in each cell. If some cells fall below that, combine categories.

When using Calc Spread Sheets for these, precompute some of the X2\mathcal X^2 values and EE values to verify the formulas are working as expected. To reject the Null Hypothesis, we need the X2\mathcal X^2 to be higher than the one for that confidence interval

On this page