| Treatment 1 | Treatment 2 | Control | Sum | |
|---|---|---|---|---|
| diseased | 20 | 17 | 23 | 60 |
| healthy | 30 | 25 | 15 | 70 |
| Sum | 50 | 42 | 38 | 130 |
Inference For Two Way Tables
with more than 2 levels.
| Treatment 1 | Treatment 2 | Control | Sum | |
|---|---|---|---|---|
| diseased | 20 | 17 | 23 | 60 |
| healthy | 30 | 25 | 15 | 70 |
| Sum | 50 | 42 | 38 | 130 |
Is there an association between the two variables?
\(H_0:\) There is no association
What should we use as test statistic?
How do we reduce the whole table to a single number?
| Treatment 1 | Treatment 2 | Control | Sum | |
|---|---|---|---|---|
| diseased | 20 | 17 | 23 | 60 |
| healthy | 30 | 25 | 15 | 70 |
| Sum | 50 | 42 | 38 | 130 |
Overall column rates:
How would the table look like if there really was no association?
| Treatment 1 | Treatment 2 | Control | Sum | |
|---|---|---|---|---|
| diseased | \(\frac{60}{130}\cdot 50\) 23.0769231 |
\(\frac{60}{130}\cdot 42\) 19.3846154 |
\(\frac{60}{130}\cdot 38\) 17.5384615 |
60 |
| healthy | \(\frac{70}{130}\cdot 50\) 26.9230769 |
\(\frac{70}{130}\cdot 42\) 22.6153846 |
\(\frac{70}{130}\cdot 38\) 20.4615385 |
70 |
| Sum | 50 | 42 | 38 | 130 |
Observed counts:
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | 20 | 17 | 23 |
| healthy | 30 | 25 | 15 |
Expected counts:
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | 23.07692 | 19.38462 | 17.53846 |
| healthy | 26.92308 | 22.61538 | 20.46154 |
Observed – Expected:
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | \(20 - 23.0769231\) | \(17 - 19.3846154\) | \(23 - 17.5384615\) |
| healthy | \(30 - 26.9230769\) | \(25 - 22.6153846\) | \(15 - 20.4615385\) |
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | \(-3.0769231\) | \(-2.3846154\) | \(5.4615385\) |
| healthy | \(3.0769231\) | \(2.3846154\) | \(-5.4615385\) |
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | \(\frac{(20 - 23.0769231)^2}{23.0769231}\) | \(\frac{(17 - 19.3846154)^2}{19.3846154}\) | \(\frac{(23 - 17.5384615)^2}{17.5384615}\) |
| healthy | \(\frac{(30 - 26.9230769)^2}{26.9230769}\) | \(\frac{(25 - 22.6153846)^2}{22.6153846}\) | \(\frac{(15 - 20.4615385)^2}{20.4615385}\) |
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | \(\frac{(-3.0769231)^2}{23.0769231}\) | \(\frac{(-2.3846154)^2}{19.3846154}\) | \(\frac{(5.4615385)^2}{17.5384615}\) |
| healthy | \(\frac{(3.0769231)^2}{26.9230769}\) | \(\frac{(2.3846154)^2}{22.6153846}\) | \(\frac{(-5.4615385)^2}{20.4615385}\) |
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | 0.4102564 | 0.2933455 | 1.700742 |
| healthy | 0.3516484 | 0.2514390 | 1.457779 |
Add all the squares of z-scores:
| Treatment 1 | Treatment 2 | Control | |
|---|---|---|---|
| diseased | 0.4102564 | 0.2933455 | 1.700742 |
| healthy | 0.3516484 | 0.2514390 | 1.457779 |
\[\chi^2 = 0.4102564 + 0.2933455 + 1.7007422 + 0.3516484 + 0.251439 + 1.4577791 = 4.4652106\]
Using R:
chisq(cont_table)X.squared
4.465211
Test statistic is the \(\chi^2\) score:
The higher the \(\chi^2\)-score is, the more evidence against the null hypothesis we have.
What is the null distribution of the sample \(\chi^2\)-scores?
Central Limit Theorem for two-way tables:
If all the expected counts are at least 5, then the null distribution of \(\chi^2\)-scores is the \(\chi^2\)-distribution with \[(\text{number of rows} - 1)(\text{number of columns} - 1)\] degrees of freedom.
gf_dist("chisq", df = 2) |>
gf_vline(xintercept = observed_chisquare, color = "red")1 - pchisq(observed_chisquare, df = 2)[1] 0.1072486
Observed \(\chi^2\)-score: 4.4652106
p-value is between 0.1 and 0.2.