Least Squares Regression Line

The line of best fit that minimizes squared prediction errors, used to predict one variable from another in a linear relationship.

y^=b0+b1x,b1=rsysx\hat{y} = b_0 + b_1 x, \quad b_1 = r\frac{s_y}{s_x}

Solve a problem with Least Squares Regression Line

Type the problem. The solver will use Least Squares Regression Line where Least Squares Regression Line is the right tool, and tell you when it is not.

Drag one in or paste from the clipboard. JPEG, PNG or WebP. You get the transcription to check before anything is solved.

How to get a better answer
  • Paste the whole problem, including the instruction word — "simplify", "solve for x" and "factor" lead to three different answers.
  • Say what you have already tried. "I got x = 4 and the book says 2" turns a solution into a diagnosis.
  • Set the level in the settings button. A calculus shortcut is not a better answer if you have not met derivatives yet.
  • For a photo, get the whole problem in frame and hold the page flat — you get the transcription to fix before anything is solved.

What each symbol means

What Least Squares Regression Line takes
y^\hat{y}
b0b_0
b1b_1
rr
xx
Least Squares Regression Line
SymbolMeaning
y^\hat{y}The predicted or fitted value of the response variable for a given xx—confusing it with actual yy makes you think the line passes through every data point when it actually minimizes overall error.
b0b_0The y-intercept, the predicted value when x=0x = 0, calculated as b0=yˉb1xˉb_0 = \bar{y} - b_1 \bar{x}—forgetting to include it gives you only a slope with no complete equation.
b1b_1The slope of the regression line, the change in y^\hat{y} per unit increase in xx, calculated from b1=rsysxb_1 = r\frac{s_y}{s_x}—it always has the same sign as rr.
rrThe correlation coefficient (Pearson's rr), ranging from -1 to 1, measuring how closely data follow a linear pattern—it is not the slope, and confusing the two is a major error.
xxThe predictor or independent variable used as input to make predictions—predictions outside the range of observed data become increasingly unreliable.

When to use it

When you have bivariate data with a linear trend and want to predict one variable from another.

Level

Usually taught in: Statistics · Appears on: AP Statistics

Worked examples

1. Clean regression line with positive correlation

Problem

A student recorded study time (hours) and test score for 10 classmates. The data shows r=0.9r = 0.9, sx=2s_x = 2 hours, sy=6s_y = 6 points, mean study time xˉ=5\bar{x} = 5 hours, and mean test score yˉ=70\bar{y} = 70 points. Write the regression equation and predict the test score for a student who studies 7 hours.
  1. b1=rsysx=0.962b_1 = r \frac{s_y}{s_x} = 0.9 \cdot \frac{6}{2}

    Apply the formula for slope using the correlation coefficient and the ratio of standard deviations.

  2. b1=0.93=2.7b_1 = 0.9 \cdot 3 = 2.7

    Simplify the fraction 62=3\frac{6}{2} = 3, then multiply by 0.9 to get the slope.

  3. b0=yˉb1xˉ=702.7(5)=7013.5=56.5b_0 = \bar{y} - b_1 \bar{x} = 70 - 2.7(5) = 70 - 13.5 = 56.5

    Use the means and the slope to find the y-intercept so the line passes through (xˉ,yˉ)=(5,70)(\bar{x}, \bar{y}) = (5, 70).

  4. y^=56.5+2.7x\hat{y} = 56.5 + 2.7x

    Write the complete regression equation in the form y^=b0+b1x\hat{y} = b_0 + b_1 x.

  5. y^=56.5+2.7(7)=56.5+18.9=75.4\hat{y} = 56.5 + 2.7(7) = 56.5 + 18.9 = 75.4

    Substitute x=7x = 7 to predict the test score for a student who studied 7 hours.

Answer: y^=56.5+2.7x; predicted score=75.4 points\hat{y} = 56.5 + 2.7x \text{; predicted score} = 75.4 \text{ points}

We first calculate the slope using the formula b1=rsysxb_1 = r\frac{s_y}{s_x}, then find the y-intercept so the line passes through the center of the data. Finally, we substitute the given study time to make a prediction.

2. Regression line with negative correlation

Problem

A real estate agent analyzed 20 homes, finding that age (years) and selling price (thousands of dollars) have r=0.8r = -0.8, sx=2.5s_x = 2.5 years, sy=25s_y = 25 thousand dollars, mean age xˉ=18\bar{x} = 18 years, and mean price yˉ=300\bar{y} = 300 thousand. Find the regression line and predict the selling price of a 25-year-old house.
  1. b1=rsysx=(0.8)252.5b_1 = r \frac{s_y}{s_x} = (-0.8) \cdot \frac{25}{2.5}

    Apply the slope formula, being careful to keep the negative sign from the correlation coefficient.

  2. b1=(0.8)10=8b_1 = (-0.8) \cdot 10 = -8

    Divide 252.5=10\frac{25}{2.5} = 10, then multiply by 0.8-0.8 to get a negative slope (older houses are cheaper).

  3. b0=yˉb1xˉ=300(8)(18)=300+144=444b_0 = \bar{y} - b_1 \bar{x} = 300 - (-8)(18) = 300 + 144 = 444

    Substitute carefully: subtracting a negative is addition, so (8)(18)=+144-(-8)(18) = +144.

  4. y^=4448x\hat{y} = 444 - 8x

    The negative slope appears as a minus sign in the equation; the regression line slopes downward.

  5. y^=4448(25)=444200=244\hat{y} = 444 - 8(25) = 444 - 200 = 244

    Substitute x=25x = 25 years to predict that a 25-year-old house sells for 244 thousand dollars.

Answer: y^=4448x; predicted price=244 thousand dollars\hat{y} = 444 - 8x \text{; predicted price} = 244 \text{ thousand dollars}

The negative correlation means older homes have lower prices, so the slope is negative. We carefully handle the negative sign when computing the y-intercept, then use the equation to predict a price for a specific age.

3. Word problem: coffee shop sales and temperature

Problem

A coffee shop recorded daily high temperature (°F) and iced coffee sales (units sold) for 30 days. The data shows r=0.9r = 0.9, standard deviation of temperature sx=4s_x = 4°F, standard deviation of sales sy=8s_y = 8 units, mean temperature xˉ=70\bar{x} = 70°F, and mean sales yˉ=140\bar{y} = 140 units. Find the regression equation and estimate how many iced coffees the shop will sell on a day when the high temperature reaches 80°F.
  1. b1=rsysx=0.984b_1 = r \frac{s_y}{s_x} = 0.9 \cdot \frac{8}{4}

    Use the correlation and standard deviations to find how much sales increase per degree of temperature.

  2. b1=0.92=1.8b_1 = 0.9 \cdot 2 = 1.8

    Simplify 84=2\frac{8}{4} = 2, then multiply by 0.9; each degree Fahrenheit corresponds to 1.8 more units sold.

  3. b0=yˉb1xˉ=1401.8(70)=140126=14b_0 = \bar{y} - b_1 \bar{x} = 140 - 1.8(70) = 140 - 126 = 14

    Calculate the y-intercept using the mean values so the line passes through the center of the data.

  4. y^=14+1.8x\hat{y} = 14 + 1.8x

    The complete regression equation; the shop sells 14 units at a temperature of 0°F (extrapolation) plus 1.8 units per degree.

  5. y^=14+1.8(80)=14+144=158\hat{y} = 14 + 1.8(80) = 14 + 144 = 158

    Substitute the temperature of 80°F to predict the number of iced coffees the shop will sell that day.

Answer: y^=14+1.8x; predicted sales at 80°F=158 units\hat{y} = 14 + 1.8x \text{; predicted sales at 80°F} = 158 \text{ units}

Higher temperatures correlate with more iced coffee sales, so we use the regression line to predict sales based on the forecast temperature. The slope 1.8 tells us the shop sells about two more iced coffees per degree increase.

Common mistakes

Where Least Squares Regression Line usually goes wrong
Answer came out wrong
Using rr directly as the slope: writing y^=0.8x+5\hat{y} = 0.8x + 5 when the correlation is r=0.8r = 0.8.
Always calculate b1=rsysxb_1 = r\frac{s_y}{s_x} before writing the equation.
Writing only the slope as the regression line: claiming the regression line is y^=2.5x\hat{y} = 2.5x without a y-intercept term.
Always compute b0=yˉb1xˉb_0 = \bar{y} - b_1 \bar{x} and include it in the equation as a separate term.
Assuming all data points lie on the regression line: stating 'the regression line passes through every point in the data set' or using actual yy values and predicted y^\hat{y} values interchangeably.
Distinguish between observed values yy (from the data) and predicted values y^\hat{y} (from the equation); the regression line balances errors across all points rather than fitting any single point perfectly.
The mistakeWhy it is wrongThe fix
Using rr directly as the slope: writing y^=0.8x+5\hat{y} = 0.8x + 5 when the correlation is r=0.8r = 0.8.The correlation coefficient rr measures the strength of the relationship, not the slope; you must convert it to slope using the standard deviations with the formula b1=rsysxb_1 = r\frac{s_y}{s_x}.Always calculate b1=rsysxb_1 = r\frac{s_y}{s_x} before writing the equation.
Writing only the slope as the regression line: claiming the regression line is y^=2.5x\hat{y} = 2.5x without a y-intercept term.The least squares regression line must have the form y^=b0+b1x\hat{y} = b_0 + b_1 x and must pass through the point (xˉ,yˉ)(\bar{x}, \bar{y}); the y-intercept b0b_0 is essential and must be calculated as b0=yˉb1xˉb_0 = \bar{y} - b_1 \bar{x}.Always compute b0=yˉb1xˉb_0 = \bar{y} - b_1 \bar{x} and include it in the equation as a separate term.
Assuming all data points lie on the regression line: stating 'the regression line passes through every point in the data set' or using actual yy values and predicted y^\hat{y} values interchangeably.The regression line is a model that minimizes the sum of squared residuals, not a curve that fits every point exactly; most real data points do not fall on the line, and that is by design.Distinguish between observed values yy (from the data) and predicted values y^\hat{y} (from the equation); the regression line balances errors across all points rather than fitting any single point perfectly.

Tips and when to use something else

  • The regression line always passes through the point (xˉ,yˉ)(\bar{x}, \bar{y})—verify this by substituting these values into your equation to check your work.
  • The slope b1b_1 always has the same sign as the correlation rr: positive correlation gives positive slope, negative correlation gives negative slope.
  • A strong correlation (close to ±1) produces a steep regression line and more reliable predictions, while a weak correlation (close to 0) produces a flatter line and less trustworthy forecasts.
  • If the correlation rr is very close to zero (weak linear relationship), the regression line may not be a good predictive tool—consider instead predicting using the sample mean yˉ\bar{y} for all values of xx.

Frequently asked questions

What is the difference between yy and y^\hat{y}?
yy is an actual observed value from your data, while y^\hat{y} is the predicted value calculated from the regression line. The difference yy^y - \hat{y} is called a residual and represents how far off the prediction was for that particular data point.
Can I use the regression line to predict values outside the range of my original data?
You can use the equation to calculate predictions for any xx (called extrapolation), but you should be cautious—the linear relationship observed in your data may not hold far outside the range you measured, so predictions become increasingly unreliable.
What does a negative slope in the regression equation mean?
A negative slope means that as xx increases, y^\hat{y} decreases; this reflects a negative correlation, such as selling price decreasing as house age increases. The regression line slopes downward from left to right.
How do I know if my regression line is actually a good predictor?
Check the correlation coefficient rr: values very close to -1 or +1 indicate a strong linear relationship and more reliable predictions, while values of rr close to 0 indicate a weak relationship where the regression line may not predict well.

Need a different method?

The full solver is not scoped to one formula — type any problem and it will pick the method.

Open the math solver

Reviewed 2026-09-18