Correspondence analysis: map a contingency table, with example
Correspondence analysis turns a two-way table of counts, such as defect type by production line or complaint type by product, into a low-dimensional map. Rows and columns that are associated, meaning they occur together more often than independence would predict, plot close to each other. It is the picture behind a chi-square test: the test says whether there is an association, and correspondence analysis shows where it is.
When to use it
- You have a table of counts with several rows and columns, and a chi-square test says rows and columns are related.
- You want to see which defect types go with which lines, shifts, suppliers or molds.
- The table is too big to read cell by cell, for example 10 defect codes by 8 machines.
- You want to present the association to people who will not read standardized residuals.
How it works
Start with a table N of counts, with grand total n.
- Profiles and masses. Each row's counts divided by its total form its profile; the row total divided by n is its mass. The same goes for columns.
- Distance from independence. Under independence every row profile would equal the average profile. The chi-square statistic measures the total departure, and the total inertia is that statistic scaled by the sample size:
Total inertia = χ² / n- Decompose. A singular value decomposition of the matrix of standardized residuals, (pᵢⱼ − rᵢcⱼ)/√(rᵢcⱼ), where p = N/n and r and c are the row and column masses, splits the inertia into dimensions. Each dimension's inertia is its squared singular value, and its share of the total says how much of the association it shows.
- Coordinates. Each row and column gets coordinates on each dimension. In the common symmetric map, both use principal coordinates. Rows near each other have similar profiles; a row and a column on the same side of the origin and far from it are positively associated.
Most tables need two dimensions; you read the plot of dimension 1 against dimension 2.
Example
A die-casting plant records the main defect on every rejected housing from four casting cells during a month:
| Defect | Cell A | Cell B | Cell C | Cell D | Total |
|---|---|---|---|---|---|
| Scratch | 42 | 38 | 15 | 20 | 115 |
| Dent | 18 | 22 | 30 | 12 | 82 |
| Porosity | 25 | 12 | 10 | 41 | 88 |
| Crack | 8 | 9 | 24 | 6 | 47 |
| Burr | 14 | 16 | 12 | 15 | 57 |
| Total | 107 | 97 | 91 | 94 | 389 |
The chi-square test of independence gives χ² = 73.46 with 12 degrees of freedom, p < 0.001, so the defect mix differs between cells. Total inertia is 73.46 / 389 = 0.1888.
| Dimension | Inertia | Share | Cumulative |
|---|---|---|---|
| 1 | 0.1284 | 68.0% | 68.0% |
| 2 | 0.0583 | 30.9% | 98.9% |
| 3 | 0.0021 | 1.1% | 100% |
Two dimensions show 98.9% of the association. The principal coordinates:
| Row | Dim 1 | Dim 2 | Column | Dim 1 | Dim 2 | |
|---|---|---|---|---|---|---|
| Scratch | −0.095 | 0.333 | Cell A | −0.153 | 0.180 | |
| Dent | 0.351 | −0.029 | Cell B | 0.083 | 0.278 | |
| Porosity | −0.496 | −0.274 | Cell C | 0.554 | −0.219 | |
| Crack | 0.602 | −0.264 | Cell D | −0.447 | −0.280 | |
| Burr | −0.043 | 0.011 |
Reading the map:
- Dimension 1 runs from Cell D and porosity (negative) to Cell C, cracks and dents (positive). Porosity and cracks together make up about 78% of this dimension's inertia.
- Dimension 2 separates scratches, with Cells A and B (positive), from porosity and cracks (negative).
- Burr sits near the origin: burrs are spread across the cells in proportion to their totals, so there is nothing cell-specific about them.
The standardized residuals of the chi-square test confirm the strongest cells: porosity in Cell D (+4.28; 41 observed against 21.3 expected) and cracks in Cell C (+3.92; 24 against 11.0). The plant now has two separate investigations: gas or venting in Cell D, and die temperature or ejection in Cell C, plus a handling question for scratches in Cells A and B.
How to read the results
- Check the inertia shares first. If the first two dimensions show most of the inertia, the two-dimensional map is a faithful picture.
- Read directions from the origin. A row and a column far from the origin in the same direction are associated; opposite directions mean they avoid each other.
- Do not read row-to-column distances literally. In the symmetric map, distances between two rows or between two columns are meaningful; a row-to-column distance is only an approximate guide.
- Use contributions to see what drives each dimension. A point with a large contribution shapes the axis; a point near the origin with a small mass contributes little.
Common mistakes
- Running it on tiny tables. For a 2 × 2 table, a chi-square test and the four proportions say everything.
- Ignoring small counts. Rows or columns with very few counts can land far from the origin by chance; merge them or treat them as supplementary points.
- Reading points near the origin as "similar". Near the origin means close to the average profile, not necessarily similar to each other in any interesting way.
- Forgetting the counts. The map shows profiles, not volumes. Scratches are the largest category, which the map does not show; pair it with a Pareto chart.
Frequently asked questions
How is correspondence analysis related to the chi-square test?
Total inertia is the chi-square statistic divided by n, and the map decomposes that statistic into dimensions. A significant chi-square test is a good reason to draw the map.
What is inertia?
The weighted spread of the row (or column) profiles around their average, measured with chi-square distances. Zero inertia means every row has the same profile.
Can I analyze more than two categorical variables?
Yes, with multiple correspondence analysis, which works on a table of all category combinations. It is often used for survey answers.
What does the mass of a point mean?
Its share of the total count. Points with large masses pull the axes toward them; points with small masses can sit far out with little influence.