Lesson 19: Chi-Square Tests and Inference for Regression Slopes
Not all data are numbers: much of the data you meet are counts in categories, and the chi-square tests are the tools for them. There are three, and telling them apart is the first skill. The goodness-of-fit test asks whether observed counts in one categorical variable match a claimed distribution. The test of independence asks whether two categorical variables are associated, using data from a single sample. The test of homogeneity asks whether the distribution of a categorical variable is the same across several populations, using separate samples from each. All three use the same statistic, χ² = Σ (observed − expected)² / expected, and differ in how the expected counts are found and in their degrees of freedom.
The expected counts are what the null hypothesis predicts. For goodness of fit, they come from the claimed proportions multiplied by the total sample size. For independence and homogeneity, they come from the row and column totals: expected count = (row total × column total) / table total. The conditions are that the data come from a random sample or randomized experiment and that all expected counts are at least 5 — if they are not, the chi-square approximation is unreliable and categories may need combining. The degrees of freedom are the number of categories minus one for goodness of fit, and (rows − 1) × (columns − 1) for the other two tests.
Inference for a regression slope answers a different question: is there really a linear relationship in the population, or is the slope you see in your sample just noise? The population model is y = α + βx + ε, where β is the true slope and ε is the random error around the line, and the test is H0: β = 0 against Ha: β ≠ 0, or a one-sided version. The test statistic is t = (b − 0) / SE_b, with n − 2 degrees of freedom, where SE_b is the standard error of the estimated slope. The conditions are linearity, independent observations, constant variance of the residuals, and Normality of the residuals, checked with the scatterplot and the residual plot.
A confidence interval for the slope, b ± t* × SE_b, is often more informative than the test alone, because it gives a range of plausible values for how much y changes per unit of x in the population. If the interval excludes zero, that matches a rejection of the null; if it includes zero, the data are consistent with no linear relationship. Remember that inference for the slope is about the linear relationship only — a test that fails to reject β = 0 does not prove there is no relationship, only that there is no evidence of a linear one, and a curved relationship could still be present.
A worked example
Worked example: a worked-example genetics experiment expects a 3:1 ratio of round to wrinkled seeds, and 200 seeds give 140 round and 60 wrinkled. The expected counts are 150 and 50, so χ² = (140 − 150)² / 150 + (60 − 50)² / 50 = 100 / 150 + 100 / 50 = 0.67 + 2 = 2.67, with 1 degree of freedom. The critical value at α = 0.05 is 3.84, and the p-value is about 0.10, so you fail to reject the null: the data are consistent with the 3:1 ratio. Now consider a regression slope example: a sample of 20 points gives b = 2.4 with SE_b = 0.8, so t = 2.4 / 0.8 = 3 with 18 degrees of freedom, giving a two-sided p-value of about 0.008 — convincing evidence of a positive linear relationship in the population.
In your answers, name the test, state the hypotheses in context, show the expected counts or the slope calculation, and conclude in words about the variables, not just the statistic. A chi-square answer that stops at a number has missed the point, and a slope answer that forgets the conditions is incomplete. When a question gives you a table, take a moment to decide which of the three chi-square tests it is: one sample and two variables means independence, several samples and one variable means homogeneity, and one variable against a claimed distribution means goodness of fit.
Key Terms
- Chi-square statistic
- χ² = Σ (observed − expected)² / expected, measuring how far counts are from what the null predicts.
- Goodness-of-fit test
- A chi-square test comparing observed counts to a claimed distribution.
- Test of independence
- A chi-square test of whether two categorical variables in one sample are associated.
- Test of homogeneity
- A chi-square test of whether a categorical distribution is the same across populations.
- Slope inference
- Testing or estimating the population regression slope β, using t = b / SE_b with n − 2 degrees of freedom.
Discussion Questions
- How do you tell a test of independence from a test of homogeneity?
- Why must expected counts be at least 5 for a chi-square test?
- A slope confidence interval is (0.5, 3.2). What does it tell you about the test of β = 0?
Practice Questions
- A goodness-of-fit test has 4 categories. How many degrees of freedom does it have?
- A 3 × 2 table is tested for independence. How many degrees of freedom?
- Expected counts are found from row and column totals in which chi-square tests?
- A regression slope has b = 1.5 and SE_b = 0.5. What is the t statistic for testing β = 0?
- A chi-square test gives p = 0.02. What do you conclude at α = 0.05?
Show answers
- 3, the number of categories minus one.
- (3 − 1) × (2 − 1) = 2.
- The tests of independence and homogeneity.
- t = 1.5 / 0.5 = 3.
- Reject the null hypothesis; there is convincing evidence against it.