Welcome to the $\chi^2$-test: Becoming a Data Detective!

Welcome to one of the most practical and fascinating chapters in Further Statistics! The Chi-squared test (or $\chi^2$-test) is your tool for determining if the data you observe in the real world matches what you would expect theoretically, or if two characteristics (like gender and favourite sport) are related.
Don't worry if this seems tricky at first. It breaks down into clear, logical steps. By the end of this chapter, you will be able to perform statistical tests to decide if your assumptions about data are reasonable!

The $\chi^2$-test falls into two main categories in this syllabus:
1. Goodness of Fit (GOF): Does a theoretical distribution (like Poisson or Binomial) accurately describe the observed data?
2. Test for Independence: Are two categorical variables related, or are they independent? (This uses a Contingency Table).

1. The Foundation: The $\chi^2$ Test Statistic

1.1 What is the $\chi^2$ statistic?

The $\chi^2$ test statistic is a single number that measures the difference between your Observed Frequencies (\(O\)) and your Expected Frequencies (\(E\)).

Analogy: Imagine you expected 50 people to wear red and 50 to wear blue. If you observed 60 red and 40 blue, the $\chi^2$ statistic quantifies how 'bad' that 10/10 difference is.

1.2 The Formula

The calculation involves summing up the squared differences between observed and expected frequencies, divided by the expected frequencies, for every category or cell:

$$ \chi^2 = \sum \frac{(O_i - E_i)^2}{E_i} $$

  • \(\chi^2\): The calculated Chi-squared statistic.
  • \(O_i\): The Observed Frequency in category $i$ (the actual count from your experiment).
  • \(E_i\): The Expected Frequency in category $i$ (what you would expect based on $H_0$).

Key Takeaway:
The bigger the $\chi^2$ value, the greater the discrepancy between what you observed and what you expected. This means the evidence against your null hypothesis (\(H_0\)) is stronger.

2. The Goodness of Fit (GOF) Test

The GOF test checks if a set of observed data follows a hypothesised theoretical distribution (like Uniform, Binomial, or Poisson).

2.1 Step-by-Step GOF Procedure

Step 1: State the Hypotheses

The $\chi^2$-test is always a one-tailed test (since larger values mean greater disagreement).

  • Null Hypothesis (\(H_0\)): The data fits the specified distribution. (e.g., $H_0$: The data follows a Poisson distribution.)
  • Alternative Hypothesis (\(H_1\)): The data does not fit the specified distribution. (e.g., $H_1$: The data does not follow a Poisson distribution.)
Step 2: Calculate the Expected Frequencies (\(E_i\))

Based entirely on \(H_0\), you must calculate the expected count for each category.

Example: If \(H_0\) states the data is Uniform across 5 categories with a total of 100 observations, then \(E_i = 100 / 5 = 20\) for each category.

If fitting Poisson/Binomial: You use the theoretical probability $P(X=x)$ derived from the distribution specified in $H_0$. Then, \(E_i = N \times P(X=x)\), where $N$ is the total number of observations.

Step 3: Check the Expected Frequency Rule (The Golden Rule)

Crucial Requirement: For the $\chi^2$ test to be valid, every expected frequency \((E_i)\) must be at least 5.

If you find an expected frequency less than 5, you must combine that class (and its corresponding observed frequency) with the adjacent class. This is usually done at the tails of the distribution (the very small or very large categories).

Did you know? This rule exists because the mathematics behind the $\chi^2$ test relies on an approximation which breaks down if the expected counts are too low.
Step 4: Calculate the Test Statistic $\(\chi^2\)$

Use the formula with the *newly combined* categories if necessary.

$$ \chi^2 = \sum \frac{(O_i - E_i)^2}{E_i} $$

Step 5: Determine the Degrees of Freedom (\(\nu\))

This is often the trickiest part for GOF tests. The degrees of freedom $\nu$ tell you how many categories are "free to vary" once constraints are applied.

$$ \nu = (\text{Number of final categories}) - 1 - (\text{Number of parameters estimated}) $$

  • Subtract 1 because the total frequency (\(N\)) is fixed, constraining the last category.
  • If you had to estimate a parameter (like \(\lambda\) for Poisson, or $p$ for Binomial) from the data itself to calculate $E_i$, you must subtract 1 for each parameter estimated.

Example:

  • If testing for Uniform distribution (no parameters estimated): $\nu = (\text{categories}) - 1$.
  • If testing for Poisson distribution, and you estimated the mean $\lambda$ from the data: $\nu = (\text{categories}) - 1 - 1$.
  • If testing for Normal distribution, and you estimated the mean $\mu$ and variance $\sigma^2$ from the data: $\nu = (\text{categories}) - 1 - 2$.

Quick Review: Degrees of Freedom in GOF

Mnemonic: Think C minus C minus P.
\(\nu = \mathbf{C}\)ategories (final number) - \(\mathbf{C}\)onstraint (always 1) - \(\mathbf{P}\)arameters estimated.

3. Test for Independence (Contingency Tables)

The Test for Independence is used when you have two categorical variables, and you want to know if knowing the value of one variable helps you predict the value of the other. The data is usually presented in a rectangular table called a Contingency Table.

3.1 Step-by-Step Independence Procedure

Step 1: State the Hypotheses

This test examines the relationship between two variables, A and B.

  • Null Hypothesis (\(H_0\)): The two variables are independent (there is no association).
  • Alternative Hypothesis (\(H_1\)): The two variables are not independent (there is an association/relationship).

Example: H0: Gender and preferred type of transport are independent.

Step 2: Calculate Expected Frequencies for Each Cell

If two events A and B are independent, \(P(A \cap B) = P(A) \times P(B)\). We use this logic for frequencies.

The expected frequency (\(E\)) for any cell in the table is calculated using the marginal totals:

$$ E = \frac{(\text{Row Total}) \times (\text{Column Total})}{\text{Grand Total}} $$

Check the Expected Frequency Rule again: Just like in GOF, every expected frequency (\(E_i\)) in every cell must be at least 5. If any cell has \(E_i < 5\), you must combine appropriate rows or columns until the constraint is met.

Step 3: Calculate the Test Statistic $\(\chi^2\)$

You calculate the $\chi^2$ statistic exactly as before, summing over all the final cells in your contingency table.

$$ \chi^2 = \sum \frac{(O_i - E_i)^2}{E_i} $$

Step 4: Determine the Degrees of Freedom (\(\nu\))

In a contingency table with $r$ rows and $c$ columns, the degrees of freedom are simple:

$$ \nu = (r-1)(c-1) $$

Where $r$ and $c$ are the final number of rows and columns after any necessary combining has occurred to satisfy the \(E_i \ge 5\) rule.

Example: If you have a 3x4 table (3 rows, 4 columns): \(\nu = (3-1)(4-1) = 2 \times 3 = 6\).

Key Takeaway:
The degrees of freedom for independence tests are found by multiplying one less than the number of rows by one less than the number of columns: \((r-1)(c-1)\).

4. Making the Decision (Interpretation)

Once you have your calculated $\chi^2$ statistic and your degrees of freedom \(\nu\), you look up the critical value in the Critical Values for the $\chi^2$-distribution table (in MF19).

4.1 The Critical Value and Significance Level

You compare your calculated $\chi^2$ value with the critical value $k$ at your chosen significance level ($\alpha$) and your specific degrees of freedom \(\nu\). Remember, since we are only interested in large discrepancies, the $\chi^2$-test is always one-tailed.

For example, if testing at the 5% significance level, you look up the column \(p=0.95\) in the table.

4.2 The Rejection Rule

The $\chi^2$ distribution is heavily skewed to the right, and the rejection region is always in the right tail.

  • If Calculated \(\chi^2\) $\le$ Critical Value: We Do Not Reject \(H_0\).
    Conclusion: There is not enough evidence to suggest the data doesn't fit the model (GOF) or that the variables are associated (Independence).
  • If Calculated \(\chi^2\) $>$ Critical Value: We Reject \(H_0\).
    Conclusion: There is sufficient evidence at the $\alpha\%$ level to conclude that the data does not fit the proposed distribution, or that the variables are not independent.

Did you know? The term 'Chi-squared' comes from the Greek letter $\chi$. The $\chi^2$ distribution is itself a continuous probability distribution, though it is used here to approximate the discrete frequencies of our test data.

4.3 Common Mistakes to Avoid

  • Forgetting the \(\nu\) constraints: Always check if you need to subtract parameters estimated (GOF) or if you've used the wrong $r$ and $c$ (Independence).
  • Failing the Golden Rule: Ignoring the requirement that Expected Frequencies (\(E_i\)) must be $\ge 5$ will invalidate your test. Combine categories until this criterion is met.
  • Comparing O and E too early: The test statistic is calculated using the *frequencies* ($O$ and $E$), not the *probabilities*. Make sure all your expected values are counts first.

Chapter Summary: $\chi^2$ Essentials

The Formula (Always the same):

$$ \chi^2 = \sum \frac{(O - E)^2}{E} $$

The Golden Rule (Always check):

Expected frequencies \(E\) must be $\ge 5$. If not, combine classes/cells.

Degrees of Freedom (\(\nu\)):
  • GOF: \(\nu = (\text{Categories}) - 1 - (\text{Parameters Estimated})\)
  • Independence: \(\nu = (r-1)(c-1)\) (Rows $r$, Columns $c$)
The Decision:

If Calculated $\chi^2$ $>$ Critical Value, you reject \(H_0\). Your observed data is too far from what was expected.