4. Statistics and Probability

Chi-squared Testing

Chi-Squared Testing 📊

students, imagine a school wants to know whether the distribution of club memberships matches what it expected, or whether two features in a survey are connected. Chi-squared testing gives a structured way to check those ideas using data instead of guesswork. In this lesson, you will learn how chi-squared tests work, what the important terms mean, and how to interpret results in a real-world setting. The main goals are to understand the logic of the test, apply the correct procedure, and connect the method to broader statistical reasoning in IB Mathematics: Applications and Interpretation HL.

By the end of this lesson, you should be able to:

  • Explain the ideas behind chi-squared testing, including observed and expected values.
  • Use chi-squared methods to compare data with a model or to test whether two variables are related.
  • Interpret conclusions in context, not just in symbols.
  • Recognize when chi-squared testing fits into statistics and probability.

What Chi-Squared Testing Is

Chi-squared testing is a family of hypothesis tests that compares what was observed in data with what would be expected if a claim were true. The key idea is simple: if the observed data are very close to the expected data, the claim may be believable. If the differences are large, the claim may not fit the data well. ✅

There are two common chi-squared tests in the IB context:

  1. Chi-squared goodness-of-fit test: used to test whether one categorical variable follows a proposed distribution.
  2. Chi-squared test of independence: used to test whether two categorical variables are associated.

Both tests use the same general statistic:

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

Here, $O$ represents the observed frequency in a category, and $E$ represents the expected frequency if the null hypothesis is true. The larger the differences between $O$ and $E$, the larger the value of $\chi^2$ tends to be.

A chi-squared test does not tell you that something is “proven.” Instead, it gives evidence for or against a claim. That is an important part of statistical reasoning: we make decisions using data, but we still allow for uncertainty.

Key Terms and Ideas

To use chi-squared testing correctly, students, you need to know the language of the test.

Observed frequency: the actual number counted in the sample.

Expected frequency: the number predicted by the null hypothesis.

Null hypothesis: a starting claim that usually says there is no effect, no difference, or no association.

Alternative hypothesis: the competing claim that there is some difference, effect, or association.

Degrees of freedom: a value used to find the correct chi-squared distribution. For a goodness-of-fit test with $k$ categories, the degrees of freedom are $k-1$ if no parameters are estimated from the data. For a contingency table with $r$ rows and $c$ columns, the degrees of freedom are $(r-1)(c-1)$.

Significance level: often written as $\alpha$, such as $0.05$. This is the cutoff chosen before the test for deciding when evidence is strong enough to reject the null hypothesis.

P-value: the probability, assuming the null hypothesis is true, of getting a test statistic at least as extreme as the one calculated from the sample.

These terms work together. The null hypothesis gives a model, the expected frequencies come from that model, the chi-squared statistic measures how far the data are from the model, and the p-value helps decide whether the difference is small enough to be explained by random variation.

Chi-Squared Goodness-of-Fit Test

A goodness-of-fit test checks whether one categorical variable follows a claimed distribution. For example, a teacher may want to know whether students choose between four lunch options equally often, or whether a spinner labeled with different colors is fair.

Suppose a spinner is spun $100$ times and the results are recorded in four categories. If the spinner is fair, each category should be expected about $25$ times. The expected frequencies are found from the claimed probabilities:

$$E=np$$

where $n$ is the total number of trials and $p$ is the probability for a category.

If one color appears $40$ times instead of $25$, that difference contributes strongly to the chi-squared statistic:

$$\frac{(40-25)^2}{25}=9$$

That is quite a large contribution, so the result may provide evidence that the spinner is not fair.

A goodness-of-fit test usually follows these steps:

  1. State $H_0$ and $H_1$.
  2. Find expected frequencies.
  3. Calculate the test statistic $\chi^2$.
  4. Find the degrees of freedom.
  5. Use a chi-squared table or technology to find the p-value.
  6. Compare the p-value with $\alpha$.
  7. Write a conclusion in context.

Important note: expected frequencies should generally be large enough for the chi-squared approximation to be reasonable. In IB-style problems, the expected counts are usually all at least $5$.

Chi-Squared Test of Independence

The test of independence asks whether two categorical variables are related. For example, are coffee preference and gender independent in a survey? Are exercise habit and grade level related? This is useful in social science, market research, and health studies. 📋

Data are often arranged in a contingency table. For each cell, the expected frequency is found using:

$$E=\frac{(\text{row total})(\text{column total})}{\text{grand total}}$$

This formula comes from the assumption that the variables are independent. If the variables are independent, the proportion in a row should not change across columns.

For example, suppose a school surveys students about whether they prefer online or printed notes and whether they are in Year 1 or Year 2. If the variables are independent, the expected number of Year 1 students who prefer online notes is found by multiplying the Year 1 total by the online total and dividing by the overall total. Then the chi-squared formula compares every observed cell to its expected value.

A large chi-squared statistic suggests that the pattern in the table is not what independence would predict. A small value suggests the observed counts are close to what independence would give.

The hypotheses are usually written as:

$$H_0: \text{the variables are independent}$$

$$H_1: \text{the variables are associated}$$

In context, that means the pattern in one variable seems to depend on the other.

Interpreting Results and Making Decisions

Chi-squared testing is not only about calculating a number. The final interpretation matters just as much. students, after finding the p-value, you compare it with $\alpha$.

  • If $p\leq \alpha$, reject $H_0$.
  • If $p>\alpha$, fail to reject $H_0$.

“Fail to reject” is not the same as “prove true.” It means the sample does not provide enough evidence against the null hypothesis.

For example, if a chi-squared test of independence gives $p=0.012$ and the significance level is $\alpha=0.05$, then $p<\alpha$. You would reject $H_0$ and conclude that there is evidence of an association between the variables.

A good conclusion must always mention the context. Instead of saying, “Reject the null hypothesis,” write something like, “There is sufficient evidence at the $5\%$ significance level to suggest that study method and exam result are associated.” This makes the statistics meaningful in the real world.

Also remember that statistical significance does not automatically mean practical importance. A very large sample can make small differences look significant. So real-world decision-making should consider both the p-value and the situation itself.

Common Mistakes and How to Avoid Them

A frequent error is mixing up the hypotheses. For goodness-of-fit, $H_0$ says the data follow the claimed distribution. For independence, $H_0$ says the variables are independent. Keeping that distinction clear avoids confusion.

Another mistake is using percentages instead of frequencies in the chi-squared calculation. The formula uses counts, not proportions. If the table gives percentages, convert them into frequencies first.

A third mistake is forgetting that expected values must be calculated correctly. Even if the observed values are correct, a wrong expected value leads to a wrong test statistic.

Students sometimes also forget to give a conclusion in context. A numerical answer alone is not enough in IB-style communication. Write a sentence that links the result to the original question.

Finally, do not confuse chi-squared testing with correlation. Correlation is used for numerical variables, while chi-squared testing is used for categorical variables. That difference is very important in statistics.

Conclusion

Chi-squared testing is a powerful tool for checking whether categorical data match a model or whether two categorical variables seem connected. It fits naturally into statistics and probability because it uses observed data, expected values, random variation, and evidence-based decisions. The method helps transform a table of counts into a statistical conclusion.

For IB Mathematics: Applications and Interpretation HL, chi-squared testing is especially important because it combines calculation, interpretation, and communication. students, when you use it well, you are not only computing $\chi^2$; you are asking whether the data support a claim in a meaningful real-world situation. That is the heart of statistical reasoning. 🌟

Study Notes

  • Chi-squared tests are used with categorical data.
  • The main statistic is $\chi^2=\sum \frac{(O-E)^2}{E}$.
  • $O$ means observed frequency and $E$ means expected frequency.
  • Goodness-of-fit tests compare data to a proposed distribution.
  • Independence tests check whether two categorical variables are related.
  • For independence, expected frequency is $E=\frac{(\text{row total})(\text{column total})}{\text{grand total}}$.
  • Degrees of freedom are $k-1$ for goodness-of-fit and $(r-1)(c-1)$ for a contingency table.
  • The null hypothesis always states the “no difference” or “no association” idea.
  • A small p-value provides evidence against $H_0$.
  • Always write the final conclusion in context, not just in symbols.
  • Chi-squared testing supports real-world decisions in surveys, experiments, and classification data.

Practice Quiz

5 questions to test your understanding