Chi-Squared Tests and Linear Regression Inference, Introduction to Statistics – Study Notes
offline

Difficulty: Intermediate to Advanced | Prerequisites: Inference for proportions and means, basic understanding of categorical data tables and least-squares regression lines.

Big picture: This material covers two distinct areas that often appear at the end of an introductory statistics course. Chi-squared tests extend hypothesis testing to categorical data with more than two categories, or to the relationship between two categorical variables. Linear regression inference lets you make formal claims about the slope of a population regression line, rather than just the slope of the line you fitted to your sample. Both topics build on the same hypothesis-testing framework you already know from proportions and means: state hypotheses, check conditions, compute a test statistic, find a p-value, draw a conclusion.


TL;DR

Chi-squared (χ²) tests handle categorical data: goodness-of-fit tests whether one variable matches expected proportions, independence tests whether two variables are related in one population, and homogeneity tests whether a variable's distribution is the same across multiple populations. Linear regression t-procedures test whether the true slope of a regression line is zero (no linear relationship) or estimate it with a confidence interval.


Key Terms

Chi-squared statistic (χ²)

A measure of how far the observed counts in your data are from the counts you would expect under the null hypothesis. Calculated as: χ² = Σ [(Observed − Expected)² / Expected]. Larger values mean bigger discrepancies between what you observed and what the null predicts.

Think of it as a single number that captures the overall "mismatch" between your data and the null model.

Expected count

The count you would expect in a cell if the null hypothesis were true. For goodness-of-fit: Expected = n × p₀ (the sample size times the hypothesised proportion for that category). For independence/homogeneity: Expected = (row total × column total) / grand total.

Degrees of freedom (df) for chi-squared

Goodness-of-fit: df = number of categories − 1. Independence and homogeneity: df = (number of rows − 1) × (number of columns − 1).

Goodness-of-fit test

Tests whether the distribution of a single categorical variable matches a set of specified proportions.

In simple terms: "Does this variable's breakdown match what we expected?"

Test for independence

Tests whether two categorical variables are associated in a single population.

In simple terms: "Are these two variables related, or is any pattern just due to chance?"

Test for homogeneity

Tests whether the distribution of a categorical variable is the same across two or more populations or treatments.

In simple terms: "Do different groups have the same breakdown of this variable?"

Least-Squares Regression Line (LSRL)

The line ŷ = a + bx that minimises the sum of squared residuals. Here b is the sample slope and a is the sample y-intercept.

True slope (β)

The slope of the population regression line. This is the parameter you test or estimate. H₀ is typically β = 0, meaning there is no linear relationship between x and y.

Standard error of the slope (SE_b)

A measure of how much the sample slope b is expected to vary from sample to sample. The formula involves the residual standard deviation and the spread of the x-values. In practice, your calculator or software computes it.


Core Content

Chi-Squared Goodness-of-Fit Test (χ² GOF Test)

  • Purpose: Test whether the observed distribution of a single categorical variable matches a specified (expected) distribution.

  • Example: Testing whether a die is fair (each face should appear 1/6 of the time).

  • Hypotheses:

    • H₀: The distribution of the variable matches the specified proportions.

    • Hₐ: The distribution does not match.

  • Conditions to check:

    • Random sample

    • Independence: n ≤ 10% of the population

    • Large sample: all expected counts ≥ 5

  • This is always a right-tailed test. Large χ² values indicate a poor fit.

  • Calculator function: χ²GOF-Test (or x²GOF Test)

  • Inputs required: Observed counts in one list, expected counts in another list, df = (number of categories − 1)

Chi-Squared Test for Independence (χ² Test)

  • Purpose: Test whether two categorical variables are associated in a single population.

  • Example: Is there a relationship between gender and preferred mode of transport in a city?

  • Hypotheses:

    • H₀: The two variables are independent (no association).

    • Hₐ: The two variables are not independent (there is an association).

  • Data layout: A two-way table (contingency table) where the data come from one sample, classified by two variables.

  • Conditions to check:

    • Random sample

    • Independence: n ≤ 10% of the population

    • Large sample: all expected counts ≥ 5

  • Calculator function: χ²-Test (or x² Test)

  • Inputs required: The observed matrix entered into the calculator

Chi-Squared Test for Homogeneity (χ² Test)

  • Purpose: Test whether the distribution of a categorical variable is the same across two or more populations or treatment groups.

  • Example: Do three different schools have the same distribution of students across class years?

  • Hypotheses:

    • H₀: The distribution of the variable is the same across all populations.

    • Hₐ: The distribution differs for at least one population.

  • Data layout: A two-way table where the rows (or columns) represent different populations and the columns (or rows) represent the categories.

  • Conditions to check: Same as the test for independence.

  • Calculator function: χ²-Test (or x² Test), the same function as the independence test

  • Inputs required: The observed matrix entered into the calculator

How to Distinguish Independence from Homogeneity

The calculation is identical. The distinction is in the study design:

  • Independence: One sample, two variables. You observe a group of people and classify each person on two dimensions (e.g., political affiliation and region).

  • Homogeneity: Two or more samples (or treatment groups), one variable. You sample separately from each population and measure the same variable (e.g., sample from School A and School B, record each student's favourite subject).

On an exam, the setup of the problem tells you which test it is. The calculator does not differentiate between them.


Confidence Interval for the True Slope of the LSRL (Lin Reg T Int)

  • Purpose: Estimate the true population slope β with a confidence interval.

  • When to use: You have bivariate quantitative data, have fitted a LSRL, and want a range of plausible values for the true slope.

  • Conditions to check (LINE):

    • Linear: the scatterplot shows a linear pattern (check the residual plot for no curves)

    • Independent: observations are independent of each other

    • Normal: for any given x, the y-values are roughly normally distributed (check: the residuals should be approximately normal, with no strong skew or outliers)

    • Equal variance: the scatter around the line is roughly the same for all x-values (check: the residual plot shows constant spread, no "fanning")

  • Calculator function: LinRegTInt

  • Inputs required: x-list, y-list, C-Level

Test for the Slope of the LSRL (Lin Reg T Test)

  • Purpose: Test whether the true slope β is zero (i.e., whether there is a linear relationship between x and y).

  • Hypotheses:

    • H₀: β = 0 (no linear relationship)

    • Hₐ: β ≠ 0 (or β < 0, or β > 0)

  • Conditions to check: Same LINE conditions as the confidence interval.

  • Test statistic: t = b / SE_b, with df = n − 2.

  • Calculator function: LinRegTTest

  • Inputs required: x-list, y-list, direction of Hₐ


Formulas

Chi-squared test statistic:

χ² = Σ [(O − E)² / E]

where O = observed count and E = expected count, summed across all cells.

Expected count (independence/homogeneity):

E = (row total × column total) / grand total

Degrees of freedom:

Goodness-of-fit: df = k − 1, where k = number of categories.

Independence/homogeneity: df = (r − 1)(c − 1), where r = number of rows and c = number of columns.

Confidence interval for slope:

b ± t* × SE_b

where t* comes from the t-distribution with df = n − 2.

t-test statistic for slope:

t = b / SE_b


Real-World Applications

A public health agency might use a chi-squared goodness-of-fit test to check whether disease cases are distributed evenly across months, or cluster in certain seasons. A test for independence might evaluate whether smoking status is associated with the occurrence of a particular illness. In regression, a marine biologist might test whether there is a significant linear relationship between water temperature and coral growth rate.


Common Misconceptions

  • "The chi-squared test for independence and the test for homogeneity are different statistical tests." The mathematics is identical. The only difference is the study design: one sample classified two ways (independence) vs. separate samples compared on one variable (homogeneity). State the correct test name based on the scenario.

  • "Expected counts are the same as observed counts." Expected counts are computed from the null hypothesis. They represent what the data would look like if H₀ were true. The entire point of the test is to measure the gap between observed and expected.

  • "A significant chi-squared test tells you which cells are different." It tells you the overall distribution deviates from expectation, but not which specific cells drive the result. You need to examine the individual contributions to χ² to identify the largest deviations.

  • "Failing to reject H₀: β = 0 means x and y are unrelated." It means there is no evidence of a linear relationship. The variables could still have a curved or otherwise non-linear association.


Why It Matters / Exam Flags

⚠️ All expected counts must be at least 5 for chi-squared tests. If any expected count is below 5, the chi-squared approximation is unreliable. This condition is frequently tested.

⚠️ Chi-squared tests are always right-tailed. The p-value is always the area to the right of your χ² statistic. There is no "less than" or "two-sided" option.

⚠️ Know how to compute expected counts by hand: (row total × column total) / grand total. Even if you use a calculator, you may be asked to show this on an exam.

⚠️ For linear regression inference, check all four LINE conditions and describe what you looked for in each (not just "conditions met").

⚠️ The degrees of freedom for the regression t-test are n − 2, not n − 1.

⚠️ Be able to read a computer output table for regression and identify the slope, SE of slope, t-statistic, and p-value. Many exam questions present output rather than asking you to compute by hand.


Quick Self-Test

  1. True or False: A chi-squared goodness-of-fit test can be left-tailed.

  1. Fill in the blank: For a test of independence on a 3 × 4 table, the degrees of freedom are __________.

  1. True or False: The test for independence and the test for homogeneity use the same calculator function.

  1. Fill in the blank: The null hypothesis for a linear regression t-test is typically H₀: β = __________.

  1. True or False: Degrees of freedom for the regression slope t-test are n − 1.

Answers: 1. False (chi-squared tests are always right-tailed). 2. (3 − 1)(4 − 1) = 6. 3. True. 4. 0. 5. False (df = n − 2).


Practice Q&A

Q: A researcher surveys 500 people and classifies each by education level (3 categories) and political party preference (4 categories). What test should be used, and what are the degrees of freedom?

A: This is a chi-squared test for independence, because it is one sample classified by two categorical variables. Use χ²-Test. Degrees of freedom = (3 − 1)(4 − 1) = 6.

Q: A company claims that 40% of its customers prefer Product A, 35% prefer Product B, and 25% prefer Product C. A sample of 200 customers shows 90, 65, and 45 in each group respectively. What test do you use, and how do you find the expected counts?

A: Use χ²GOF-Test. Expected counts are 200 × 0.40 = 80, 200 × 0.35 = 70, and 200 × 0.25 = 50. Degrees of freedom = 3 − 1 = 2. Compute χ² = (90 − 80)²/80 + (65 − 70)²/70 + (45 − 50)²/50 and compare the p-value to your significance level.

Q: A regression analysis on n = 30 data points gives a slope b = 2.4 and SE_b = 0.8. Is there significant evidence of a linear relationship at α = 0.05?

A: H₀: β = 0, Hₐ: β ≠ 0. The test statistic is t = 2.4 / 0.8 = 3.0 with df = 30 − 2 = 28. Using a t-table or calculator, the two-sided p-value for t = 3.0 with 28 df is approximately 0.006. Since 0.006 < 0.05, reject H₀. There is significant evidence of a linear relationship.

Q: How do you decide between a goodness-of-fit test, a test for independence, and a test for homogeneity?

A: Ask two questions. First, how many variables? If one categorical variable compared to a specified distribution, use goodness-of-fit. If two categorical variables, move to the second question: how many samples? If one sample classified by both variables, use independence. If separate samples (or treatment groups) compared on one variable, use homogeneity.


Connections to Other Topics

Chi-squared tests are a natural extension of one- and two-proportion z-tests: where those compare one or two proportions, chi-squared handles the general case of multiple categories. Linear regression inference builds on the concept of the LSRL from earlier in the course, adding the formal hypothesis-testing and confidence-interval machinery. The LINE conditions for regression connect back to residual analysis and the assumptions behind the least-squares model.


Related Terms / Search Tags

chi-squared, chi-square, χ², x², goodness of fit, GOF test, test for independence, test for homogeneity, expected count, observed count, contingency table, two-way table, categorical data, degrees of freedom, linear regression, LSRL, least-squares regression line, slope, true slope, beta, regression inference, LinRegTTest, LinRegTInt, t-test for slope, residual plot, LINE conditions, intro stats, AP Statistics, Purdue STAT