Back to homeMathematics · Integrated Math III · Change subject
Start for free
Math III · Mathematics
Statistical inference · Inference

Chi-Square Tests and Inference for Regression Slopes

A game designer says a four-color spinner is fair: each color should come up $25\%$ of the time. You spin it $200$ times and get red $62$, blue $48$, green $51$, yellow $39$. A fair spinner would give $50$ of each, so these counts are off. But samples never match perfectly. Is this just random variation, or is the spinner rigged? In this page you will learn a test that answers this kind of question for categorical data. Then you will use a related tool, a $t$ procedure, to decide whether a regression slope is really different from $0$.

The chi-square statistic

When data fall into categories, we compare observed counts ($O$) with expected counts ($E$): the counts we would see if the claim (the null hypothesis) were true.

Why this formula? The difference $O - E$ measures the miss. Squaring keeps misses above and below from cancelling. Dividing by $E$ makes a miss of $10$ matter more when you only expected $20$ than when you expected $2{,}000$.

Bar graph of observed spinner counts for red, blue, green and yellow compared with the expected count of 50 shown as a dashed line. 62 48 51 39 Red Blue Green Yellow expected: 50 Observed counts in 200 spins

Red and yellow account for almost all of the $5.4$. When a test is significant, the largest contributions tell you where the data differ from the claim.

Practice★☆☆Not started
A market researcher wants to know if the distribution of car colors in Los Angeles matches the national distribution. Nationally, $25\%$ of cars are white, $20\%$ are…

A market researcher wants to know if the distribution of car colors in Los Angeles matches the national distribution. Nationally, $25\%$ of cars are white, $20\%$ are black, $15\%$ are silver, $10\%$ are red, and $30\%$ are other colors. The researcher selects a random sample of $400$ cars in Los Angeles. Calculate the expected count for red cars to be used in a chi-square goodness-of-fit test.

Solve
Practice★☆☆Not started
In a chi-square goodness-of-fit test comparing observed frequencies of a categorical variable to expected frequencies, one of the categories has an observed count of…

In a chi-square goodness-of-fit test comparing observed frequencies of a categorical variable to expected frequencies, one of the categories has an observed count of $45$ and an expected count of $50$. Calculate the individual contribution of this category to the overall chi-square test statistic.

Solve
Practice★★★Not started
A software company wants to know if the proportion of bugs reported in three different modules of their application matches the historical distribution. Historically,…

A software company wants to know if the proportion of bugs reported in three different modules of their application matches the historical distribution. Historically, Module A accounts for $50\%$ of bugs, Module B for $30\%$, and Module C for $20\%$. A recent update was pushed, and out of a random sample of $200$ new bug reports, $90$ were for Module A. You are given that the total chi-square test statistic for this sample is $\chi^2 = 6.5$. Determine the exact number of observed bugs for Module B and Module C. (Assume the observed count for Module B is greater than the expected count for Module B).

Solve

Goodness-of-fit test

A chi-square goodness-of-fit test asks whether one categorical variable in one population follows a claimed distribution.

Why $k - 1$? The counts must add up to $n$, so once you know $k - 1$ of them, the last one is forced.

Conditions:

  • Random: the data come from a random sample (or a randomized experiment).

  • 10%: if sampling without replacement, $n$ is less than $10\%$ of the population.

  • Large counts: every expected count is at least $5$.

Right-skewed chi-square density curve with the area to the right of 5.4 shaded, labeled P-value about 0.145. 5.4 0 P-value ≈ 0.145 χ² with df = 3

Big values of $\chi^2$ mean the data are far from the claim, so only the right tail counts as evidence against $H_0$. On a TI-84, use χ²cdf(5.4, 1E99, 3) for the P-value, or STAT TESTS χ²GOF-Test if the counts are in lists.

If an expected count is below $5$ you can sometimes combine similar categories. This lowers $k$, so it lowers $df$ too.

Practice★★☆Not started
The manufacturer of a popular candy claims that the color distribution of their product is $20\%$ red, $20\%$ orange, $20\%$ yellow, $20\%$ green, and $20\%$ purple. A…

The manufacturer of a popular candy claims that the color distribution of their product is $20\%$ red, $20\%$ orange, $20\%$ yellow, $20\%$ green, and $20\%$ purple. A student buys a large bag containing $150$ candies and counts $38$ red, $25$ orange, $22$ yellow, $35$ green, and $30$ purple candies. Calculate the chi-square test statistic to test the manufacturer's claim and state the degrees of freedom.

Solve
Practice★★☆Not started
An AP Statistics student rolls a standard six-sided die $120$ times to test if it is fair. The observed frequencies for the faces $1$ through $6$ are…

An AP Statistics student rolls a standard six-sided die $120$ times to test if it is fair. The observed frequencies for the faces $1$ through $6$ are $15, 25, 18, 22, 16,$ and $24$, respectively. Calculate the expected count for each face, compute the chi-square test statistic, and determine if there is convincing evidence at the $\alpha = 0.10$ level that the die is not fair.

Solve
Practice★★★Not started
In genetic crosses, the Hardy-Weinberg principle and Mendelian genetics predict that the offspring of a certain dihybrid cross should exhibit four distinct phenotypes in…

In genetic crosses, the Hardy-Weinberg principle and Mendelian genetics predict that the offspring of a certain dihybrid cross should exhibit four distinct phenotypes in a $9:3:3:1$ ratio. A botanist performs this cross and observes $400$ plants. The observed counts are $245$ for the first phenotype, $65$ for the second, $70$ for the third, and $20$ for the fourth.

Carry out a complete chi-square goodness-of-fit test. If the botanist decides to combine the last two phenotypes into a single category due to their biological similarity, how does this modification change the degrees of freedom and the critical value of the test at the $\alpha = 0.05$ level?

Solve

Back to the spinner: $\chi^2 = 5.4$ with $df = 3$ gives P-value $\approx 0.145$. If the spinner were fair, results this far from $50$-$50$-$50$-$50$ would happen about $14.5\%$ of the time. That is not unusual enough to call the spinner rigged at the $5\%$ level. It could well be luck.

Two-way tables: expected counts and degrees of freedom

Sometimes each person is classified by two categorical variables, and the counts go in a two-way table. If the variables had no relationship (or the groups had the same distribution), the expected count in each cell would follow from the totals.

Why? If there is no association, a column's share of the whole table should apply to every row. A row with $100$ people, in a table where $45\%$ of everyone is in column 1, should have about $45$ people in column 1.

On a TI-84, enter the observed table as matrix [A], then run STAT TESTS χ²-Test. The calculator stores the expected counts in [B].

Practice★☆☆Not started
A high school administrator is investigating if there is an association between a student's grade level (Freshman, Sophomore, Junior, Senior) and their preferred method…

A high school administrator is investigating if there is an association between a student's grade level (Freshman, Sophomore, Junior, Senior) and their preferred method of transportation to school (Bus, Car, Walk). The data is organized in a two-way table. The total number of Juniors surveyed is $120$, the total number of students who walk is $80$, and the grand total of all students surveyed is $500$. Calculate the expected count of Juniors who walk, assuming the null hypothesis of no association is true.

Solve
Practice★☆☆Not started
A political scientist conducts a survey to determine if there is a difference in the distribution of political party affiliation (Democrat, Republican, Independent,…

A political scientist conducts a survey to determine if there is a difference in the distribution of political party affiliation (Democrat, Republican, Independent, Green) across three different regions of a state (Urban, Suburban, Rural). The results are tallied in a contingency table. Determine the degrees of freedom for the appropriate chi-square test.

Solve
Practice★★☆Not started
Two different manufacturing plants in Ohio produce the same electronic component. A quality control manager takes a random sample of $200$ components from Plant A and…

Two different manufacturing plants in Ohio produce the same electronic component. A quality control manager takes a random sample of $200$ components from Plant A and $300$ components from Plant B, categorizing them as Defective, Minor Flaw, or Perfect.

In Plant A, $10$ are Defective, $30$ have a Minor Flaw, and $160$ are Perfect.

In Plant B, $25$ are Defective, $45$ have a Minor Flaw, and $230$ are Perfect.

Identify the expected count for "Defective components from Plant A" and check if the expected count condition for the chi-square test of homogeneity is satisfied.

Solve

Homogeneity or independence?

The calculation for a two-way table is identical in both tests. What differs is how the data were collected, and so how you write the hypotheses.

Homogeneity Independence
Data collection Separate random samples from two or more populations (or treatments in a randomized experiment) One random sample from one population, each person measured on two variables
Question Is the distribution of the categorical variable the same in every group? Are the two categorical variables associated?
$H_0$ The distribution of the variable is the same for all populations. The two variables are independent (no association) in the population.
$H_a$ The distribution is not the same for all populations. The two variables are associated.

The streaming example above was a homogeneity test: separate samples of teens and adults. If instead you had surveyed $300$ random people and recorded both age group and streaming preference, it would be a test of independence.

Conditions are the same as before: random sample(s) or randomized experiment, the $10\%$ condition, and all expected counts at least $5$.

If one or two expected counts fall below $5$ and you cannot collect more data, combine similar categories (for example, merge "Print" and "Radio" into "Print/Radio"). The table loses a row or column, so $df$ drops. Recompute the expected counts and check again.

Practice★☆☆Not started
Determine whether the following scenario requires a chi-square test for homogeneity or a chi-square test for independence: A researcher selects a single random sample of…

Determine whether the following scenario requires a chi-square test for homogeneity or a chi-square test for independence: A researcher selects a single random sample of $300$ registered voters in Texas and asks each voter for their highest level of education (High School, College, Graduate) and their opinion on a new tax bill (Support, Oppose, No Opinion).

Solve
Practice★★☆Not started
A university researcher wants to know if the type of extracurricular activity a student participates in (Sports, Arts, Academic Clubs) is independent of their academic…

A university researcher wants to know if the type of extracurricular activity a student participates in (Sports, Arts, Academic Clubs) is independent of their academic major (STEM, Humanities, Business). A random sample of $240$ students yields a chi-square test statistic of $\chi^2 = 11.45$. Determine the degrees of freedom for this test and interpret the meaning of the P-value if it is found to be $0.022$.

Solve
Practice★★☆Not started
A sociologist conducts a chi-square test for independence to see if there is an association between a person's generation (Gen Z, Millennials, Gen X, Boomers) and their…

A sociologist conducts a chi-square test for independence to see if there is an association between a person's generation (Gen Z, Millennials, Gen X, Boomers) and their primary news source (Social Media, TV, Print, Radio). After calculating the expected counts, she notices that the expected count for "Boomers who use Social Media" is $3.2$ and for "Gen Z who use Print" is $2.5$. All other expected counts are greater than $5$. Describe the appropriate statistical remedy to satisfy the conditions for the chi-square test without collecting more data, and state the new degrees of freedom if this remedy is applied.

Solve

Interpreting chi-square results

Meaning of the P-value. It is the probability of getting a $\chi^2$ at least this large if $H_0$ were true. It is not the probability that $H_0$ is true.

Errors.

  • A Type I error means rejecting $H_0$ when it is true. Its probability is $\alpha$.

  • A Type II error means failing to reject $H_0$ when it is false. In context: "concluding there is no association (or no difference) when there actually is one."

Sample size matters. Suppose the sample proportions stay exactly the same but $n$ is multiplied by $10$. Every observed and expected count is multiplied by $10$, and so is each $(O-E)^2/E$ (the numerator grows by $10^2$ and the denominator by $10$). So $\chi^2$ is multiplied by $10$, $df$ does not change, and the P-value gets much smaller. Bigger samples give more power, which means a lower chance of a Type II error. They also make tiny differences statistically significant.

Practice★★★Not started
A public health official is conducting a chi-square test for independence to determine if there is an association between a person's smoking status (Current, Former,…

A public health official is conducting a chi-square test for independence to determine if there is an association between a person's smoking status (Current, Former, Never) and their risk of developing a specific respiratory disease (High, Low). The test yields a P-value of $0.08$ at a significance level of $\alpha = 0.05$.

Define what a Type II error would mean in the context of this specific study. Furthermore, explain conceptually how increasing the sample size from $150$ to $1,500$ patients (assuming the sample proportions remain identical) would affect the expected counts, the chi-square test statistic, and the probability of making a Type II error.

Solve
Practice★★★Not started
A school district wants to compare the pass rates of a standardized math test across four different high schools. A random sample of $50$ students is taken from each…

A school district wants to compare the pass rates of a standardized math test across four different high schools. A random sample of $50$ students is taken from each school. The district runs a chi-square test for homogeneity and finds a test statistic of $\chi^2 = 12.8$.

A separate analyst decides to pool the data from all four schools and run a single-sample proportion $z$-test comparing the overall pass rate to a hypothesized state average.

Discuss why the chi-square test is the more appropriate method for comparing the four schools directly, and mathematically demonstrate the relationship between the chi-square test statistic and the two-sample $z$-test statistic if the district had only compared two schools instead of four.

Solve

Reading regression output

Now we switch from categorical data to two quantitative variables. The least-squares line $\hat{y} = a + bx$ from a sample estimates the true population line. Its slope $b$ is a statistic. The true slope $\beta$ (the Greek letter beta) is the parameter. Because $b$ changes from sample to sample, we use inference to ask about $\beta$.

Drag $b$ to $0$: the line is flat, so $x$ tells you nothing about the average of $y$. That is exactly the null hypothesis $H_0: \beta = 0$, "no linear relationship."

Most software prints something like this, for a sample of $n = 20$ students (free-throw percentage versus hours of practice per week):

Predictor Coef SE Coef T P
Constant 38.1 4.9 7.78 0.000
Hours 2.6 0.8 3.25 0.004
  • The Coef in the row of the explanatory variable is the sample slope: $b = 2.6$. The "Constant" row is the $y$-intercept.

  • SE Coef in that row is $SE_b = 0.8$. It tells you how much $b$ typically varies from sample to sample.

  • T is the test statistic for $H_0: \beta = 0$, and P is its two-sided P-value.

The standard error comes from the formula

$$SE_b = \frac{s}{s_x\sqrt{n-1}}$$

where $s$ is the standard deviation of the residuals and $s_x$ is the standard deviation of the $x$-values. A larger $n$, a wider spread in $x$, or less scatter around the line all make $SE_b$ smaller. Also, remember $b = r\,\dfrac{s_y}{s_x}$.

Practice★☆☆Not started
A real estate agent runs a linear regression to predict the price of a house (in thousands of dollars) based on its size (in hundreds of square feet). The computer…

A real estate agent runs a linear regression to predict the price of a house (in thousands of dollars) based on its size (in hundreds of square feet). The computer output is shown below:

Predictor Coef SE Coef T P
Constant $45.20$ $12.40$ $3.65$ $0.002$
Size $15.80$ $2.15$ $7.35$ $0.000$

Identify the value of the sample slope and the standard error of the slope from this output.

Solve
Practice★☆☆Not started
An ecologist is studying the relationship between the elevation (in feet) and the average daily temperature (in degrees Fahrenheit) in the Rocky Mountains. A…

An ecologist is studying the relationship between the elevation (in feet) and the average daily temperature (in degrees Fahrenheit) in the Rocky Mountains. A least-squares regression line is fitted to a sample of $25$ locations. The estimated slope is $b = -0.004$ and the standard error of the slope is $SE_b = 0.0012$. Calculate the test statistic for testing the null hypothesis $H_0: \beta_1 = 0$.

Solve
Practice★★★Not started
An economist is studying the relationship between a city's unemployment rate ($x$, in percent) and its crime rate ($y$, in incidents per $1,000$ residents). A random…

An economist is studying the relationship between a city's unemployment rate ($x$, in percent) and its crime rate ($y$, in incidents per $1,000$ residents). A random sample of $45$ US cities is selected. The computer output is lost, but the economist remembers the following summary statistics: the sample correlation is $r = 0.65$, the standard deviation of the unemployment rates is $s_x = 2.4$, and the standard deviation of the crime rates is $s_y = 15.6$. Calculate the standard error of the slope ($SE_b$) using the formula $SE_b = \frac{s}{s_x \sqrt{n-1}}$, given that the standard deviation of the residuals is $s = 12.1$. Then, construct a $99\%$ confidence interval for the population slope.

Solve

The t test for a slope

The $t$ value says how many standard errors the sample slope is from $0$. On a TI-84 use STAT TESTS LinRegTTest.

One-sided tests. Computer output gives the two-sided P-value. For $H_a: \beta > 0$ or $\beta < 0$, divide it by $2$, but only if the sign of $b$ agrees with $H_a$. If $b$ points the other way, the one-sided P-value is $1 - \frac{P}{2}$, which is large.

If the output hides $SE_b$ but gives the two-sided P-value, you can work backward: find the $t$ with that two-tailed area using invT and $df = n-2$, then use $SE_b = b/t$.

Practice★★☆Not started
A fitness coach believes that the number of hours a person spends sleeping per night positively affects their maximum weight lifted (in pounds) on the bench press. A…

A fitness coach believes that the number of hours a person spends sleeping per night positively affects their maximum weight lifted (in pounds) on the bench press. A regression analysis on a random sample of $30$ athletes yields a slope of $b = 5.2$ and a standard error $SE_b = 2.4$. The computer output provides a two-sided P-value of $0.0385$. Assuming all conditions for inference are met, determine the P-value for the coach's specific hypothesis and state the conclusion at the $\alpha = 0.05$ significance level.

Solve
Practice★★★Not started
A sports analyst has the computer output for a linear regression predicting the number of wins a baseball team will have based on their run differential (Runs Scored…

A sports analyst has the computer output for a linear regression predicting the number of wins a baseball team will have based on their run differential (Runs Scored minus Runs Allowed). The sample size is $30$ teams. The P-value for the two-sided hypothesis test $H_0: \beta_1 = 0$ is exactly $0.014$, and the estimated slope is $b = 0.105$.

The analyst accidentally deletes the standard error of the slope ($SE_b$) from the output. Using the given information, reconstruct the value of $SE_b$. (Hint: You will need to use an inverse t-distribution function or table to find the t-statistic corresponding to the P-value). Assume the test statistic is positive.

Solve

Confidence interval for a slope

A test only says whether $\beta$ could be $0$. An interval tells you how large it could be.

Always interpret the slope as a change in the mean $y$ per one-unit increase in $x$, with units and context.

Transformed data. If a scatterplot is curved, you can take $\ln y$ and fit a line $\widehat{\ln y} = a + bx$. Exponentiating gives $\hat{y} = e^a\,(e^b)^x$, so each one-unit increase in $x$ multiplies the predicted $y$ by the growth factor $e^b$. For example, if $b = 0.03$, then $e^{0.03} \approx 1.0305$, a growth of about $3.05\%$ per unit. To interpret the ends of a confidence interval for $b$, apply $e^{(\cdot)}$ to each end.

Practice★☆☆Not started
A consumer advocate is analyzing the relationship between the weight of a car (in pounds) and its fuel efficiency (in miles per gallon). Based on a random sample of $18$…

A consumer advocate is analyzing the relationship between the weight of a car (in pounds) and its fuel efficiency (in miles per gallon). Based on a random sample of $18$ cars, the slope of the least-squares regression line is $-0.006$ with a standard error of $0.0015$. The critical value for a $95\%$ confidence interval is $t^* = 2.120$. Construct the expression for the $95\%$ confidence interval for the true population slope.

Solve
Practice★★☆Not started
A marine biologist investigates the relationship between the length of a certain species of shark (in inches) and its weight (in pounds). The computer output for the…

A marine biologist investigates the relationship between the length of a certain species of shark (in inches) and its weight (in pounds). The computer output for the regression analysis of a sample of $22$ sharks is provided:

Predictor Coef SE Coef T P
Constant $-120.5$ $35.2$ $-3.42$ $0.003$
Length $8.45$ $1.85$ $4.57$ $0.000$

Calculate the $90\%$ confidence interval for the true slope of the regression line. Assume the conditions for inference are met. (Use $t^* = 1.725$ for $20$ degrees of freedom).

Solve
Practice★★★Not started
A scatterplot of the price of a stock ($y$) against time in days ($x$) shows a clear exponential growth pattern. A data scientist applies a natural logarithm…

A scatterplot of the price of a stock ($y$) against time in days ($x$) shows a clear exponential growth pattern. A data scientist applies a natural logarithm transformation to the $y$-variable and fits the least-squares regression line $\widehat{\ln(y)} = 1.2 + 0.045x$. The standard error of the slope is $0.012$ based on a sample of $30$ days.

Construct a $95\%$ confidence interval for the slope of the transformed regression line. Then, interpret the upper bound of this interval in terms of the original variables, specifically detailing the percentage growth of the stock price per day.

Solve

Conditions for regression inference

Both the $t$ test and the interval for $\beta$ need these conditions. Remember them as LINER:

  • Linear: the true relationship is linear. Check the scatterplot and the residual plot (no curved pattern).

  • Independent: observations are independent. For sampling without replacement, $n < 10\%$ of the population.

  • Normal: for any fixed $x$, the response varies approximately normally around the line. Check that the residuals are roughly symmetric and have no strong outliers, using a histogram or normal probability plot.

  • Equal SD: the spread of the residuals is about the same for all $x$.

  • Random: the data come from a random sample or randomized experiment.

Three residual plots: random scatter around zero is fine, a U-shaped pattern shows a nonlinear relationship, and a fan shape shows unequal spread. Random scatter: OK Curved: not linear Fan: unequal spread

A good residual plot looks like a horizontal band of random scatter around $0$. A curve means the line is the wrong model (try a transformation such as $\ln y$). A fan shape means the spread is not constant, so the standard error is unreliable.

Influential points. A point far from the others in the $x$-direction (high leverage) can pull the least-squares line toward itself. If removing it noticeably changes the slope, it is influential. It may also change $r$ and the standard error. Report the analysis with and without it, and investigate why it is unusual.

Practice★★☆Not started
A data analyst is running a linear regression to predict the annual maintenance cost of delivery trucks based on their total mileage. The analyst checks the conditions…
Predicted (x) Residuals 0 A

A data analyst is running a linear regression to predict the annual maintenance cost of delivery trucks based on their total mileage. The analyst checks the conditions for inference by examining the residual plot provided in Panel A. Based on the visual evidence, identify which specific condition for linear regression inference is clearly violated and explain why.

Solve
Practice★★★Not started
A researcher is investigating the relationship between the dosage of a new medication ($X$) and the reduction in blood pressure ($Y$). The scatterplot in Panel 1…
X Y Point P 1 X Y 2

A researcher is investigating the relationship between the dosage of a new medication ($X$) and the reduction in blood pressure ($Y$). The scatterplot in Panel 1 includes all data points, with a highly influential point labeled as Point P. Panel 2 shows the data with Point P removed.

Let $t_1$ and $p_1$ be the test statistic and P-value for testing $H_0: \beta_1 = 0$ in Panel 1. Let $t_2$ and $p_2$ be the corresponding values for Panel 2.

Analyze the visual data and explain theoretically how removing Point P will affect the standard error of the slope ($SE_b$), the magnitude of the test statistic ($t$), and the P-value. Will the evidence for a linear relationship become stronger or weaker?

Solve

Summary

  • Chi-square statistic: $\chi^2 = \sum \dfrac{(O-E)^2}{E}$. The P-value is the right-tail area. Conditions: random, $10\%$, all expected counts at least $5$.

  • Goodness-of-fit: one variable, one sample, $E = np$, $df = k-1$.

  • Two-way tables: $E = \dfrac{\text{row total} \times \text{column total}}{\text{table total}}$, $df = (r-1)(c-1)$. Use homogeneity for separate samples from several populations or treatments, and independence for one sample measured on two variables.

  • Interpretation: a significant result means association or difference, not causation. Look at the biggest contributions to $\chi^2$. A larger $n$ multiplies $\chi^2$ and gives more power.

  • Slope inference: $t = \dfrac{b}{SE_b}$ with $df = n-2$. The output P-value is two-sided, and the confidence interval is $b \pm t^* SE_b$.

  • Conditions (LINER): Linear, Independent, Normal residuals, Equal SD, Random. Check the residual plot and watch for influential points.

See all the exercises in this section