Tutorials › Introduction to Statistics › The Least-Squares Regression Line

Least-Squares Regression Lines · Tutorial 250 of 996

The Least-Squares Regression Line

Learn to read a least-squares regression equation, identify its slope and intercept, and use it to calculate a predicted response.

Beginner 9 min read

What You'll Learn

  • Define the least-squares regression line as a fitted straight-line rule for predicting a quantitative response.
  • Distinguish observed response values from values predicted by the fitted line.
  • Identify the slope and intercept in the standard regression equation.
  • Recognize the same line when its equation is written in an equivalent form.
  • Substitute an explanatory-variable value into a fitted equation to find a prediction.
  • Check whether a line-based prediction is being used within a reasonable range of the data.

From a Relationship to a Prediction Rule

A scatterplot can show how two quantitative variables vary together. When a straight line provides a useful summary of the pattern, it can also provide a rule for predicting one variable from the other. For example, a campus facilities team might use a building’s floor area to predict its monthly electricity use. The prediction is not a guarantee about an individual building; it is the value given by a fitted line for the specified floor area.

The least-squares regression line is the straight line fitted to paired observations of an explanatory variable and a response variable. Its equation specifies one predicted response for each explanatory-variable value. In this tutorial, we focus on reading that equation and identifying the two coefficients that determine the line. The method used to choose the coefficients is the least-squares criterion; the detailed fitting calculations are a separate topic.

Definition: A least-squares regression line is a fitted straight-line rule for predicting a quantitative response variable from a quantitative explanatory variable. In the standard form, its equation is \( \hat{y}=b_0+b_1x \). Here, \(x\) is a value of the explanatory variable, \( \hat{y} \) is the response value predicted by the line, \(b_0\) is the intercept, and \(b_1\) is the slope.

The hat on \( \hat{y} \) is important. The observed response for an individual or case is written \(y\); \( \hat{y} \) is the response predicted by the fitted line. These need not be the same. The equation provides a rule for the prediction, not a claim that every observed response lies exactly on the line.

Reading the Equation

In \( \hat{y}=b_0+b_1x \), the intercept is the constant term \(b_0\), and the slope is the coefficient multiplying \(x\), \(b_1\). The order of terms may vary: \( \hat{y}=b_1x+b_0 \) has the same coefficients and represents the same line. The intercept is not the coefficient of \(x\), and the slope is not the constant term.

A brief algebraic check explains these labels. Setting \(x=0\) gives the predicted response at zero on the explanatory-variable scale:

$$ \hat{y}=b_0+b_1(0)=b_0. $$

So the line crosses the vertical axis at \(b_0\), which is why \(b_0\) is called the intercept. Now compare the prediction at \(x\) with the prediction one unit higher, at \(x+1\):

$$ \begin{aligned} \hat{y}(x+1)-\hat{y}(x) &=\bigl(b_0+b_1(x+1)\bigr)-\bigl(b_0+b_1x\bigr)\\ &=b_1. \end{aligned} $$

Thus, for each one-unit increase in \(x\), the line’s predicted response changes by \(b_1\) response units. This algebraic role distinguishes the slope from the intercept. Interpreting what that change means in a particular setting requires attention to the variables and their units.

The equation is a mathematical rule: enter an \(x\)-value and evaluate the right-hand side to obtain the predicted \( \hat{y} \). The slope can be positive, negative, or zero. A positive slope makes the line rise as \(x\) increases; a negative slope makes it fall; a zero slope gives a horizontal line. These descriptions concern the line’s direction, not whether a relationship is causal.

Worked Example: Identifying the Coefficients

Suppose a hypothetical analysis of monthly building data reports the fitted line \( \hat{y}=120+0.08x \), where \(x\) is floor area in square meters and \( \hat{y} \) is predicted monthly electricity use in kilowatt-hours. Identify the intercept and slope.

Intercept. The constant term is 120, so \(b_0=120\). It is the line’s predicted response when \(x=0\).

Slope. The coefficient multiplying \(x\) is 0.08, so \(b_1=0.08\). It is the change in the line’s predicted response for a one-square-meter increase in floor area.

The slope has units of kilowatt-hours per square meter, while the intercept has units of kilowatt-hours. The equation identifies these coefficients directly; it does not require calculating them from the original observations.

Using a Fitted Line to Predict

To obtain a prediction, substitute the specified explanatory-variable value for \(x\) and simplify. Keep the symbols straight: the given \(x\) is the input to the prediction rule, and the result is \( \hat{y} \), not necessarily the observed response \(y\). Also keep the original units attached to the variables; a numerical prediction is meaningful only as a value of the response in its stated units.

Worked Example: Predicting From a Fitted Equation

In a hypothetical set of buildings, a facilities analyst reports \( \hat{y}=120+0.08x \), with floor area \(x\) measured in square meters and predicted monthly electricity use \( \hat{y} \) measured in kilowatt-hours. Use the line to predict monthly use for a building with floor area 1,500 square meters.

Substitute \(x=1{,}500\) into the fitted equation:

$$ \begin{aligned} \hat{y} &=120+0.08(1{,}500)\\ &=120+120\\ &=240. \end{aligned} $$

The fitted line predicts monthly electricity use of 240 kilowatt-hours for a building with floor area 1,500 square meters. This is the line’s prediction, not a statement that an actual building of that size must use exactly 240 kilowatt-hours.

Before relying on a line for predictions, inspect the data’s scatterplot. A straight-line rule is more suitable when the pattern is roughly linear and is not dominated by an unusual point. The value 1,500 should also be within or reasonably close to the observed floor-area range; a line can give a number beyond the data, but that does not ensure the prediction is useful.

Recognizing the Same Line in Different Forms

An equation does not have to be printed in the exact order \( \hat{y}=b_0+b_1x \). To identify its coefficients, locate the term without \(x\) and the number multiplying \(x\). If the equation is written \( \hat{y}=mx+c \), then \(m\) plays the role of the slope and \(c\) the role of the intercept. If it is written \( \hat{y}=c+mx \), the roles are unchanged. The letters used for coefficients can vary; their positions and algebraic roles determine which is which.

Worked Example: Reading an Equation in a Different Order

A hypothetical report gives a fitted line for predicting a plant’s height \( \hat{y} \), in centimeters, from the number of weeks since planting, \(x\): \( \hat{y}=-3+2.5x \). Identify the slope and intercept, then find the predicted height at 8 weeks.

The term \(-3\) does not multiply \(x\), so it is the intercept: \(b_0=-3\). The coefficient of \(x\) is \(2.5\), so the slope is \(b_1=2.5\) centimeters per week.

Substitute \(x=8\):

$$ \begin{aligned} \hat{y} &=-3+2.5(8)\\ &=-3+20\\ &=17. \end{aligned} $$

The fitted line predicts a height of 17 centimeters at 8 weeks. The equation’s negative intercept is simply what the line predicts at \(x=0\); whether that prediction has a useful meaning in the setting depends on the context and the range of data.

A final example makes clear that the number attached to \(x\) is the slope even when the equation’s terms are rearranged.

Worked Example: A Negative Slope

A hypothetical fitted line relates outdoor temperature \(x\), in degrees Celsius, to predicted daily heating demand \( \hat{y} \), in kilowatt-hours: \( \hat{y}=500-12x \). Identify its slope and intercept, and calculate the prediction at \(x=10\).

Rewriting the equation in the standard order gives \( \hat{y}=500+(-12)x \). Therefore, the intercept is \(b_0=500\) kilowatt-hours and the slope is \(b_1=-12\) kilowatt-hours per degree Celsius.

At \(x=10\):

$$ \begin{aligned} \hat{y} &=500-12(10)\\ &=500-120\\ &=380. \end{aligned} $$

The line predicts 380 kilowatt-hours of daily heating demand at 10 degrees Celsius. The negative coefficient makes the line decrease as temperature increases. This is a description of the fitted pattern, not evidence by itself that changing the temperature would cause the predicted change.

When the Prediction Rule Is Useful

A regression equation is useful when the variables are quantitative and a straight line gives a reasonable summary of their observed relationship. Before using the line, consider the scatterplot and the range of the measured explanatory values. A strongly curved pattern may not be summarized well by a straight line; an extreme observation may have an outsized influence on the fitted result; and a prediction far outside the observed range is an extrapolation. These checks help determine whether a line-based prediction is sensible, but they do not turn an association into a causal effect.

A fitted equation can also be used for prediction without knowing every observed response. Once the equation is supplied, the arithmetic is direct. What the equation cannot tell you on its own is how close a particular observed value will be to its prediction, how uncertain the fitted coefficients are, or whether changing \(x\) would change \(y\). Those are different questions from identifying the line and evaluating its rule.

Key takeaway: In \( \hat{y}=b_0+b_1x \), \(b_0\) is the constant term and the predicted response at \(x=0\); \(b_1\) is the coefficient of \(x\) and determines how the line changes as \(x\) increases. Substitute an \(x\)-value to calculate the line’s predicted response \( \hat{y} \).

Common Mistakes

  • Swapping the coefficients. The number multiplying \(x\) is the slope; the standalone constant is the intercept. In \( \hat{y}=500-12x \), the slope is \(-12\), not 500.
  • Calling a prediction an observation. The line gives \( \hat{y} \), a predicted response. It does not assert that the actual response \(y\) equals that prediction.
  • Dropping units. A slope is expressed in response units per explanatory-variable unit. State the response prediction in the response variable’s units.
  • Assuming a numerical result is automatically trustworthy. A calculation can be correct even when the line is not a suitable summary for that pattern or the input lies far beyond the observed range. Check the scatterplot and range before relying on a prediction.
  • Reading causation into the line. A fitted line describes a relationship in the data. The equation alone does not establish that changing the explanatory variable causes a change in the response.

Check Your Understanding

Answer each question using the fitted-line equation and the context provided.

  1. A fitted line is \( \hat{y}=4+0.6x \). Identify its slope and intercept.
  2. A report gives \( \hat{y}=90-3x \). What is the slope, and what is the predicted value when \(x=10\)?
  3. In \( \hat{y}=7x+2 \), which coefficient is the intercept? Explain how you can tell.
  4. A line predicts response values measured in minutes from an explanatory variable measured in miles. What are the units of its slope?
  5. Why should a prediction far outside the observed range of \(x\)-values be treated cautiously?