# In chi square contingency table 2x2: why we sum up all four cells, but compare with chi square distribution with 1 df (only one square)? [duplicate]

I have read this and this and I understand where squared standard normal distribution comes from. I also understand why df = (r-1)(c-1). But I don't understand why I sum all fours cell (four squared standard normals) and compare this value with distribution of only one squared standard normal.

• Intuitive view: Imagine a 2×2 table. In a chi-squared test, you will have row, column, and grand totals. Given these totals, if you know the count in any one of the four cells, then you can fill in the remaining three cells with no further information. So you have 1 'degree of freedom'. // My Answer below illustrates with a simulation that the chi-squared statistic has very nearly a chi-squared distribution with one degree of freedom. Commented Oct 3, 2019 at 4:10
• Degrees of freedom are often identified with dimensions in $n$-space: The $2 \times 2$ table is a 4-dimensional object, but as the result of the conditioning on totals, the chi-squared statistic has only one dimension. Just as you have to sum the squares of two sides of a right triangle to get the length of the one-dimensional hypotenuse, you have to sum squares in four dimensions to get the one-dimensional chi-squared statistic. Commented Oct 3, 2019 at 4:30

Here is one kind of chi-squared test based on a $$2 \times 2$$ table. We have 350 women and 320 men selected at random from the population of a city. We want to know whether the probability of having a college degree is the same in the two groups.

Let $$p_w$$ and $$p_m$$ be the respective probabilities. Under the null hypothesis $$p_w = p_m.$$ Let's suppose both probabilities are $$1/5.$$

We can use binomial distributions to simulate data. Here is how to simulate data for a single chi-squared test (using parameter cor=F to avoid the Yates continuity correction, which does not exactly use a chi-squared statistic).

set.seed(310)
x = rbinom(1, 350, 1/5)
y = rbinom(1, 320, 1/5)
DTA = rbind(c(x, 350-x), c(y, 320-y))
DTA
[,1] [,2]        # 2 x 2 table
[1,]   54  296
[2,]   71  249

chisq.test(DTA, cor=F)

Pearson's Chi-squared test

data:  DTA
X-squared = 1.5776, df = 1, p-value = 0.2091


Here is now to get chi-squared statistics from 100,000 such tests:

set.seed(2019)
m = 10^5;  q = numeric(m)
for(i in 1:m) {
x = rbinom(1, 350, 1/5);  y = rbinom(1, 320, 1/5)
DTA = rbind(c(x, 350-x), c(y, 320-y))
q[i] = chisq.test(DTA, cor=F)\$stat
}
mean(q);  var(q)
[1] 0.9990056     # aprx E(Q) = 1
[1] 2.002622      # aprx Var(Q) = 2

lbl = "Simulated Chi-sq Statistics with CHISQ(1) Density"
hist(q, prob=T, br=40, col="skyblue2", main=lbl)

Under the null hypothesis that the two probabilities are equal, the chi-squared statistic $$Q$$ (X-squared in the output) has nearly the distribution $$\mathsf{Chisq}(1),$$ for which the mean is $$1$$ and the variance is $$2.$$
The figure below shows a histogram of the 100,000 simulated values of $$Q$$ along with the closely-matching density function of $$\mathsf{Chisq}(1).$$