Cross Tabulation (Contingency Table)

Count the combinations of two categories, such as defect type by machine or result by shift, in a table. Row and column percentages and standardized residuals show which combinations stand out, and stacked bars and a mosaic plot compare the composition at a glance.

1Data Table

Paste a table copied from Excel into a cell (Ctrl+V). Click a column header (A, B…) before pasting to use the first line as column names. Double-click a header to rename it, right-click to insert/delete rows and columns, and formulas such as =A1*2 work too.

2Cross Tabulation Options

Data input

How to make a cross tabulation

  1. Copy two categorical columns (one observation per row), or pre-counted category and frequency columns, together with the header.
  2. Choose the data input and select the row category column and the column category column (and frequency column).
  3. Press Analyze and check the count and percentage tables and the cells with large standardized residuals.

Worked example with sample data

The sample data are the defect types (Contamination, Dent, Dimension, Scratch) of 120 defects from 3 machines (M1 to M3), one defect per row. The Machine column is the row category and the Defect type column the column category.

Mosaic plot of defect type by machine - column width is the number of defects per machine, tile height the share of each type
Mosaic plot of defect type by machine - column width is the number of defects per machine, tile height the share of each type

The most frequent combination in the observed count table is (M3, Dimension) with 19. Row percentages show that each machine has a different main defect: Scratch is 45% for M1, Contamination 41.67% for M2 and Dimension 43.18% for M3.

The standardized residuals of (M2, Contamination) 2.277 and (M3, Dimension) 2.121 exceed 2, so these two combinations occur clearly more often than expected if rows and columns were independent. (M1, Scratch) is also high at 1.732.

The very different tile heights in each machine's column of the mosaic plot tell the same story. A chi-square test of association on the same data gives χ²=19.23 (6 degrees of freedom), p=0.00379, so the defect type depends significantly on the machine.

Three ways to enter data

Two categorical columns counts raw data where each row is one observation. Row and column category columns + frequency column adds up counts that are already aggregated, and a row category column + several numeric columns uses counts already split by column (such as 'good' and 'defect') as the column categories.

Row and column categories are sorted by name.

Standardized residuals

Standardized residual = (observed - expected) / √expected, where the expected count is the value if rows and columns were independent (row total × column total / grand total). Cells with an absolute value above 2 are combinations with clearly more or fewer observations than expected.

What the result shows

Observed counts, row percentages, column percentages, total percentages and standardized residual tables, plus a stacked bar, a 100% stacked bar, a mosaic plot and a residual heatmap.

How to read a cross tabulation

  • Row percentages show the share of each column category (e.g. defect type) within each row (e.g. machine), so use them to compare rows; column percentages work the other way round.
  • A standardized residual above +2 means the combination occurs more than expected, and below -2 less than expected. These are the deep red and blue cells in the residual heatmap.
  • To check whether the two variables are statistically related, use the chi-square test of association.

Frequently asked questions

Is it the same as an Excel pivot table?

The observed count table is the same as a pivot table count. Percentages, standardized residuals and charts come with it.

What if my table is already counted?

Choose 'row and column category columns + frequency column' or 'row category column + numeric columns per column category' to use the counts as they are.

How do I read the mosaic plot?

The width is the count of each row category and the height is the share of each column category within that row. If the tile heights differ a lot between rows, the two variables are likely related.

Other chart tools