X-squared
18.96998
gss2016 1 datasetparty (Dem, Ind, or Rep)natarms opinion on current level of government spending on national defensenatspac opinion on current level of government spending on space exploration| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH | Total |
|---|---|---|---|---|
| Dem | 17 | 14 | 12 | 43 |
| Ind | 20 | 28 | 24 | 72 |
| Rep | 24 | 8 | 2 | 34 |
| Total | 61 | 50 | 38 | 149 |
| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH | Total |
|---|---|---|---|---|
| Dem | 8 | 22 | 13 | 43 |
| Ind | 13 | 37 | 22 | 72 |
| Rep | 9 | 17 | 8 | 34 |
| Total | 30 | 76 | 43 | 149 |
Hypotheses stated in terms of an association
Hypotheses stated in terms of differences
| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH | Total |
|---|---|---|---|---|
| Dem | 17 (17.60) | 14 (14.43) | 12 (10.97) | 43 |
| Ind | 20 (29.48) | 28 (24.16) | 24 (18.36) | 72 |
| Rep | 24 (13.92) | 8 (11.41) | 2 (8.67) | 34 |
| Total | 61 | 50 | 38 | 149 |
| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH |
|---|---|---|---|
| Dem | \(\frac{(17 -17.60)^2}{17.60}=0.02\) | \(\frac{(14-14.43)^2}{14.43}=0.01\) | \(\frac{(12-10.97)^2}{10.97}=0.10\) |
| Ind | \(\frac{(20-29.48)^2}{29.48}=3.05\) | \(\frac{(28-24.16)^2}{24.16}=0.61\) | \(\frac{(24-18.36)^2}{18.36}=1.73\) |
| Rep | \(\frac{(24-13.92)^2}{13.92}=7.30\) | \(\frac{(8-11.41)^2}{11.41}=1.02\) | \(\frac{(2-8.67)^2}{8.67}=5.13\) |
Or just ask R…
Here is the original GSS data with 5 random permutations.
Here is the resulting histogram
Histogram of \(X^2\) statistics for 1,000 random permutations. Observed value (\(18.97\)) indicated by dashed vertical line.
Chi-squared test for assessing independence between categorical variables
When the null-hypothesis is true and the following conditions are met, \(X^2\) has a Chi-squared distribution with \(df=(r-1)\times(c-1)\) degrees of freedom:


pchisq function computes the area up to the specified cutoff, subtract value from 1 to find the p-value
Hypotheses stated in terms of an association
Hypotheses stated in terms of differences
| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH | Total |
|---|---|---|---|---|
| Dem | 8 | 22 | 13 | 43 |
| Ind | 13 | 37 | 22 | 72 |
| Rep | 9 | 17 | 8 | 34 |
| Total | 30 | 76 | 43 | 149 |
| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH | Total |
|---|---|---|---|---|
| Dem | 8 (8.66) | 22 (21.93) | 13 (12.41) | 43 |
| Ind | 13 (14.50) | 37 (36.72) | 22 (20.78) | 72 |
| Rep | 9 (6.85) | 17 (17.34) | 8 (9.81) | 34 |
| Total | 30 | 76 | 43 | 149 |
This time we will go straight to R to calculate \(\chi^2\) statistic
Chi-squared disributions with different degrees of freedom.