Least-Squares Regression Equation — Formula & Examples
Least-Squares Regression Equation
An equation of a particular
form (linear, quadratic, exponential, etc.) that fits a set of
paired data as closely as possible. The equation must be chosen
so that the sum of the squares of the residuals is made as small
as possible.
Step 5: Write the least-squares regression equation.
y^=1.9+0.7x
Answer: The least-squares regression equation is ŷ = 1.9 + 0.7x. For every 1-unit increase in x, the predicted y increases by 0.7.
Another Example
This example focuses on residuals and the sum of squares, demonstrating what 'least squares' actually minimizes rather than just computing the equation.
Problem: Using the regression equation ŷ = 1.9 + 0.7x from the first example, compute all the residuals and verify that the sum of squared residuals is minimized (i.e., show the value that the method minimizes).
Step 1: Compute the predicted value for each data point using ŷ = 1.9 + 0.7x.
y^1=2.6,y^2=3.3,y^3=4.0,y^4=4.7,y^5=5.4
Step 2: Calculate each residual: residual = observed y − predicted ŷ.
Step 4: No other line of the form ŷ = b₀ + b₁x produces a sum of squared residuals smaller than 2.50. This is the quantity the least-squares method minimizes.
mini=1∑n(yi−y^i)2=2.50
Answer: The sum of squared residuals is 2.50. Any other straight line through these data would give a larger value.
Frequently Asked Questions
What is the difference between a least-squares regression equation and a least-squares regression line?
A least-squares regression line is specifically a straight line (ŷ = b₀ + b₁x). A least-squares regression equation is a broader term that includes any model form—linear, quadratic, exponential, and so on—as long as the parameters are chosen to minimize the sum of squared residuals. Every least-squares regression line is a least-squares regression equation, but not every least-squares regression equation is a line.
Why do we square the residuals instead of just adding them?
If you simply add the residuals without squaring, positive and negative errors cancel out, often giving a sum near zero even for a terrible fit. Squaring makes all residuals positive and also penalizes larger errors more heavily, which pushes the best-fit equation closer to the bulk of the data. This approach also leads to clean, closed-form formulas for the slope and intercept.
When should you use a least-squares regression equation?
Use it whenever you have paired data and want to model the relationship between an explanatory variable and a response variable. It is most common in statistics courses for prediction—estimating a y-value from a given x-value. Before fitting, always check a scatterplot to see whether a linear, quadratic, or other model shape is appropriate.
Least-Squares Regression Equation vs. Least-Squares Regression Line
Least-Squares Regression Equation
Least-Squares Regression Line
Definition
Any equation form (linear, quadratic, exponential, etc.) fit by minimizing squared residuals
Specifically a linear equation ŷ = b₀ + b₁x fit by minimizing squared residuals
Formula forms
ŷ = b₀ + b₁x, ŷ = ax² + bx + c, ŷ = abˣ, etc.
ŷ = b₀ + b₁x only
When to use
When the scatterplot suggests any particular curve or pattern
When the scatterplot shows a roughly linear trend
Complexity
May require more parameters and technology to compute
Slope and intercept computed with standard formulas or a calculator
Why It Matters
The least-squares regression equation is central to AP Statistics, college introductory statistics, and data science. You use it every time you draw a trend line on a scatterplot or predict values from data. Understanding how it works also builds the foundation for more advanced topics like multiple regression and machine learning models.
Common Mistakes
Mistake: Swapping x and y when computing the slope, which gives the regression of x on y instead of y on x.
Correction: Always place the response variable (the one you want to predict) as y and the explanatory variable as x. The regression of y on x is not the same equation as the regression of x on y.
Mistake: Using the regression equation to predict far outside the range of the original x-values (extrapolation).
Correction: The least-squares equation is only reliable within (or near) the range of x-values in your data. Predicting well beyond that range assumes the same pattern continues, which may not be true.