AP STATISTICS • EXPLORING TWO-VARIABLE DATA

Least Squares Regression

The method that finds the single best-fitting line by minimizing the total squared distance from data to prediction.

Historical Context & Motivation

The quest to summarize the relationship between two quantitative variables with a single straight line is one of the oldest problems in applied mathematics. Long before modern statistics existed, astronomers and physicists needed a principled way to draw a line through noisy observations so they could predict planetary orbits, track cometary paths, and refine gravitational constants. The challenge was always the same: when data points do not fall perfectly on a line, which line among infinitely many candidates should we choose? The least squares regression method provides an elegant, mathematically optimal answer to that question—one that has endured for over two centuries and remains the backbone of modern statistical modeling.

1805
Legendre Publishes the Method
Adrien-Marie Legendre publishes Nouvelles méthodes pour la détermination des orbites des comètes, introducing the principle of minimizing the sum of squared deviations—the first formal statement of least squares.
1809
Gauss Claims Prior Use
Carl Friedrich Gauss asserts he had been using least squares since 1795, connecting the method to the normal distribution of errors in his landmark work on celestial mechanics.
1886
Galton's Regression to the Mean
Francis Galton coins the term regression while studying the heights of parents and children, noting that extreme values tend to regress toward the average in the next generation.
1896
Pearson Formalizes Correlation
Karl Pearson develops the product-moment correlation coefficient r, giving regression a direct link to the strength and direction of linear association.
1900s–Present
Computational Revolution
Electronic computers and modern software (TI-84, JMP, R, Python) make least squares regression accessible to every student and researcher, enabling instant computation even for massive data sets.

The central question driving this entire history is deceptively simple: given n paired observations (x, y), how do we find the slope and intercept of a line ŷ = a + bx that best captures the linear trend in the data? The least squares criterion—minimize the sum of the squared vertical distances from each point to the line—turns that qualitative question into one with a unique, closed-form solution.

Core Principles & Definitions

Before computing any regression line, it is essential to internalize the foundational ideas that make least squares both powerful and interpretable. Each principle below connects directly to how the AP Statistics exam frames regression questions—from identifying explanatory and response variables to interpreting the slope in context.

1

Explanatory & Response Variables

The explanatory variable (x) is the predictor; the response variable (y) is the outcome. Regression models ŷ as a linear function of x, and the direction of prediction matters.
2

Residuals

A residual is the vertical distance from an observed point to the regression line: residual = y − ŷ. Positive residuals lie above the line; negative residuals lie below it.
3

Minimizing Σ(residual²)

The least squares criterion chooses the line that makes Σ(yᵢ − ŷᵢ)² as small as possible. Squaring the residuals penalizes large deviations more heavily and ensures the total is always non-negative.
4

The Line Passes Through (x̄, ȳ)

A critical algebraic consequence: the least squares regression line (LSRL) always passes through the point of means (x̄, ȳ). This anchors the line to the center of the data cloud.
5

r² — Coefficient of Determination

The value tells us the proportion of variability in y that is explained by the linear relationship with x. It ranges from 0 (no linear fit) to 1 (perfect linear fit).
KEY TAKEAWAY
Think of the LSRL like a tightly stretched rubber band running through a scatter of push-pins on a board. If every pin exerts a pull proportional to the square of its vertical distance from the band, the equilibrium position of the band is exactly the least squares line—it balances the total squared tension. That physics-style analogy explains why the line is unique: there is only one equilibrium.

Visual Explanation — Scatter Plot & LSRL

Each cyan dot represents an observed (x, y) pair. The violet line is the LSRL. The dashed red segments show residuals—the vertical gaps between each observed y-value and its predicted ŷ. The LSRL is the unique line that minimizes the sum of the squares of these red segments.

Notice how some residual segments are longer than others. Points far from the line contribute disproportionately to the sum of squared residuals because squaring amplifies large deviations. The least squares algorithm, in effect, compromises: it allows slightly larger residuals where many points cluster close to the line in order to pull the line closer to the most deviant observations. This balancing act is why the LSRL passes through (x̄, ȳ)—it anchors itself at the center of the data cloud and rotates to minimize total squared error.

Mathematical Framework

The LSRL is written ŷ = a + bx, where b is the slope and a is the y-intercept. The formulas below are derived by taking partial derivatives of the sum of squared residuals with respect to a and b, setting each to zero, and solving the resulting system of two linear equations (the normal equations).

SLOPE OF THE LSRL
b = r × (s_y / s_x)
where r is the correlation coefficient, sy is the standard deviation of y, and sx is the standard deviation of x. The slope inherits the sign of r and rescales it by the ratio of spread in y to spread in x.
Y-INTERCEPT OF THE LSRL
a = ȳ − b × x̄
This formula guarantees that the LSRL passes through the point (x̄, ȳ). It is derived directly from substituting the mean point into the line equation ŷ = a + bx.
COEFFICIENT OF DETERMINATION
r² = 1 − (SSresid / SStotal)
SSresid = Σ(yᵢ − ŷᵢ)² is the residual sum of squares; SStotal = Σ(yᵢ − ȳ)² is the total sum of squares. Equivalently, r² equals the square of the correlation coefficient r. It represents the fraction of total variability in y accounted for by the linear model.
STANDARD DEVIATION OF RESIDUALS
s = √[ Σ(yᵢ − ŷᵢ)² / (n − 2) ]
The denominator is n − 2 because two parameters (a and b) have been estimated. This value s measures the typical size of a residual—the typical vertical distance an observed y falls from the LSRL.
📝 AP Exam Tip
When interpreting slope on the AP exam, always include context: "For each additional [unit of x], the predicted [y variable] changes by [b] [units of y]." Graders award separate points for the word predicted (or estimated) and for naming both variables.

Residual Analysis & Assessing Fit

Computing the LSRL is only half the story; we must also evaluate whether a linear model is appropriate. The primary diagnostic tool is the residual plot, which graphs residuals (y − ŷ) on the vertical axis against either x or ŷ on the horizontal axis. A well-behaved residual plot shows random scatter with no discernible pattern. Conversely, a curved pattern in the residual plot signals that a straight line is not the best model for the data and that a nonlinear transformation or a polynomial model should be considered.

Left: a good residual plot with random scatter about the zero line, indicating a linear model is appropriate. Right: a problematic residual plot showing a curved pattern, indicating the relationship is not linear and a different model or variable transformation should be considered.

Beyond curvature, watch for heteroscedasticity—a fanning pattern where the spread of residuals increases (or decreases) as x increases. This condition does not invalidate the regression equation itself, but it signals that predictions are less reliable at one end of the x-range than the other. On the AP exam, describing what you see in a residual plot (pattern versus no pattern, increasing spread versus constant spread) is essential for earning full credit on free-response questions about model adequacy.

  • No pattern → linear model is appropriate
  • Curved pattern → nonlinear relationship; consider transforming x, y, or both
  • Fan shape → non-constant variance (heteroscedasticity); predictions less reliable at the wider end
  • One or two extreme residuals → potential outliers or influential points; investigate their effect on slope and r²

Worked Example

A researcher records the number of hours eight students spent studying for a statistics exam and their resulting exam scores. Use the summary statistics to find the LSRL, interpret the slope and y-intercept in context, and calculate r².

Summary statistics for the study-hours data
Summary StatisticValue
n8
x̄ (mean study hours)5.0
ȳ (mean exam score)72.0
sₓ2.4
s_y10.0
r0.92
Finding and Interpreting the LSRL
1
Step 1 — Compute the Slope (b)Use the formula b = r × (sy / sx). Substituting: b = 0.92 × (10.0 / 2.4) = 0.92 × 4.1667 ≈ 3.833.
b ≈ 3.833
2
Step 2 — Compute the Y-Intercept (a)Use a = ȳ − b × x̄. Substituting: a = 72.0 − 3.833 × 5.0 = 72.0 − 19.167 ≈ 52.833.
a ≈ 52.833
3
Step 3 — Write the LSRL EquationCombining the slope and intercept: ŷ = 52.833 + 3.833x, where x = study hours and ŷ = predicted exam score.
ŷ = 52.833 + 3.833x
4
Step 4 — Interpret the Slope in ContextFor each additional hour of studying, the predicted exam score increases by approximately 3.833 points. The word 'predicted' is critical—the LSRL gives estimates, not certainties.
5
Step 5 — Interpret the Y-Intercept in ContextWhen study hours = 0, the predicted exam score is approximately 52.833. Whether this interpretation is meaningful depends on whether x = 0 is within the range of observed data. Here it may be an extrapolation and should be stated with caution.
6
Step 6 — Calculate and Interpret r²r² = (0.92)² = 0.8464. Interpretation: approximately 84.6% of the variability in exam scores is explained by the linear relationship with study hours.
r² ≈ 0.846 — 84.6% of variability explained

Strengths, Limitations & Common Pitfalls

Strengths and limitations of least squares regression
StrengthsLimitations
Closed-form solution—fast and unique; always yields a single best lineOnly captures linear associations; curved relationships require transformation
Interpretable coefficients: slope and intercept have direct contextual meaningSensitive to outliers and influential points, which can dramatically shift the line
r² provides a clear measure of explanatory powerDoes not establish causation—association ≠ causation
Residual analysis offers a visual check on model adequacyExtrapolation beyond the observed x-range is unreliable
Foundation for more complex models (multiple regression, ANOVA)Assumes homoscedasticity (constant variance of residuals) for inference
COMMON AP EXAM PITFALLS
Three errors appear repeatedly on AP Statistics exams. First, students forget to say predicted when interpreting slope—this single word distinguishes a regression interpretation from a deterministic statement. Second, students confuse r with ; remember that r measures direction and strength of linear association, while r² measures the proportion of variability explained. Third, students extrapolate the regression line far beyond the data and make unwarranted predictions—like predicting exam scores for 50 hours of study when the data only goes up to 10.

Connection to Inference & Advanced Topics

The LSRL you compute from sample data is an estimate of the true population regression line β₀ + β₁x. In the inference unit of AP Statistics, you will test whether the true slope β₁ is significantly different from zero—a t-test for the slope—and construct confidence intervals for β₁. These procedures rely on the same residual standard deviation s introduced in Section 4 and require that residuals be approximately normal with constant variance. Understanding the mechanics of least squares now will make the inferential extension feel natural rather than opaque.

Descriptive LSRL versus inference for regression
TopicDescriptive LSRL (This Lesson)Inference for Regression (Later)
GoalSummarize the linear relationship in a sampleTest whether the population slope β₁ differs from 0
Key statisticb (sample slope), r, r²t = b / SE_b with df = n − 2
ConditionsLinearity (check residual plot)Linearity, independence, normality of residuals, equal variance
OutputEquation ŷ = a + bx, r², sp-value, confidence interval for β₁

Beyond simple linear regression, the same least squares principle extends to multiple regression (more than one explanatory variable), polynomial regression (fitting curves such as ŷ = a + b₁x + b₂x²), and generalized linear models. Every one of these more advanced techniques builds on the intuition you develop here: minimize a measure of prediction error to find the best-fitting model.

Practice Problems

1
A least squares regression line is fit to a set of data. Which of the following must always be true?
2
For a data set with x̄ = 10, ȳ = 50, sx = 3, sy = 12, and r = −0.80, what is the equation of the LSRL?
3
The equation of the LSRL for predicting a car's fuel efficiency (miles per gallon) from its weight (thousands of pounds) is ŷ = 48.7 − 8.1x. A car that weighs 3.5 thousand pounds gets 22 mpg. What is the residual for this car, and what does it mean in context?
PROBLEM 4APPLIED
A marine biologist studying coral reef health collected data on water temperature (°C) and coral coverage (% of reef area) at 25 sites. Computer output is shown below: Predictor Coef SE Coef T P Constant 118.5 6.8 17.43 0.000 Temperature −3.20 0.27 −11.85 0.000 s = 4.12 R-Sq = 85.9% R-Sq(adj) = 85.3% (a) Write the equation of the least-squares regression line. Define any variables used. (b) Interpret the slope in context. (c) Interpret r² in context. (d) A site has a water temperature of 30°C. Calculate the predicted coral coverage. Then explain why using this model to predict coral coverage at a temperature of 45°C would be problematic.
PROBLEM 5CRITICAL THINKING
A statistics student claims that because the correlation between hours of TV watched per day and GPA is r = −0.65, watching more TV causes GPA to drop. The student also notes that the LSRL is ŷ = 3.8 − 0.15x, and since r² = 0.4225, the model explains a large amount of variability. (a) Identify and explain the flaw in the student's causal claim. (b) Give a plausible confounding variable and explain how it could produce the observed negative association without TV directly causing lower GPA. (c) The student interprets r² = 0.4225 as meaning the model 'explains most of the variability in GPA.' Evaluate this claim. (d) Using the LSRL, compute the predicted GPA for a student who watches 6 hours of TV per day and the residual if that student's actual GPA is 3.1. Interpret the residual.

Lesson Summary

The least squares regression line (LSRL) is the unique line ŷ = a + bx that minimizes the sum of squared residuals Σ(yᵢ − ŷᵢ)². The slope b = r × (s_y / s_x) quantifies the predicted change in y per unit increase in x, and the y-intercept a = ȳ − bx̄ anchors the line through the point of means (x̄, ȳ). The coefficient of determination r² tells us the proportion of variability in the response variable explained by the linear model.

Always check the residual plot for patterns: random scatter supports a linear model, while curvature or fanning signals inadequacy. Remember that correlation does not imply causation, extrapolation beyond the observed data is risky, and influential points can dramatically alter the LSRL. When interpreting slope on the AP exam, always include the word predicted, name both variables in context, and state the direction and magnitude of the change.

Varsity Tutors • AP Statistics • Least Squares Regression