Tests whether the rows and the columns of a two-row contingency table are related. The expected count of each cell is row total × column total ÷ grand total, and χ² = Σ(observed − expected)² ÷ expected. The degrees of freedom are the number of columns − 1. Any number of columns is allowed.
A test of independence asks whether the two ways of splitting a contingency table are related: treatment against recovery, sex against opinion, region against choice.
If the rows and the columns were unrelated, every cell would hold row total × column total ÷ grand total. Call that the expected count and compare it with the observed count .
The degrees of freedom are (rows − 1) × (columns − 1). This calculator takes two rows, so they come to the number of columns − 1. Any number of columns is allowed.
In the defaults, of 50 people given a drug 30 recovered and 20 did not; of 50 given nothing, 15 recovered and 35 did not. Enter 30, 20 as row 1 and 15, 35 as row 2.
In all, 45 recovered and 55 did not, out of 100. The expected count of the first cell is , and the four expected counts are 22.5, 27.5, 22.5 and 27.5.
On 1 degree of freedom the upper-tail p-value is 0.0026, below 0.05, and exceeds the critical value 3.8415. The drug and the recovery are related.
A relationship is not a cause. The test says the two splits go together; it says nothing about which one drives the other.
With an expected count below 5 in any cell the test is unreliable, and for a two-by-two table Fisher's exact test is the usual answer. Some traditions apply Yates's continuity correction to a two-by-two table, which lowers a little.