Degrees of freedom

If we have a contingency table with dimensions r \times c, then the number of degrees of freedom (v) is:

v = (r - 1)(c - 1)

The degrees of freedom is the number of rows, minus one, all multiplied by the number of columns minus one.

How do we get this?

Let’s take this (very abstract) contingency table for example:

YesNoTotal
A102030
B152540
C51520
Total306090

We have 3 rows (A, B, C), and 2 columns (Yes, No).

What is the maximum number of cells in the main body of the table (the cells with the numbers in them, but not the totals) can we completely remove, while still being able to find them from the rest of the table?

Here’s one example of the maximum number of cells we can remove:

YesNoTotal
A1030
B1540
C20
Total306090

From just these 2 values in the main table body, we can calculate all of the other values:

YesNoTotal
A1030-1030
B1540-1540
C30-10-1560-20-2520
Total306090

Because the maximum number of cells we need to keep in order to retain all the data is 2, it means our degrees of freedom is 2.

If we instead calculated the degrees of freedom using the formula, we would do (3-1)(2-1) = 2, which matches our result from the example. So that makes sense!