AP Statistics · Exploring two-variable data
Linear regression
1The least-squares regression line
A regression line models how the response $y$ changes as the explanatory $x$ changes:
$$\hat{y} = a + bx$$
- $\hat{y}$ ("y-hat") is the predicted value.
- The least-squares regression line (LSRL) makes the sum of squared residuals as small as possible.
- Slope: $b = r\frac{s_y}{s_x}$. The line always passes through $(\bar{x}, \bar{y})$, so $a = \bar{y} - b\bar{x}$.
$\bar{x} = 20$, $s_x = 4$, $\bar{y} = 75$, $s_y = 10$, $r = 0.8$.
- $b = 0.8 \times \frac{10}{4} = 2$.
- $a = 75 - 2(20) = 35$.
- $\hat{y} = 35 + 2x$.
Check yourself
The LSRL always passes through:
Show the answer
(x̄, ȳ)
A property of least squares.
2Interpreting slope and intercept
- Slope: "For each additional 1 [unit of $x$], the predicted [y] increases (or decreases) by $b$ [units]."
- Intercept: "When $x = 0$, the predicted [y] is $a$." It may not be meaningful if $x = 0$ is outside the data or impossible.
$\widehat{\text{price}} = 32{,}000 - 2{,}400(\text{age})$ for used cars.
- Slope: for each additional year of age, the predicted price falls by $2,400.
- Intercept: a new car (age 0) has predicted price $32,000.
Use the word predicted: the slope describes the model, not every individual.
Check yourself
ŷ = 12 + 0.5x predicts weight (kg) from age (months). The slope means:
Show the answer
Predicted weight increases by 0.5 kg for each extra month
"Predicted" is essential.
3Prediction and extrapolation
Substitute an $x$ value to make a prediction. Extrapolation (predicting outside the range of $x$ values in the data) is risky: the linear pattern may not continue.
a line $\hat{y} = 35 + 2x$ was fitted for $x$ from 10 to 30.
- Predicted $y$ at $x = 25$: $85$. (Interpolation: reasonable.)
- At $x = 80$: $195$. (Extrapolation: unreliable.)
Predict inside the data range; beyond it the straight line may not continue
Check yourself
Predicting using x = 100 when the data range from 10 to 40 is:
Show the answer
Extrapolation, and unreliable
Outside the data.
4The coefficient of determination r²
$r^2$ is the proportion of the variation in $y$ that is explained by the linear model with $x$.
- $r = 0.8$ gives $r^2 = 0.64$: "64% of the variation in [y] is accounted for by the linear model relating [y] to [x]."
- $s$ (the standard deviation of the residuals) gives the typical prediction error: "Actual [y] values typically differ from predicted values by about $s$ [units]."
Reading computer output: the row "Constant" gives $a$; the row with the variable name gives $b$; "R-sq" gives $r^2$; "S" gives $s$.
Check yourself
r² = 0.81 means:
Show the answer
81% of the variation in y is explained by the linear model with x
Proportion of variation explained.
5Going deeper: finding the line from summary statistics and interpreting every part
A regression line models how a response variable y changes as an explanatory variable x changes, and is used to predict y from x.
$$\hat{y} = a + bx$$
- $\hat{y}$ ("y-hat") is the predicted value.
- b is the slope; a is the y-intercept.
Least-squares regression line: the line that makes the sum of the squared residuals as small as possible.
From summary statistics
$$b = r\frac{s_y}{s_x}, \qquad a = \bar{y} - b\bar{x}$$
The line always passes through the point $(\bar{x}, \bar{y})$.
for a class, hours studied (x) has mean 3.5 and standard deviation 1.2; exam score (y) has mean 72 and standard deviation 9; r = 0.80.
- b = 0.80 × 9 ÷ 1.2 = 6.0.
- a = 72 − 6.0 × 3.5 = 51.
- Equation: predicted score = 51 + 6.0 (hours).
Interpreting the slope (use this template): "For each additional hour studied, the predicted exam score increases by 6.0 points."
- Include "predicted" (or "on average"): the line describes a tendency, not every individual.
- Include units and context.
Interpreting the intercept: "A student who studies 0 hours is predicted to score 51." It is meaningful only if x = 0 makes sense and lies within, or near, the range of the data.
Predicting: for 5 hours, predicted score = 51 + 6.0(5) = 81.
Residual = observed − predicted = $y - \hat{y}$.
- A student who studied 5 hours and scored 85 has residual 85 − 81 = +4: the line underpredicted.
- A negative residual means the point lies below the line: the line overpredicted.
Extrapolation: predicting for x outside the range of the data. The linear pattern may not continue, so such predictions are unreliable. Predicting a score for 20 hours of study gives 171, which is impossible.
Coefficient of determination, r²: the proportion of the variation in y that is accounted for by the linear relationship with x.
- Here r² = 0.64: "About 64% of the variation in exam scores is explained by the linear relationship with hours studied."
- The remaining 36% is due to other factors and chance.
- From r² to r: take the square root and attach the sign of the slope.
Standard deviation of the residuals, s: the typical size of a prediction error. "Actual scores typically differ from the scores predicted by the line by about s points."
Reading computer output: a typical table has a row labelled "Constant" (the intercept) and a row labelled with the explanatory variable (the slope), each with a coefficient, a standard error, a t-value and a P-value; below it are S (the standard deviation of the residuals) and R-Sq.
output shows Constant, Coef 12.4; Width, Coef 3.25; S = 2.1; R-Sq = 81.0%, for predicting a leaf's length (cm) from its width (cm).
- Predicted length = 12.4 + 3.25 (width).
- Slope: each extra centimeter of width is associated with a predicted increase of 3.25 cm in length.
- r = +√0.81 = +0.90 (positive, like the slope).
- Predictions are typically off by about 2.1 cm.
Regression to the mean: since |r| ≤ 1, a value of x that is 1 standard deviation above its mean predicts a y that is only r standard deviations above its mean. Very tall parents tend to have children who are tall, but less extremely so.
The roles of x and y matter: the line for predicting y from x is not the same as the line for predicting x from y. (Correlation, by contrast, is the same either way.)
Before fitting a line: plot the data. A line is appropriate only if the form is roughly linear.
Common mistakes
- Leaving out "predicted" when interpreting the slope.
- Interpreting r as r².
- Writing y in place of $\hat{y}$ in the equation.
- Not defining the variables.
- Extrapolating.
- Giving r the wrong sign when taking the square root of r².
- Treating the slope as showing that x causes y.
Check yourself
A regression line is predicted price = 4.2 + 1.5 (weight), with weight in kilograms and price in dollars. What does the slope mean?
Show the answer
For each additional kilogram, the predicted price increases by 1.50 dollars
The slope is the predicted change in y for a one-unit increase in x.
6For top marks
- Write the equation with variable names and a hat: $\widehat{\text{score}} = 40 + 5(\text{hours})$.
- Interpret slope with "predicted" and units; interpret $r^2$ and $s$ in context.
- Identify extrapolation and explain why it is risky.
- The regression line of $y$ on $x$ is not the same as $x$ on $y$; choose the explanatory variable correctly.
"$s = 3.2$: the actual exam scores typically differ from the scores predicted by hours of study by about 3.2 points."
Check yourself
To find r from r² = 0.49 with a negative slope:
Show the answer
r = −0.7
Square root, with the slope's sign.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera