Chi-squared test for the relationship between two categorical variables - overview

This page offers structured overviews of one or more selected methods. Add additional methods for comparisons by clicking on the dropdown button in the right-hand column. To practice with a specific method click the button at the bottom row of the table

Chi-squared test for the relationship between two categorical variables

$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

$z = \dfrac{p - \pi_0}{\sqrt{\dfrac{\pi_0(1 - \pi_0)}{N}}}$
$p$ is the sample proportion of successes: $\dfrac{X}{N}$, $N$ is the sample size, and $\pi_0$ is the population proportion of successes according to the null hypothesis.

When $N$ is large, the $p$ value from the $z$ test for a single proportion approaches the $p$ value from the binomial test for a single proportion. The $z$ test for a single proportion is just a large sample approximation of the binomial test for a single proportion.

Example context

Example context

Is there an association between economic class and gender? Is the distribution of economic class different between men and women?

Is the proportion of smokers amongst office workers different from $\pi_0 = .2$? Use the normal approximation for the sampling distribution of the test statistic.

SPSS

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

Analyze > Nonparametric Tests > Legacy Dialogs > Binomial...

Put your dichotomous variable in the box below Test Variable List

Fill in the value for $\pi_0$ in the box next to Test Proportion

If computation time allows, SPSS will give you the exact $p$ value based on the binomial distribution, rather than the approximate $p$ value based on the normal distribution

Jamovi

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

Frequencies > 2 Outcomes - Binomial test

Put your dichotomous variable in the white box at the right

Fill in the value for $\pi_0$ in the box next to Test value

Under Hypothesis, select your alternative hypothesis

Jamovi will give you the exact $p$ value based on the binomial distribution, rather than the approximate $p$ value based on the normal distribution