01 / 20

Least Squares
Regression

Master the line of best fit, understand residuals, and learn how to measure the strength of linear relationships with data.

College Statistics

What Is Regression?

Regression is a statistical method for modeling the relationship between two quantitative variables. Given a set of data points, we want to find the straight line that best summarizes the trend in the data.

Explanatory Variable
The independent variable \(x\): the input we use to predict.
Response Variable
The dependent variable \(y\): the outcome we want to predict.

Scatterplots and Linear Patterns

Hours Studied (x) Test Score (y) 50 60 70 80 90 1 3 5 7 9

Each dot represents one student. The dashed green line shows the general trend: more hours studied tends to predict a higher test score. But which line is the best one?

Why "Least Squares"?

Many lines could be drawn through a scatterplot. The least squares regression line (LSRL) is the unique line that minimizes the sum of squared residuals: the total squared vertical distance from each point to the line.

LSRL residual

The LSRL Equation

The least squares regression line has the form:

Slope \(b\)
$$b = r \cdot \frac{s_y}{s_x}$$
The predicted change in \(y\) for each one-unit increase in \(x\).
Intercept \(a\)
$$a = \bar{y} - b\bar{x}$$
The predicted value of \(y\) when \(x = 0\).

Interpreting the Slope

The slope \(b\) tells us the direction and rate of the linear relationship. A proper interpretation always includes context:

\(b > 0\)
Positive association: as \(x\) increases, \(\hat{y}\) increases.
\(b < 0\)
Negative association: as \(x\) increases, \(\hat{y}\) decreases.
\(b = 0\)
No linear relationship: changing \(x\) does not predict a change in \(y\).

What Are Residuals?

A residual is the vertical distance between an observed data point and the regression line. It measures how far off our prediction is for that particular observation.

Positive Residual
The observed value is above the line: the model underestimated.
Negative Residual
The observed value is below the line: the model overestimated.

Reading a Residual Plot

x (Explanatory Variable) Residual 0 + − Good: Random scatter around zero

Correlation vs. Regression

Correlation \(r\) Regression (LSRL)
Purpose Measures strength and direction Predicts \(\hat{y}\) from \(x\)
Output A single number: \(-1 \leq r \leq 1\) An equation: \(\hat{y} = a + bx\)
Symmetry \(r_{xy} = r_{yx}\) Depends on which is \(x\) vs. \(y\)
Units Unitless Slope has units of \(y/x\)
Connection Slope \(b = r \cdot \dfrac{s_y}{s_x}\), so \(r\) and \(b\) always share the same sign.

The Power of \(r^2\)

The coefficient of determination \(r^2\) tells us the proportion of variability in \(y\) that is explained by the linear relationship with \(x\).

\(r^2 = 0.85\)
85% of the variation in \(y\) is explained by the linear model with \(x\).
\(r^2 = 0.15\)
Only 15% is explained: the line is a poor fit for these data.

How to Find the LSRL

1
Compute summary statistics: Find \(\bar{x}\), \(\bar{y}\), \(s_x\), \(s_y\), and the correlation \(r\).
2
Calculate the slope: \(b = r \cdot \dfrac{s_y}{s_x}\).
3
Calculate the intercept: \(a = \bar{y} - b\bar{x}\).
4
Write the equation: \(\hat{y} = a + bx\). Always use \(\hat{y}\), not \(y\).
5
Check the residual plot for patterns to validate that a linear model is appropriate.

Example: Finding the LSRL

A researcher collects data on hours of exercise per week (\(x\)) and resting heart rate (\(y\)) for 20 adults. Summary statistics:

\(\bar{x} = 4.5\)
\(s_x = 2.1\)
\(\bar{y} = 72\)
\(s_y = 8.4\)
\(r = -0.78\)
Strong negative

Example: Equation and Prediction

Interpret the slope: For each additional hour of exercise per week, the model predicts a decrease of 3.12 bpm in resting heart rate, on average.

Predict for \(x = 6\) hours:

Coefficient of determination: \(r^2 = (-0.78)^2 = 0.6084\). About 60.8% of the variability in resting heart rate is explained by the linear relationship with hours of exercise.

Example: Computing Residuals

Using our LSRL \(\hat{y} = 86.04 - 3.12x\), suppose one adult exercises 6 hours/week and has an observed resting heart rate of 70 bpm.

1
Predicted value: \(\hat{y} = 86.04 - 3.12(6) = 67.32\)
2
Residual: \(y - \hat{y} = 70 - 67.32 = \) \(+2.68\)
3
Interpretation: This person's heart rate is 2.68 bpm higher than predicted by the model. The point lies above the regression line.

Common Mistakes

✕ Confusing \(r\) and \(r^2\)
\(r = 0.7\) does not mean 70% of variation is explained. You must square it: \(r^2 = 0.49\), so 49%.
✕ Extrapolation
Predicting \(\hat{y}\) for \(x\) values far outside the data range is unreliable. The linear trend may not continue.
✕ Using \(y\) instead of \(\hat{y}\)
The regression equation predicts \(\hat{y}\) (y-hat), not \(y\). Using \(y\) implies certainty that does not exist.
✕ Residual = \(\hat{y} - y\)
The residual is always observed minus predicted: \(y - \hat{y}\). Reversing the order flips the sign.
✕ Causation from correlation
A strong \(r\) or a good-fitting line does not prove \(x\) causes \(y\). Association is not causation.

Key Formulas at a Glance

Concept Formula Interpretation
LSRL \(\hat{y} = a + bx\) Predicted \(y\) from \(x\)
Slope \(b = r \cdot \dfrac{s_y}{s_x}\) Change in \(\hat{y}\) per unit \(x\)
Intercept \(a = \bar{y} - b\bar{x}\) \(\hat{y}\) when \(x = 0\)
Residual \(e = y - \hat{y}\) Observed minus predicted
\(r^2\) \(r^2\) % of variability explained

Question 1 of 5

A regression line is given by \(\hat{y} = 12.5 + 3.2x\). What is the predicted value of \(y\) when \(x = 5\)?

Question 2 of 5

If the observed value is \(y = 45\) and the predicted value is \(\hat{y} = 48\), what is the residual?

Question 3 of 5

If \(r = 0.9\), what does \(r^2 = 0.81\) tell us?

Question 4 of 5

Given \(\bar{x} = 10\), \(\bar{y} = 50\), \(s_x = 4\), \(s_y = 12\), and \(r = 0.6\), what is the slope of the LSRL?

Question 5 of 5

A residual plot shows a clear U-shaped curve. What does this suggest?