Overview

Use a contingency table to test whether two or more categorical variables are independent: for example, whether handedness is independent of sex. The tests examine the null hypothesis that the frequencies of one variable are independent of the other; a small P value suggests the variables are related, such as left-handedness being more common in one sex than the other.

statistiXL cross-tabulates frequencies and compares the observed counts with the counts expected if the variables were independent, showing observed, expected and observed − expected values for each cell. The help also shows how to use the tests for heterogeneity and subdivided chi-square analyses.

Two horizontal bars split into left-handed and right-handed. Of 34 boys, 18% are left-handed and 82% right-handed; of 36 girls, 33% are left-handed and 67% right-handed.
Handedness of boys and girls. If handedness and sex were independent, both bars would split at about the same point.

Methods

  • Two-way contingency tables
  • n-way (three-way and higher) contingency tables

Running the analysis

Enter the data as a cross-tab, for a table of two variables, or as a list with one column per variable and an optional frequency column, for two or more variables.

The same hair colour by sex data in two layouts. On the left, a cross-tab with rows for male and female, and columns for black, brown, blond and red hair. On the right, a list with columns for colour, sex and frequency, one row for each combination. An arrow points from a label to each layout.
The same data as a cross-tab and as a list.

Click Contingency Tables on the statistiXL ribbon and choose Two-Way or n-Way. In the dialog, select your data and the output location, and set any options.

The Contingency Tables button on the statistiXL ribbon with its menu open, listing Two-Way (highlighted) and n-Way.
The Contingency Tables menu on the statistiXL ribbon.
The Two-Way Contingency Table dialog, with an input range, a Col & Row Labels option, an output range, a summary tables option, and the QuickHelp pane on the right showing an example table of handedness by sex.
The Two-Way Contingency Table dialog, with QuickHelp on the right.

What the output includes

  • A table of observed and expected frequencies and their differences for each cell (optional)
  • Chi-square and log-likelihood ratio (G) tests, with degrees of freedom and P values
  • For 2 × 2 tables, the Yates and Cochran continuity corrections and Fisher's exact test (one- and two-tailed)
Two-way contingency table output in Excel for hair colour by sex. A frequency table lists the observed and expected counts and their differences for each combination, followed by test results for chi-square (8.987, 3 degrees of freedom, P of 0.029) and log-likelihood (9.512, P of 0.023).
Output from a two-way contingency table of hair colour by sex.