AP · Statistics · Linear Regression

The Least-Squares Regression Line

14 min readUpdated November 30, 2026FreeAP Statistics, Exploring Two-Variable Data

The least-squares regression line y^=a+bx\hat{y} = a + bx is the straight line that best predicts a response yy from an explanatory variable xx, and you can find it from data or from five summary statistics. Its slope is b=rsysxb = r\dfrac{s_y}{s_x}, and it always passes through (xˉ,yˉ)(\bar{x}, \bar{y}). You interpret the slope and intercept in context, predict only within the range of the data, and read aa and bb straight off computer output.

Quick check

  1. A line is y=4+2.5xy = 4 + 2.5x. What is yy when x=6x = 6?Show answerHide answer

    y=4+2.5(6)=19y = 4 + 2.5(6) = 19.

  2. Two variables have a strong positive correlation. Will the slope of the regression line be positive or negative?Show answerHide answer

    Positive: the slope always has the same sign as rr, because b=rsysxb = r\dfrac{s_y}{s_x} and standard deviations are positive.

Know these already? Jump to the practice questions

What you'll be able to do

  • Calculate the least-squares regression line from summary statistics or from data.
  • Interpret the slope and the y-intercept in context.
  • Use the line to predict, and explain why extrapolation is risky.
  • Identify the equation of the line from computer regression output.

Key terms

Least-squares regression line

The line y^=a+bx\hat{y} = a + bx that makes the sum of the squared vertical distances from the points to the line as small as possible.

In plain English
The line that fits the points best, judged by how far the actual yy-values are from the predicted ones.
Don't write
y=a+bxy = a + bx; the hat shows that y^\hat{y} is a predicted value.

Slope

The predicted change in yy for each increase of 1 unit in xx.

In plain English
How much the prediction moves when xx goes up by one.
Don't write
"yy increases by bb"; it is the predicted (average) yy that changes.

Extrapolation

Using the line to predict for an xx-value outside the range of the data used to fit it.

In plain English
Predicting where you have no data.
Don't write
"the prediction is reliable because the line fits well"; a good fit inside the data says nothing outside it.

What makes the line "least squares"?

For each point, the vertical distance from the point to the line is y−y^y - \hat{y}, the actual value minus the predicted value. These are called residuals and have their own note (Residuals, Residual Plots and r²). The least-squares line is the one line that makes the sum of the squared residuals, ∑(y−y^)2\sum (y - \hat{y})^2, as small as possible.

The notation matters. y^\hat{y} ("y-hat") is a predicted value, and aa is the y-intercept: the predicted yy when x=0x = 0.

Two facts follow from the least-squares criterion. The line always passes through the point of means (xˉ,yˉ)(\bar{x}, \bar{y}), and its slope has the same sign as the correlation.

Check yourself

A least-squares line has xˉ=10\bar{x} = 10 and yˉ=35\bar{y} = 35. What does the line predict at x=10x = 10?
Show answerHide answer

y^=35\hat{y} = 35, because the line always passes through (xˉ,yˉ)(\bar{x}, \bar{y}).

How do you find the line from summary statistics?

On the formula sheet:

b=rsysx,yˉ=a+bxˉb = r\frac{s_y}{s_x}, \qquad \bar{y} = a + b\bar{x}

Find the slope first, then rearrange the second formula for a=yˉ−bxˉa = \bar{y} - b\bar{x}.

Suppose, for 30 hypothetical students, hours studied has mean 4.5 and standard deviation 1.8, exam score has mean 76 and standard deviation 9, and r=0.72r = 0.72. Then b=0.72×91.8=3.6b = 0.72 \times \dfrac{9}{1.8} = 3.6 and a=76−3.6(4.5)=59.8a = 76 - 3.6(4.5) = 59.8, so y^=59.8+3.6x\hat{y} = 59.8 + 3.6x.

The slope formula says the line rises rr standard deviations in yy for every standard deviation in xx. So a weaker correlation gives a flatter line, even with the same spreads.

With raw data, a graphing calculator's linear regression gives aa and bb directly; state the equation with the variables named.

Key idea

Slope first, b=rsysxb = r\dfrac{s_y}{s_x}, then a=yˉ−bxˉa = \bar{y} - b\bar{x}.

Check yourself

If r=0.5r = 0.5, sx=2s_x = 2 and sy=6s_y = 6, what is the slope?
Show answerHide answer

b=0.5×62=1.5b = 0.5 \times \dfrac{6}{2} = 1.5.

How do you interpret the slope and the intercept?

Use a sentence template, and always name the variables and units.

  • Slope: "For each additional 1 [unit of xx], the predicted [yy] increases (or decreases) by ∣b∣|b| [units of yy]." For the study line: for each additional hour studied, the predicted exam score increases by 3.6 points.
  • Intercept: "When [xx] is 0, the predicted [yy] is aa." For the study line: a student who studies 0 hours has a predicted score of 59.8 points.

The intercept only has a sensible meaning if x=0x = 0 is a reasonable value inside or near the data. A car that weighs 0 pounds does not exist, so in that context you say the intercept has no practical meaning.

Examiner's eye

Credit is lost when the slope is stated as a certain change. Say "predicted" or "on average", and name both variables with units.

Check yourself

The line y^=6−0.8x\hat{y} = 6 - 0.8x predicts hours of free time from hours of homework. Interpret the slope.
Show answerHide answer

For each additional hour of homework, the predicted free time decreases by 0.8 hours.

How do you predict, and when is it risky?

To predict, substitute the xx-value into the line. For 6 hours of study, y^=59.8+3.6(6)=81.4\hat{y} = 59.8 + 3.6(6) = 81.4 points.

A prediction is only trustworthy within the range of xx-values used to fit the line. Outside that range is extrapolation: the pattern may bend, level off or stop, so the prediction can be badly wrong, even impossible.

Check yourself

A line was fitted to cars weighing 1.8 to 4.6 thousand pounds. Is a prediction for 4.0 thousand pounds extrapolation?
Show answerHide answer

No. 4.0 is inside the range of the data, so the prediction is reasonable.

How do you read computer regression output?

Software prints a table. The row labeled "Constant" (or "Intercept") gives aa in the "Coef" (coefficient) column; the row named for the explanatory variable gives bb. Other columns, such as "SE Coef", belong to inference for slope, a later topic.

PredictorCoefSE Coef
Constant47.930.93
Weight−6.670.28

This hypothetical output, for car weight (thousands of pounds) and fuel efficiency (miles per gallon), gives mpg^=47.93−6.67(weight)\widehat{\text{mpg}} = 47.93 - 6.67(\text{weight}).

Check yourself

In that output, what is the slope, and what is its sign telling you?
Show answerHide answer

b=−6.67b = -6.67: heavier cars have lower predicted fuel efficiency.

Worked example 1: From summary statistics to a prediction

Question: For 25 hypothetical trees, trunk diameter has mean 12 inches and standard deviation 4 inches, height has mean 60 feet and standard deviation 10 feet, and r=0.8r = 0.8. (a) Find the least-squares regression line for predicting height from diameter. (b) Interpret the slope. (c) Predict the height of a tree with diameter 15 inches.

What tells you the method

Summary statistics and "least-squares regression line" mean b=rsysxb = r\dfrac{s_y}{s_x}, then a=yˉ−bxˉa = \bar{y} - b\bar{x}.

  1. Step 1: Slope.

    b=0.8×104=2b = 0.8 \times \dfrac{10}{4} = 2.

    Why

    yy is height, so sy=10s_y = 10 goes on top.

  2. Step 2: Intercept.

    a=60−2(12)=36a = 60 - 2(12) = 36, so height^=36+2(diameter)\widehat{\text{height}} = 36 + 2(\text{diameter}).

    Why

    The line passes through (xˉ,yˉ)=(12,60)(\bar{x}, \bar{y}) = (12, 60).

  3. Step 3: Interpret and predict.

    For each additional inch of diameter, the predicted height increases by 2 feet. At 15 inches, height^=36+2(15)=66\widehat{\text{height}} = 36 + 2(15) = 66 feet.

    Why

    The slope sentence names both variables and units, and 15 inches is close to the mean diameter, so it is not extrapolation.

Check it

15 is 0.75 standard deviations above the mean diameter, and 6666 is 0.6=0.8×0.750.6 = 0.8 \times 0.75 standard deviations above the mean height, as the slope formula predicts.

Answer

(a) y^=36+2x\hat{y} = 36 + 2x, so a=36a = 36 and b=2b = 2. (b) For each additional inch of diameter, predicted height increases by 2 feet. (c) 6666 feet.

Worked example 2: Using computer output

Question: Hypothetical regression output for 12 cars weighing from 1.8 to 4.6 thousand pounds gives Constant 47.93 and Weight −6.67, with fuel efficiency in miles per gallon. (a) Write the equation. (b) Predict the fuel efficiency of a car weighing 3.2 thousand pounds. (c) Explain why predicting for a 7.5-thousand-pound truck is unwise. (d) Interpret the intercept, if it is meaningful.

What tells you the method

"Constant" gives aa and the variable's row gives bb; a weight outside 1.8 to 4.6 is extrapolation.

  1. Step 1: Equation.

    mpg^=47.93−6.67(weight)\widehat{\text{mpg}} = 47.93 - 6.67(\text{weight}).

    Why

    The Coef column holds aa and bb.

  2. Step 2: Predict.

    47.93−6.67(3.2)=26.5947.93 - 6.67(3.2) = 26.59 miles per gallon.

    Why

    3.2 lies inside the data's range, so the prediction is reasonable.

  3. Step 3: Extrapolation.

    At 7.5, the line gives 47.93−6.67(7.5)=−2.1047.93 - 6.67(7.5) = -2.10 miles per gallon, which is impossible.

    Why

    7.5 is far outside the weights in the data, and the linear pattern cannot continue forever.

  4. Step 4: Intercept.

    It would be the predicted efficiency of a car weighing 0 pounds, which cannot exist, so it has no practical meaning here.

    Why

    x=0x = 0 is far outside the data.

Check it

The slope is negative, and the 3.2 prediction (26.59) is lower than the intercept, as it should be for a heavier car.

Answer

(a) y^=47.93−6.67x\hat{y} = 47.93 - 6.67x (b) 26.5926.59 miles per gallon (c) 7.5 is far outside 1.8 to 4.6, and the prediction, −2.10-2.10 miles per gallon, is impossible. (d) No practical meaning.

Your turn

Question: For five hypothetical players, practice hours has xˉ=3\bar{x} = 3 and sx=1.5811s_x = 1.5811; free throws made has yˉ=11\bar{y} = 11 and sy=2.7386s_y = 2.7386; r=0.9238r = 0.9238. Find the least-squares regression line.

  1. Step 1:

    b=0.9238×2.73861.5811=1.6b = 0.9238 \times \dfrac{2.7386}{1.5811} = 1.6.

  2. Step 2: Your go: use the point of means to find aa, then write the equation.

Show the full solutionHide the solution

a=11−1.6(3)=6.2a = 11 - 1.6(3) = 6.2, so free throws^=6.2+1.6(hours)\widehat{\text{free throws}} = 6.2 + 1.6(\text{hours}).

Answer: y^=6.2+1.6x\hat{y} = 6.2 + 1.6x, so a=6.2a = 6.2 and b=1.6b = 1.6.

Traps

Trap

Writing the slope as b=rsxsyb = r\dfrac{s_x}{s_y}.

It seems right because xx comes first in the line. But the slope is the change in yy per unit of xx, so the yy spread goes on top: b=rsysxb = r\dfrac{s_y}{s_x}.

Check yourself

With r=0.6r = 0.6, sx=5s_x = 5 and sy=15s_y = 15, which slope is right, 0.20.2 or 1.81.8?
Show answerHide answer

1.8=0.6×1551.8 = 0.6 \times \dfrac{15}{5}. The value 0.2 inverts the ratio.

Trap

Trusting a prediction because rr is close to 1.

It seems right because a strong fit looks reliable everywhere. But the fit was only checked inside the data's range; outside it, extrapolation can give nonsense.

Check yourself

A line fitted to children aged 3 to 12 predicts a 40-year-old's height. Why is that unwise?
Show answerHide answer

Age 40 is far outside 3 to 12, and growth stops in adulthood, so the linear pattern does not continue.

What's examined

Regression lines are tested on the AP® Statistics exam (Two-variable data), in multiple-choice and free-response questions. Expect Calculate, Interpret, Identify and Explain: find the line from summary statistics, read it from computer output, interpret slope and intercept in context, and judge a prediction. The formulas y^=a+bx\hat{y} = a + bx, yˉ=a+bxˉ\bar{y} = a + b\bar{x} and b=rsysxb = r\dfrac{s_y}{s_x} are on the formula sheet. Residuals and r² come next: see the note on Residuals, Residual Plots and r².

Practice questions

  1. Recall Which point is always on the least-squares regression line?
    • A) (0,0)(0, 0)
    • B) (xˉ,yˉ)(\bar{x}, \bar{y})
    • C) (sx,sy)(s_x, s_y)
    • D) The first data point
Show answer

Answer: B) (xˉ,yˉ)(\bar{x}, \bar{y})

Marking points:

  • yˉ=a+bxˉ\bar{y} = a + b\bar{x}, so the point of means is on the line.
  • A holds only if the intercept is 0. C mixes spreads with values. D is on the line only by chance.
  1. Apply For hypothetical summer days, temperature (°F) has mean 70 and standard deviation 8, iced drinks sold at a café has mean 150 and standard deviation 24, and r=0.85r = 0.85. Find the least-squares regression line for predicting drinks sold from temperature.
Show answer

Answer: y^=−28.5+2.55x\hat{y} = -28.5 + 2.55x, so a=−28.5a = -28.5 and b=2.55b = 2.55.

Marking points:

  • b=0.85×248=2.55b = 0.85 \times \dfrac{24}{8} = 2.55.
  • a=150−2.55(70)=−28.5a = 150 - 2.55(70) = -28.5.
  1. Apply For hypothetical puppies, weight^=520+85(age)\widehat{\text{weight}} = 520 + 85(\text{age}), with weight in grams and age in weeks. Which is the correct interpretation of 85?
    • A) Every puppy gains exactly 85 grams each week.
    • B) A newborn puppy weighs 85 grams.
    • C) For each additional 85 grams, predicted age increases by 1 week.
    • D) For each additional week of age, predicted weight increases by 85 grams.
Show answer

Answer: D) For each additional week of age, predicted weight increases by 85 grams.

Marking points:

  • The slope is the predicted change in yy (weight) for each 1-unit increase in xx (age).
  • A drops "predicted". B confuses the slope with the intercept, 520. C swaps the roles of the variables.
  1. Apply Hypothetical regression output for minutes of daily exercise (xx) and resting heart rate in beats per minute (yy) shows Constant 78.6 and Exercise −0.24. Predict the resting heart rate for 45 minutes of daily exercise.
Show answer

Answer: The predicted resting heart rate is 67.867.8 beats per minute.

Marking points:

  • y^=78.6−0.24x\hat{y} = 78.6 - 0.24x.
  • y^=78.6−0.24(45)=78.6−10.8=67.8\hat{y} = 78.6 - 0.24(45) = 78.6 - 10.8 = 67.8.
  1. Recall A line was fitted to data on children aged 2 to 10. Using it to predict the height of a 30-year-old is called what?
    • A) Extrapolation
    • B) Interpolation
    • C) A residual
    • D) Correlation
Show answer

Answer: A) Extrapolation

Marking points:

  • Predicting outside the range of xx in the data is extrapolation.
  • B predicts inside the range. C is y−y^y - \hat{y} for a data point. D measures linear strength.
  1. Exam-style Hypothetical regression output for hours of study (xx) and quiz score (yy):
PredictorCoefSE Coef
Constant48.303.12
Study hours1.920.47

Which is the equation of the least-squares line?

  • A) y^=1.92+48.30x\hat{y} = 1.92 + 48.30x
  • B) y^=48.30+0.47x\hat{y} = 48.30 + 0.47x
  • C) y^=48.30+1.92x\hat{y} = 48.30 + 1.92x
  • D) y^=3.12+0.47x\hat{y} = 3.12 + 0.47x
Show answer

Answer: C) y^=48.30+1.92x\hat{y} = 48.30 + 1.92x

Marking points:

  • The Constant row's Coef is a=48.30a = 48.30; the Study hours row's Coef is b=1.92b = 1.92.
  • A swaps aa and bb. B takes the slope from the SE Coef column. D uses the SE Coef column for both.
  1. Exam-style For 20 hypothetical apartments, floor area (square feet) has mean 800 and standard deviation 150, monthly heating cost (dollars) has mean 90 and standard deviation 18, and r=0.75r = 0.75. The areas range from 500 to 1100 square feet. (a) Find the least-squares regression line. (b) Predict the heating cost for 1000 square feet. (c) Should you use the line for a 3000-square-foot house? Explain.
Show answer

Answer: (a) y^=18+0.09x\hat{y} = 18 + 0.09x, so a=18a = 18 and b=0.09b = 0.09. (b) 108108 dollars. (c) No: 3000 is far outside 500 to 1100 square feet, so it would be extrapolation.

Marking points:

  • b=0.75×18150=0.09b = 0.75 \times \dfrac{18}{150} = 0.09; a=90−0.09(800)=18a = 90 - 0.09(800) = 18.
  • y^=18+0.09(1000)=108\hat{y} = 18 + 0.09(1000) = 108.
  • The explanation names extrapolation and the data's range.

Key points

Recall, then reveal

Say the main points from memory first, then check them.

Show key pointsHide key points
  • The least-squares line minimizes the sum of squared vertical distances and passes through (xˉ,yˉ)(\bar{x}, \bar{y}).
  • Find b=rsysxb = r\dfrac{s_y}{s_x} first, then a=yˉ−bxˉa = \bar{y} - b\bar{x}.
  • Slope: the predicted change in yy per 1-unit increase in xx, in context with units; intercept: the prediction at x=0x = 0, if that makes sense.
  • Predict only inside the range of the data; outside it is extrapolation.
  • In computer output, "Constant" gives aa and the explanatory variable's row gives bb.

Keep learning

Explore AP Statistics tutoring →

View the full Statistics syllabus →

More in this unit

Exploring Two-Variable Data

All Linear Regression notes

Part of Novark's AP Statistics notes