Scribe logoScribeNotes & practice
Sign inStart free
  1. Notes
  2. ›AP Statistics
  3. ›5 Regression Analysis
  4. ›5.5 Least-squares regression

AP Statistics · Unit 5 · Regression Analysis

5.5 Least-squares regression

Describe how the least-squares line is chosen, explain what least-squares means, and find the line from formulas or technology.

  • 4 min read
  • 5 parts
  • 10 questions
  • Draft
Start a Quick 5 on this topic→Jump to the 10 questions
1/5A rule is needed to choose the best-fitting line
  1. 1A rule is needed to choose the best-fitting line
  2. 2The least-squares line minimizes the sum of squared residuals
  3. 3The slope and intercept follow from summary statistics
  4. 4Technology finds the line faster than hand calculation
  5. 5The line passes through the means and balances residuals
  6. Check your recall
  7. Practice: 10 questions
1

Part 1 of 5: A rule is needed to choose the best-fitting line

Residuals show how far a line misses each point. Two different lines through the same scatterplot give two different sets of residuals. We need one rule that picks a single best line.

Simply adding the residuals does not work, because positive and negative values cancel. A poor line can still have residuals that sum to zero. A flat line at the mean of yyy does exactly that.

A better rule must treat misses above and below the line alike. It should also work for any data set.

Part 1 done

2

Part 2 of 5: The least-squares line minimizes the sum of squared residuals

Squaring each residual solves the cancellation problem. Every squared value is positive, and larger misses count for much more. Adding the squares gives the sum of squared residuals, written ∑(y−y^)2\sum(y-\hat{y})^2∑(y−y^​)2.

Among all straight lines, one gives the smallest total. We call it the least-squares regression line. Here least refers to that total, not to any single residual.

Squaring also means one large miss costs more than several small ones. The line therefore works hard to avoid big residuals. This is why the method is named after squares.

Worked example

Compare two lines

Five students have study times x=1,2,3,4,5x=1,2,3,4,5x=1,2,3,4,5 hours and quiz scores y=2,4,5,4,5y=2,4,5,4,5y=2,4,5,4,5 points. Compare the lines y^=2.2+0.60x\hat{y}=2.2+0.60xy^​=2.2+0.60x and y^=2.0+0.70x\hat{y}=2.0+0.70xy^​=2.0+0.70x using the sum of squared residuals.
  1. 1
    Line A predictions: 2.8, 3.4, 4.0, 4.6, 5.2. Residuals: −0.8,+0.6,+1.0,−0.6,−0.2-0.8, +0.6, +1.0, -0.6, -0.2−0.8,+0.6,+1.0,−0.6,−0.2.
  2. 2
    Line A total: 0.64+0.36+1.00+0.36+0.04=2.400.64+0.36+1.00+0.36+0.04=2.400.64+0.36+1.00+0.36+0.04=2.40.
  3. 3
    Line B predictions: 2.7, 3.4, 4.1, 4.8, 5.5. Residuals: −0.7,+0.6,+0.9,−0.8,−0.5-0.7, +0.6, +0.9, -0.8, -0.5−0.7,+0.6,+0.9,−0.8,−0.5.
  4. 4
    Line B total: 0.49+0.36+0.81+0.64+0.25=2.550.49+0.36+0.81+0.64+0.25=2.550.49+0.36+0.81+0.64+0.25=2.55.

Answer: Line A has the smaller total, 2.40 points22.40\,\mathrm{points^2}2.40points2 against 2.55 points22.55\,\mathrm{points^2}2.55points2, so it fits better by the least-squares rule.

Key terms · tap one for its definition

sum of squared residuals

The sum of squared residuals is the total ∑(y−y^)2\sum(y-\hat{y})^2∑(y−y^​)2 found by squaring every residual and adding the results.

least-squares regression line

The least-squares regression line is the unique line y^=a+bx\hat{y}=a+bxy^​=a+bx that makes the sum of squared residuals as small as possible for the data.

Part 2 done

Quick check

One question on the part you just read

Easy

Identify the quantity that the least-squares regression line minimizes.
Show answer and explanation

Answer: A · Worked explanation

The least-squares line makes the sum of squared residuals as small as possible. The plain sum of residuals is not what is minimized, since it can be zero for many different lines. The largest single residual is a different criterion that least-squares does not use.
3

Part 3 of 5: The slope and intercept follow from summary statistics

You do not have to test every possible line. The slope is b=rsysxb=r\frac{s_y}{s_x}b=rsx​sy​​. Here rrr is the correlation, a measure of linear association. The values sxs_xsx​ and sys_ysy​ are the sample standard deviations of xxx and yyy. Slope has units of yyy per unit of xxx, which is why the ratio sysx\frac{s_y}{s_x}sx​sy​​ appears.

The intercept is a=yˉ−bxˉa=\bar{y}-b\bar{x}a=yˉ​−bxˉ, where xˉ\bar{x}xˉ and yˉ\bar{y}yˉ​ are the means. This forces the line through the point (xˉ,yˉ)(\bar{x},\bar{y})(xˉ,yˉ​).

Worked example

Find the line from summary statistics

For the study-time data, xˉ=3\bar{x}=3xˉ=3, yˉ=4\bar{y}=4yˉ​=4, sx=1.58s_x=1.58sx​=1.58, sy=1.22s_y=1.22sy​=1.22, and r=0.775r=0.775r=0.775. Find the least-squares line.
  1. 1
    Slope: b=rsysx=0.775×1.221.58b=r\frac{s_y}{s_x}=0.775\times\frac{1.22}{1.58}b=rsx​sy​​=0.775×1.581.22​.
  2. 2
    Calculate: b≈0.598b\approx0.598b≈0.598, so b≈0.60b\approx0.60b≈0.60.
  3. 3
    Intercept: a=yˉ−bxˉ=4−0.60(3)=2.2a=\bar{y}-b\bar{x}=4-0.60(3)=2.2a=yˉ​−bxˉ=4−0.60(3)=2.2.
  4. 4
    Write the line: y^=2.2+0.60x\hat{y}=2.2+0.60xy^​=2.2+0.60x.

Answer: The line is y^=2.2+0.60x\hat{y}=2.2+0.60xy^​=2.2+0.60x, with xxx in hours studied and y^\hat{y}y^​ the predicted quiz score in points.

Exam tip

Write the formula, then the substituted values, then the result. Keep extra digits until the final step, then round.

Part 3 done

4

Part 4 of 5: Technology finds the line faster than hand calculation

In practice, a calculator or statistical software does the arithmetic. Your job is to enter the data correctly and read the output.

  • Enter the xxx values in one list and the yyy values in another.
  • Run the linear regression command, often labeled LinReg(a+bx) on a graphing calculator.
  • Read aaa and bbb from the output.
  • Write y^=a+bx\hat{y}=a+bxy^​=a+bx and define both variables in context.

Computer output often shows a table of coefficients. The intercept appears in the row labeled Constant. The slope appears in the row named for the explanatory variable.

Common mistake

Do not swap the two coefficients. The intercept is aaa, the constant term. The slope is bbb, the number that multiplies xxx.

Part 4 done

Quick check

One question on the part you just read

Easy

Identify the formula for the slope of the least-squares regression line.
Show answer and explanation

Answer: A · Worked explanation

The slope is the correlation times the ratio of the standard deviation of yyy to that of xxx. Flipping the ratio gives the wrong units, since a slope is in units of yyy per unit of xxx. The expression yˉ−rxˉ\bar{y}-r\bar{x}yˉ​−rxˉ resembles the intercept formula, not the slope.
5

Part 5 of 5: The line passes through the means and balances residuals

Now that the line is defined, some useful properties follow. The least-squares line always passes through (xˉ,yˉ)(\bar{x},\bar{y})(xˉ,yˉ​). Its residuals always sum to zero.

Figure 1. Each red segment is a residual. The line balances them, with positive and negative residuals canceling.

The figure shows the study-time data with its line. Each vertical segment is a residual. The positive residuals add to 1.6, and the negative residuals add to -1.6.

The squares also make the line sensitive to unusual points. A point far from the pattern has a large residual, and squaring magnifies it. Such a point can pull the line toward itself. Check unusual points before trusting the equation.

Go deeperWhy the line passes through the means

The intercept formula rearranges to yˉ=a+bxˉ\bar{y}=a+b\bar{x}yˉ​=a+bxˉ. This says that when x=xˉx=\bar{x}x=xˉ, the line predicts exactly yˉ\bar{y}yˉ​.

So the line can also be written as y^−yˉ=b(x−xˉ)\hat{y}-\bar{y}=b(x-\bar{x})y^​−yˉ​=b(x−xˉ). This form is handy when you know only the means and the slope.

Note read

Check your recall[12 marks]

5 written questions. Answer each one in your head or on paper, then open the mark scheme.

  1. 1.Describe[2 marks]

    Describe how the least-squares regression line is chosen from all possible lines.

    Show mark schemeHide mark scheme

    Model answer

    Each residual is squared and the squares are added. The chosen line is the one with the smallest sum of squared residuals.

    • 1 mark for stating that residuals are squared and added
    • 1 mark for stating that the line with the smallest sum of squared residuals is chosen
  2. 2.Explain[2 marks]

    Explain why residuals are squared before they are added when choosing a line.

    Show mark schemeHide mark scheme

    Model answer

    Positive and negative residuals would cancel if simply added. Squaring makes every value positive, so misses above and below the line both count, and large misses count more.

    • 1 mark for stating that positive and negative residuals would cancel
    • 1 mark for explaining that squaring makes all values positive (and gives large misses more weight)
  3. 3.Calculate[3 marks]

    Data have r=0.60r=0.60r=0.60, sx=2.0s_x=2.0sx​=2.0, sy=5.0s_y=5.0sy​=5.0, xˉ=10\bar{x}=10xˉ=10, and yˉ=30\bar{y}=30yˉ​=30. Calculate the least-squares line.

    Show mark schemeHide mark scheme

    Model answer

    b=rsysx=0.60×5.02.0=1.5b=r\frac{s_y}{s_x}=0.60\times\frac{5.0}{2.0}=1.5b=rsx​sy​​=0.60×2.05.0​=1.5. a=yˉ−bxˉ=30−1.5(10)=15a=\bar{y}-b\bar{x}=30-1.5(10)=15a=yˉ​−bxˉ=30−1.5(10)=15. The line is y^=15+1.5x\hat{y}=15+1.5xy^​=15+1.5x.

    • 1 mark for calculating the slope b=1.5b=1.5b=1.5
    • 1 mark for calculating the intercept a=15a=15a=15 using the means
    • 1 mark for writing the equation y^=15+1.5x\hat{y}=15+1.5xy^​=15+1.5x
  4. 4.Describe[2 marks]

    Describe the steps for finding a least-squares regression line with technology.

    Show mark schemeHide mark scheme

    Model answer

    Enter the xxx values and the yyy values into lists, run the linear regression command, and read the intercept aaa and slope bbb to write y^=a+bx\hat{y}=a+bxy^​=a+bx.

    • 1 mark for entering the xxx and yyy data into lists
    • 1 mark for running the regression command and reading aaa and bbb
  5. 5.Justify[3 marks]

    For the same data, line A has a sum of squared residuals of 18.4 and line B has 21.7. Justify which line fits better, and say whether line A must be the least-squares line.

    Show mark schemeHide mark scheme

    Model answer

    Line A fits better because its sum of squared residuals is smaller. Line A need not be the least-squares line, because another line might give an even smaller total.

    • 1 mark for stating that line A has the smaller sum of squared residuals
    • 1 mark for concluding that line A fits better by the least-squares rule
    • 1 mark for stating that another untested line could have a smaller total, so line A is not necessarily the least-squares line

Practice this topic

10 quick-fire multiple-choice questions, easy to hard. Tap an answer to see if you're right and the worked explanation. (The written questions with mark schemes are under “Check your recall” above.)

0 right0 of 10 answered

Includes the 2 quick checks in the note above.

3.

Easy·Identify[1 mark]

Identify the point that every least-squares regression line passes through.
Show answer and explanation

Answer: A · Worked explanation

Because a=yˉ−bxˉa=\bar{y}-b\bar{x}a=yˉ​−bxˉ, the line predicts exactly yˉ\bar{y}yˉ​ when x=xˉx=\bar{x}x=xˉ, so it passes through (xˉ,yˉ)(\bar{x},\bar{y})(xˉ,yˉ​). Passing through (0,0)(0,0)(0,0) would need an intercept of zero, which is generally not true. Medians play no role in the formulas. Both means are needed to find the intercept.
4.

Medium·Calculate[2 marks]

Data have r=−0.80r=-0.80r=−0.80, sx=4.0s_x=4.0sx​=4.0, and sy=10s_y=10sy​=10. Calculate the slope of the least-squares line.
Show answer and explanation

Answer: A · Worked explanation

b=rsysx=−0.80×104.0=−2.0b=r\frac{s_y}{s_x}=-0.80\times\frac{10}{4.0}=-2.0b=rsx​sy​​=−0.80×4.010​=−2.0. The value -0.32 comes from inverting the ratio of standard deviations. The value -32 multiplies instead of dividing. Dropping the sign gives +2.0+2.0+2.0, but a negative correlation must give a negative slope because sxs_xsx​ and sys_ysy​ are always positive.
5.

Medium·Calculate[2 marks]

A least-squares line has slope b=−2.0b=-2.0b=−2.0, and the means are xˉ=6.0\bar{x}=6.0xˉ=6.0 and yˉ=50\bar{y}=50yˉ​=50. Calculate the y-intercept.
Show answer and explanation

Answer: A · Worked explanation

a=yˉ−bxˉ=50−(−2.0)(6.0)=50+12=62a=\bar{y}-b\bar{x}=50-(-2.0)(6.0)=50+12=62a=yˉ​−bxˉ=50−(−2.0)(6.0)=50+12=62. The value 38 comes from subtracting 12 instead of adding it, which mishandles the negative slope. The value -12 is only bxˉb\bar{x}bxˉ. The value 56 adds the two means, which has no basis in the formula. Always subtract bxˉb\bar{x}bxˉ from yˉ\bar{y}yˉ​ and keep the sign of bbb.
6.

Medium·Determine[2 marks]

A least-squares line leaves residuals of -2.5, +1.0+1.0+1.0, and +3.0+3.0+3.0 for three points. A fourth point is the only other point in the data. Determine its residual.
Show answer and explanation

Answer: A · Worked explanation

Residuals from a least-squares line always sum to zero. The first three add to −2.5+1.0+3.0=+1.5-2.5+1.0+3.0=+1.5−2.5+1.0+3.0=+1.5, so the fourth must be -1.5. The value +1.5+1.5+1.5 has the wrong sign. A residual of 0 would leave the total at +1.5+1.5+1.5 instead of zero.
7.

Medium·Identify[2 marks]

Software output for a regression of quiz score on hours studied lists a Constant coefficient of 4.20 and an hours studied coefficient of 1.85. Identify the least-squares equation.
Show answer and explanation

Answer: A · Worked explanation

The Constant is the y-intercept aaa, and the coefficient beside the explanatory variable is the slope bbb. So y^=4.20+1.85x\hat{y}=4.20+1.85xy^​=4.20+1.85x. Reversing the two coefficients attaches 1.85 to the wrong role. A negative slope or a multiplied intercept does not match the output.
8.

Hard·Determine[2 marks]

For the same data, three lines have sums of squared residuals of 14.2, 11.8, and 12.6. Determine the best conclusion.
Show answer and explanation

Answer: A · Worked explanation

A smaller sum of squared residuals means a better fit under the least-squares rule, so 11.8 is best of these three. Some other line, not tested, could give an even smaller total, so it need not be the least-squares line. A larger total means a worse fit, not a better one.
9.

Hard·Explain[2 marks]

A student says the least-squares line must pass through as many data points as possible. Identify the correct response.
Show answer and explanation

Answer: A · Worked explanation

The criterion is the total of squared residuals, not the number of points the line touches. A line can minimize that total and still pass through none of the points. A line through more points can even have a larger total. Requiring exactly one point, or every point, is not part of the rule.
10.

Hard·Predict[2 marks]

Summary statistics are xˉ=5\bar{x}=5xˉ=5, yˉ=20\bar{y}=20yˉ​=20, sx=2s_x=2sx​=2, sy=8s_y=8sy​=8, and r=0.5r=0.5r=0.5. Predict yyy for x=7x=7x=7 using the least-squares line.
Show answer and explanation

Answer: A · Worked explanation

b=0.5×82=2b=0.5\times\frac{8}{2}=2b=0.5×28​=2 and a=20−2(5)=10a=20-2(5)=10a=20−2(5)=10, so y^=10+2(7)=24\hat{y}=10+2(7)=24y^​=10+2(7)=24. The value 44 comes from using a=yˉ+bxˉa=\bar{y}+b\bar{x}a=yˉ​+bxˉ, the wrong sign. The value 20.25 inverts the ratio of standard deviations when finding the slope. Using b=2b=2b=2, the line goes through (5,20)(5,20)(5,20), so x=7x=7x=7 is two units above the mean.

Keep going

Previous topic5.4 Residuals

More in Unit 5 · Regression Analysis

  1. 5.1ScatterplotsNotes · 10 questions
  2. 5.2CorrelationNotes · 10 questions
  3. 5.3Linear regression modelsNotes · 10 questions
  4. 5.4ResidualsNotes · 10 questions
  5. 5.5Least-squares regressionNotes · 10 questions

All AP Statistics topics →

Draft: written by Scribe and checked automatically, not yet by a subject reviewer.

Practice questions are original, written by Scribe and checked automatically for correctness.

Topic codes follow the official numbering. Not endorsed by College Board or any exam board.

On this page

0/5 read

  1. 1A rule is needed to choose the best-fitting line
  2. 2The least-squares line minimizes the sum of squared residuals
  3. 3The slope and intercept follow from summary statistics
  4. 4Technology finds the line faster than hand calculation
  5. 5The line passes through the means and balances residuals
  6. Check your recall
  7. Practice: 10 questions
All coursesScribeHow it worksPricingPrivacyTerms

Notes and questions are written by Scribe in our own words. Topic codes follow the official course numbering so you can find your place. Not produced or endorsed by the IB, College Board, AQA, OCR, Pearson Edexcel or any exam board.

© 2026 Scribe