Chi-squared test for the relationship between two categorical variables
This page offers all the basic information you need about the chi-squared test for the relationship between two categorical variables. It is part of Statkat’s wiki module, containing similarly structured info pages for many different statistical methods. The info pages give information about null and alternative hypotheses, assumptions, test statistics and confidence intervals, how to find p values, SPSS how-to’s and more.
To compare the chi-squared test for the relationship between two categorical variables with other statistical methods, go to Statkat's or practice with the chi-squared test for the relationship between two categorical variables at Statkat's
Contents
- 1. When to use
- 2. Null hypothesis
- 3. Alternative hypothesis
- 4. Assumptions
- 5. Test statistic
- 6. Sampling distribution
- 7. Significant?
- 8. Example context
- 9. SPSS
- 10. Jamovi
When to use?
Deciding which statistical method to use to analyze your data can be a challenging task. Whether a statistical method is appropriate for your data is partly determined by the measurement level of your variables. The chi-squared test for the relationship between two categorical variables requires the following variable types:
Independent /column variable: One categorical with $I$ independent groups ($I \geqslant 2$) | Dependent /row variable: One categorical with $J$ independent groups ($J \geqslant 2$) |
Note that theoretically, it is always possible to 'downgrade' the measurement level of a variable. For instance, a test that can be performed on a variable of ordinal measurement level can also be performed on a variable of interval measurement level, in which case the interval variable is downgraded to an ordinal variable. However, downgrading the measurement level of variables is generally a bad idea since it means you are throwing away important information in your data (an exception is the downgrade from ratio to interval level, which is generally irrelevant in data analysis).
If you are not sure which method you should use, you might like the assistance of our method selection tool or our method selection table.
Null hypothesis
The chi-squared test for the relationship between two categorical variables tests the following null hypothesis (H_{0}):
H_{0}: there is no association between the row and column variableMore precisely, if there are $I$ independent random samples of size $n_i$ from each of $I$ populations, defined by the independent variable:
- H_{0}: the distribution of the dependent variable is the same in each of the $I$ populations
- H_{0}: the row and column variables are independent
Alternative hypothesis
The chi-squared test for the relationship between two categorical variables tests the above null hypothesis against the following alternative hypothesis (H_{1} or H_{a}):
H_{1}: there is an association between the row and column variableMore precisely, if there are $I$ independent random samples of size $n_i$ from each of $I$ populations, defined by the independent variable:
- H_{1}: the distribution of the dependent variable is not the same in all of the $I$ populations
- H_{1}: the row and column variables are dependent
Assumptions
Statistical tests always make assumptions about the sampling procedure that's been used to obtain the sample data. So called parametric tests also make assumptions about how data are distributed in the population. Non-parametric tests are more 'robust' and make no or less strict assumptions about population distributions, but are generally less powerful. Violation of assumptions may render the outcome of statistical tests useless, although violation of some assumptions (e.g. independence assumptions) are generally more problematic than violation of other assumptions (e.g. normality assumptions in combination with large samples).
The chi-squared test for the relationship between two categorical variables makes the following assumptions:
- Sample size is large enough for $X^2$ to be approximately chi-squared distributed under the null hypothesis. Rule of thumb:
- 2 $\times$ 2 table: all four expected cell counts are 5 or more
- Larger than 2 $\times$ 2 tables: average of the expected cell counts is 5 or more, smallest expected cell count is 1 or more
- There are $I$ independent simple random samples from each of $I$ populations defined by the independent variable, or there is one simple random sample from the total population
Test statistic
The chi-squared test for the relationship between two categorical variables is based on the following test statistic:
$X^2 = \sum{\frac{(\mbox{observed cell count} - \mbox{expected cell count})^2}{\mbox{expected cell count}}}$where for each cell, the expected cell count = $\dfrac{\mbox{row total} \times \mbox{column total}}{\mbox{total sample size}}$, the observed cell count is the observed sample count in that same cell, and the sum is over all $I \times J$ cells
Sampling distribution
Sampling distribution of $X^2$ if H_{0} were true:Approximately the chi-squared distribution with $(I - 1) \times (J - 1)$ degrees of freedom
Significant?
This is how you find out if your test result is significant:
- Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
- Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
Example context
The chi-squared test for the relationship between two categorical variables could for instance be used to answer the question:
Is there an association between economic class and gender? Is the distribution of economic class different between men and women?SPSS
How to perform the chi-squared test for the relationship between two categorical variables in SPSS:
Analyze > Descriptive Statistics > Crosstabs...- Put one of your two categorical variables in the box below Row(s), and the other categorical variable in the box below Column(s)
- Click the Statistics... button, and click on the square in front of Chi-square
- Continue and click OK
Jamovi
How to perform the chi-squared test for the relationship between two categorical variables in jamovi:
Frequencies > Independent Samples - $\chi^2$ test of association- Put one of your two categorical variables in the box below Rows, and the other categorical variable in the box below Columns