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

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:

Variable types required for the chi-squared test for the relationship between two categorical variables :
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 (H0):

H0: there is no association between the row and column variable

More precisely, if there are $I$ independent random samples of size $n_i$ from each of $I$ populations, defined by the independent variable: If there is one random sample of size $N$ from the total population:
Alternative hypothesis

The chi-squared test for the relationship between two categorical variables tests the above null hypothesis against the following alternative hypothesis (H1 or Ha):

H1: there is an association between the row and column variable

More precisely, if there are $I$ independent random samples of size $n_i$ from each of $I$ populations, defined by the independent variable: If there is one random sample of size $N$ from the total population:
Assumptions

Statistical tests always make assumptions about the sampling procedure that was 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:

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}}}$
Here 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 H0 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:

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...
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