Chi squared
1. Summary and interpretation
Chi-squared (χ2) tests are powerful statistical tools used to analyze categorical data when dealing with three or more categories or assessing associations between categorical variables.
1.1 When to use a chi-squared test
Chi-squared tests are employed in various scenarios involving categorical data, categorized by the research question they address:
- Goodness-of-Fit Test: Used to determine if the observed counts of a single categorical variable fit an expected distribution or model.
- Example Question: Are four coffee brands equally preferred by consumers?
- Test of Independence: Applied to assess whether two categorical variables are related or associated within a single population.
- Example Question: Is gender associated with smoking status?
- Test of Homogeneity: Used to compare the distribution of a categorical variable across two or more distinct populations.
- Example Question: Do party preferences differ across provinces?
Example Application:
- Scenario (a): Testing if car quality is affected by the day of the week built involves comparing observed defect counts across Monday-Friday to an expected uniform distribution. This is a Goodness-of-Fit test. .
- Scenario (b): Investigating if political leaning is related to the choice of major in students involves analyzing two categorical variables within one population. This is a test of Independence. .
- Scenario (c): Comparing course choice distributions between residential and nonresidential students requires examining a categorical variable across two groups. This is a test of Homogeneity. 5.
1.2 Key assumptions and general statistic
All chi-squared (χ2) tests are subject to several critical assumptions to ensure the validity of the results:
- Data Type: The data must consist of counts, not percentages or proportions.
- Independence: Observations within the sample must be independent of each other.
- Expected Counts: The expected count for each category or cell must be at least 5. If this condition is not met, categories may need to be combined.
The general statistic for chi-squared tests is calculated as:
χ2=∑E(O−E)2
where:
- O represents the observed count in a category or cell.
- E represents the expected count in that same category or cell under the null hypothesis (H0). 6.
1.3 General interpretation of the chi-squared statistic
The core principle behind chi-squared tests is to compare the observed frequencies of data with the frequencies that would be expected if the null hypothesis were true.
- Large Differences: If the differences between the observed (O) and expected (E) counts are substantial, it suggests that the observed data are unlikely to have occurred by random chance under the null hypothesis.
- Chi-Squared Distribution: When the null hypothesis (H0) is true and the sample size is sufficiently large, the calculated χ2 statistic approximately follows a chi-squared distribution with a specific number of degrees of freedom (df). .
Tip: The magnitude of the χ2 statistic should be interpreted in the context of the degrees of freedom. A larger χ2 value, relative to its degrees of freedom, provides stronger evidence against the null hypothesis. 7.
2. Goodness-of-fit test en Test of independence
This section details two types of chi-squared tests: the goodness-of-fit test, used to assess if observed data fits a theoretical distribution, and the test of independence, used to determine if two categorical variables are related within a single population.
2.1 Goodness-of-fit chi-squared test
The goodness-of-fit chi-squared test is employed to determine whether an observed frequency distribution differs significantly from an expected theoretical distribution. This test is particularly useful when dealing with a single categorical variable.
2.1.1 Application and hypothesis formulation
The primary goal is to assess if the observed counts in different categories align with what would be expected under a specific hypothesis about the population proportions.
- Null Hypothesis (H0): The observed data fits the specified theoretical distribution (e.g., all categories are equally likely). For a fair die, H0:p1=p2=⋯=p6=1/6.
- Alternative Hypothesis (HA): The observed data does not fit the specified theoretical distribution (i.e., at least one proportion is different). For a fair die, HA: Not all probabilities are 1/6.
2.1.2 Calculating expected counts
Under the assumption of the null hypothesis, the expected count for each category is calculated by multiplying the total number of observations (n) by the hypothesized probability for that category.
Ei=n×pi
Where:
- Ei is the expected count for category i.
- n is the total number of observations.
- pi is the hypothesized proportion for category i under H0.
Example: If a die is rolled 600 times and we hypothesize it's fair (pi=1/6 for each face), the expected count for each face is 600×(1/6)=100.
2.1.3 Computing the chi-squared statistic
The chi-squared (χ2) statistic quantifies the discrepancy between the observed and expected counts. It is calculated as the sum of the squared differences between observed (Oi) and expected (Ei) counts, divided by the expected count for each category.
χ2=∑i=1kEi(Oi−Ei)2
Where:
- k is the number of categories.
- Oi is the observed count for category i.
- Ei is the expected count for category i.
Example: For a die rolled 600 times with observed counts and expected counts of 100 for each face, the χ2 statistic would involve summing terms like (89−100)2/100, (113−100)2/100, etc., for all six faces 10.
2.1.4 Decision-making process
The decision to reject or fail to reject the null hypothesis is based on comparing the calculated χ2 statistic to a critical value from the chi-squared distribution or by examining the p-value.
-
Degrees of Freedom (df): For a goodness-of-fit test, the degrees of freedom are calculated as the number of categories minus one (k−1). This represents the number of categories whose frequencies can vary independently once the total count is known. df=k−1 For a fair die example with 6 faces, df=6−1=5.
-
P-value: The p-value is the probability of observing a χ2 statistic as extreme as, or more extreme than, the one calculated, assuming H0 is true. A smaller p-value (typically less than a chosen significance level, α, such as 0.05) indicates stronger evidence against H0.
-
Conclusion: If the p-value is less than α, reject H0. If the p-value is greater than or equal to α, fail to reject H0.
Example: If the calculated χ2 is 10.40 with df=5, the p-value might be around 0.064. If the significance level α is 0.05, since 0.064≥0.05, we fail to reject H0. The data do not provide strong evidence that the die is unfair 11.
Remember: Degrees of freedom (df) represent the number of independent pieces of information available to estimate variation. For goodness-of-fit, df=k−1, where k is the number of categories.
2.2 Test of independence
The test of independence is used to determine whether there is a statistically significant association between two categorical variables within a single population. It assesses if the distribution of one variable is independent of the distribution of the other.
2.2.1 Hypothesis formulation
- Null Hypothesis (H0): The two categorical variables are independent.
- Alternative Hypothesis (HA): The two categorical variables are associated (dependent).
2.2.2 Calculating expected counts
For a contingency table with r rows and c columns, the expected count for a cell in row i and column j (Eij) is calculated assuming independence between the row and column variables.
Eij=n(Row i total)×(Column j total)
Where:
- Eij is the expected count for the cell in row i and column j.
- n is the total number of observations in the contingency table.
Example: In a 2x2 table, for a Male-Smoker cell with a row total of 150, a column total of 120, and a grand total of 250, the expected count is (150×120)/250=72 17.
2.2.3 Computing the chi-squared statistic
Similar to the goodness-of-fit test, the chi-squared statistic for the test of independence is the sum of the squared differences between observed (Oij) and expected (Eij) counts, divided by the expected count for each cell.
χ2=∑i∑jEij(Oij−Eij)2
Example: For a 2x2 table, the χ2 statistic would sum terms like (90−72)2/72, (60−78)2/78, (30−48)2/48, and (70−52)2/52.
2.2.4 Degrees of freedom and decision-making
-
Degrees of Freedom (df): For a contingency table with r rows and c columns, the degrees of freedom are calculated as: df=(r−1)(c−1) This formula reflects that once row and column totals are fixed, only (r−1)(c−1) cells can vary independently For a 2x2 table, df=(2−1)(2−1)=1 12 14.
-
P-value and Conclusion: The calculated χ2 statistic is compared to the chi-squared distribution with the appropriate degrees of freedom to obtain a p-value. If the p-value is less than the significance level (α), the null hypothesis of independence is rejected, indicating a significant association between the two variables.
Example: For a 2x2 table, if the calculated χ2 is 21.63 with df=1, the p-value is less than 0.001. Since p<0.001, we reject H0. There is strong evidence of an association between gender and smoking status in this sample 18.
Important: The degrees of freedom are crucial for determining the correct chi-squared distribution to use for calculating critical values and p-values 13.
3. Test of homogeneity
The test of homogeneity is used to determine if the distribution of a categorical variable is consistent across multiple independent populations.
3.1 Purpose and application
The test of homogeneity addresses the question of whether the proportions of a categorical variable are the same in several different populations. This is distinct from the test of independence, which examines the relationship between two categorical variables within a single population. In essence, the homogeneity test compares the distributions of the same categorical variable across different groups or strata.
Example: We want to know if the proportion of voters preferring different political parties is the same in Alberta, Ontario, and Quebec. Here, "party preference" is the categorical variable, and "province" defines the populations being compared.
3.2 Hypotheses
The formal hypotheses for a test of homogeneity are:
- Null Hypothesis (H0): The distribution of the categorical variable is the same across all populations.
- Alternative Hypothesis (HA): At least one population has a different distribution of the categorical variable.
3.3 Calculating expected counts
To perform the test, we first need to calculate the expected counts for each cell in the contingency table under the assumption that the null hypothesis is true. The formula for the expected count in a cell, representing the intersection of a specific row (population) and column (category), is:
Eij=Grand TotalRow Totali×Column Totalj
where:
- Eij is the expected count for cell (i,j).
- Row Totali is the total for row i (the total for population i).
- Column Totalj is the total for column j (the total for category j).
- Grand Total is the total number of observations across all populations and categories.
Example Calculation (Alberta, Liberal): Given a total sample size of 300 voters, with 100 from Alberta, 140 total liberal preferences, and 45 observed liberal preferences in Alberta: EAlberta, Liberal=300100×140≈46.67
3.4 The Chi-squared statistic
The test statistic used is the chi-squared (χ2) statistic, which quantifies the discrepancy between the observed counts (Oij) and the expected counts (Eij) in each cell. The formula is:
χ2=∑all cellsEij(Oij−Eij)2
The sum is taken over all cells in the contingency table. A larger χ2 value indicates a greater difference between the observed data and what would be expected if the null hypothesis were true.
Calculation Steps: For each cell in the table, calculate Eij(Oij−Eij)2. Then, sum these values across all cells to obtain the total χ2 statistic.
3.5 Degrees of freedom
The degrees of freedom (df) for a test of homogeneity are calculated based on the dimensions of the contingency table. If there are r rows (populations) and c columns (categories), the degrees of freedom are:
df=(r−1)(c−1)
These degrees of freedom are used to determine the appropriate critical value from the chi-squared distribution or to find the p-value associated with the calculated χ2 statistic.
3.6 Decision and conclusion
After calculating the χ2 statistic and degrees of freedom, we compare the χ2 value to a critical value from the χ2 distribution at a chosen significance level (e.g., α=0.05), or we determine the p-value.
- If the p-value is less than α (or if χ2 exceeds the critical value): We reject the null hypothesis (H0). This suggests that there is statistically significant evidence that the distributions of the categorical variable differ across the populations.
- If the p-value is greater than or equal to α (or if χ2 does not exceed the critical value): We fail to reject the null hypothesis (H0). This indicates that the data do not provide sufficient evidence to conclude that the distributions differ across the populations.
Interpretation Tip: A large χ2 value, relative to the degrees of freedom, implies that the observed counts are considerably different from the expected counts, leading to a small p-value and providing evidence against H0.
Example Conclusion: If the calculated χ2 is approximately 7.02 with 4 degrees of freedom, yielding a p-value of approximately 0.13. Since 0.13 is greater than the typical significance level of 0.05, we fail to reject H0. The data do not provide strong evidence that party preferences differ across the provinces.
3.7 Summary of chi-squared tests
| Test | Use Case | Degrees of Freedom |
|---|---|---|
| Goodness-of-Fit | One categorical variable compared against an expected model proportions. | k−1 |
| Independence | Relationship between two categorical variables within one population. | (r−1)(c−1) |
| Homogeneity | Same categorical variable across multiple populations. | (r−1)(c−1) |
Common mistakes to avoid
- Review all topics thoroughly before exams
- Pay attention to formulas and key definitions
- Practice with examples provided in each section
- Don't memorize without understanding the underlying concepts
© 2026 Maeve. All rights reserved. This content is protected by copyright.