Tutorials › AP Statistics › Computing Slope and Intercept From Summary Statistics

Least-squares regression · Tutorial 864 of 1000

Computing Slope and Intercept From Summary Statistics

Use the correlation and summary statistics to calculate a least-squares line, then check that its coefficients and units make sense.

Intermediate 9 min read

What You'll Learn

  • Calculate the slope using the correlation and the ratio of the response and predictor standard deviations.
  • Find the intercept using the means and the calculated slope.
  • Write the least-squares regression equation with the predictor and response in the correct roles.
  • Check the sign and units of the slope and intercept.
  • Verify the equation by checking that it predicts the response mean at the predictor mean.

Build a Regression Line From Summary Values

In “Fitting a Line by Eye Versus Least Squares,” we compared candidate lines using their residuals. Now we can calculate the least-squares line directly when we know several summary statistics for the paired data. We do not need the individual observations to find the line’s slope and intercept.

The needed summaries are the correlation \(r\), the mean and sample standard deviation of the predictor \(x\), and the mean and sample standard deviation of the response \(y\). As established in “Computing Slope From r and Summary Statistics,” calculate the slope first, then use the two means to calculate the intercept. The main task is to keep the predictor and response roles straight and carry enough precision through both calculations.

Formula: For a least-squares regression line \(\hat{y}=a+bx\), calculate the slope and intercept from the summary statistics as follows:
$$ b=r\left(\frac{s_y}{s_x}\right) \qquad\text{and}\qquad a=\bar{y}-b\bar{x} $$
Here, \(r\) is the correlation, \(s_x\) and \(s_y\) are the sample standard deviations of the predictor and response, and \(\bar{x}\) and \(\bar{y}\) are their sample means.

The slope formula scales the correlation by the ratio of the response standard deviation to the predictor standard deviation. Since \(r\) has no units, the slope’s units are response units per predictor unit. The intercept then makes the line align with the means: a least-squares line with an intercept passes through \((\bar{x},\bar{y})\), as discussed in “Finding the Line Through the Means.”

These formulas use summaries from the same paired observations. The \(x\)-mean and \(x\)-standard deviation must describe the predictor values paired with the \(y\)-mean and \(y\)-standard deviation used in the calculation. The correlation must summarize the association between those same variables. Also, \(s_x\) must be greater than zero; if all predictor values are identical, the slope formula is undefined and there is no variation in \(x\) from which to fit a regression slope.

A Reliable Calculation and Check

Work in a consistent order. First identify which variable is the predictor and which is the response. Then calculate \(b\), use that unrounded or sufficiently precise value to calculate \(a\), and write the equation as \(\hat{y}=a+bx\). Finally, check that the slope’s sign and units fit the variables and that substituting \(\bar{x}\) into the line gives \(\bar{y}\), allowing for rounding.

1
Label the summaries.
Record \(\bar{x}\), \(s_x\), \(\bar{y}\), \(s_y\), and \(r\), making sure the \(x\)-values are the predictor and the \(y\)-values are the response.
2
Calculate the slope.
Substitute \(r\), \(s_y\), and \(s_x\) into \(b=r(s_y/s_x)\). Check that the sign of \(b\) matches the sign of \(r\).
3
Calculate the intercept.
Substitute the means and the slope into \(a=\bar{y}-b\bar{x}\). Keep the sign of \(b\) when multiplying.
4
Write and check the line.
Write \(\hat{y}=a+bx\), then confirm that \(a+b\bar{x}\) is approximately \(\bar{y}\). State the units of the coefficients when interpreting them.

A useful distinction: \(r\) describes the direction and strength of the linear association, while \(b\) describes the change in the line’s predicted response for a one-unit increase in the predictor. The slope is not usually equal to the correlation. Its size depends on the units and spread of both variables through \(s_y/s_x\).

Worked Example: Quiz Score and Study Time

Suppose an invented summary of students’ weekly study time \(x\), in hours, and quiz score \(y\), in points, gives \(\bar{x}=12\), \(s_x=3\), \(\bar{y}=48\), \(s_y=10\), and \(r=0.60\). We will construct the least-squares regression line for predicting quiz score from study time.

Worked Example: Calculate Both Coefficients

First calculate the slope. The response standard deviation is measured in points and the predictor standard deviation in hours, so the slope will be in points per hour.

$$ b=r\left(\frac{s_y}{s_x}\right) =0.60\left(\frac{10}{3}\right) =\frac{6}{3} =2 $$

Now calculate the intercept using \(\bar{x}=12\) and \(\bar{y}=48\):

$$ a=\bar{y}-b\bar{x} =48-(2)(12) =48-24 =24 $$

The regression equation is \(\hat{y}=24+2x\), where \(x\) is weekly study time in hours and \(\hat{y}\) is predicted quiz score in points. The positive slope agrees with the positive correlation. Its interpretation is that for each additional hour of weekly study time, the line’s predicted quiz score increases by 2 points. The intercept predicts a score of 24 points at zero study hours; whether that is a practically meaningful prediction depends on the context and the observed range.

As a check, substitute the mean study time into the line: \(24+2(12)=48\), exactly the mean quiz score. This confirms the intercept calculation is consistent with the mean point.

Worked Example: Evening Screen Time and Sleep

For a fictional group of people, let \(x\) be evening screen time in hours and \(y\) be sleep duration in hours. Suppose the summaries are \(\bar{x}=4\), \(s_x=1.5\), \(\bar{y}=7\), \(s_y=0.8\), and \(r=-0.75\). Find the line that predicts sleep duration from evening screen time.

Worked Example: Keep the Negative Sign

Calculate the slope using the signed correlation. Because both standard deviations are positive, the slope has the same sign as \(r\).

$$ b=r\left(\frac{s_y}{s_x}\right) =-0.75\left(\frac{0.8}{1.5}\right) =-0.75\left(\frac{8}{15}\right) =-0.40 $$

Use this negative slope when finding the intercept. Subtracting a negative product is equivalent to adding:

$$ a=\bar{y}-b\bar{x} =7-(-0.40)(4) =7-(-1.60) =8.60 $$

The equation is \(\hat{y}=8.60-0.40x\). The slope is in hours of sleep per hour of evening screen time. For each additional hour of evening screen time, the line’s predicted sleep duration decreases by 0.40 hour. The intercept is the predicted sleep duration, 8.60 hours, at zero evening screen time. This is an association-based prediction, not evidence that screen time causes a change in sleep.

Check the mean point: \(8.60-0.40(4)=8.60-1.60=7.00\), which equals \(\bar{y}\). The negative sign in the equation is important: using \(+0.40\) instead would contradict the negative correlation.

Worked Example: Preserve Precision Before Rounding

A fictional equipment log summarizes operating time \(x\), in hours, and energy use \(y\), in kilowatt-hours. Suppose \(\bar{x}=18\), \(s_x=6\), \(\bar{y}=42\), \(s_y=7\), and \(r=0.55\). Here the slope is not a whole number, so we will retain extra digits while calculating the intercept.

Worked Example: Use the Unrounded Slope in the Intercept

The slope is:

$$ b=0.55\left(\frac{7}{6}\right) =\frac{3.85}{6} =0.641666\ldots $$

Now calculate the intercept using the slope before rounding it:

$$ a=42-(0.641666\ldots)(18) =42-11.55 =30.45 $$

Thus the line, with the slope rounded to four decimal places for display, is \(\hat{y}=30.45+0.6417x\). The slope’s units are kilowatt-hours per operating hour, and the intercept’s units are kilowatt-hours. For each additional operating hour, the line’s predicted energy use increases by about 0.6417 kilowatt-hour.

Check with the unrounded slope: \(30.45+(0.641666\ldots)(18)=30.45+11.55=42\). If we instead used the displayed rounded slope, the result would be \(30.45+(0.6417)(18)=42.0006\), a tiny difference caused by rounding. That is why it is best to keep extra digits during the calculation and round only when reporting the final equation.

Check the Equation, Not Just the Arithmetic

The mean-point check is particularly useful because the intercept is calculated from the means. If substituting \(\bar{x}\) into the equation does not give approximately \(\bar{y}\), revisit the calculation. Common causes include using the wrong mean, multiplying the slope by the wrong \(\bar{x}\), or mishandling a negative slope.

A second check is conceptual. Since standard deviations are positive, \(s_y/s_x\) is positive. Therefore, when both variables vary, \(b\) and \(r\) must have the same sign. If the correlation is negative but your slope is positive, check your arithmetic. The size of the slope, however, cannot be checked by comparing it directly with \(r\); the standard-deviation ratio matters.

Keep the order of variables consistent. If you switch which variable is the predictor, the slope calculation uses a different ratio of standard deviations, and the resulting regression line is generally different. A line that predicts \(y\) from \(x\) is not interchangeable with a line that predicts \(x\) from \(y\).

Common Mistakes and AP Exam Tips

  • Reversing the standard-deviation ratio. Use \(s_y/s_x\), not \(s_x/s_y\). The slope must have response units per predictor unit.
  • Using the wrong correlation sign. Use the signed value of \(r\), not its absolute value. When both variables vary, the slope has the same sign as \(r\).
  • Finding the intercept with the wrong mean. Use \(a=\bar{y}-b\bar{x}\). The response mean is first; the predictor mean is multiplied by the slope.
  • Dropping a negative sign. If \(b\) is negative, \(a=\bar{y}-b\bar{x}\) involves subtracting a negative product. Write that step explicitly.
  • Rounding too early. Keep the slope’s extra digits while calculating \(a\). Round the reported equation at the end and allow for a small difference in the mean-point check.
  • Calling \(r\) the slope. Correlation is unitless; slope has response units per predictor unit. The slope equals \(r\) times the standard-deviation ratio.
  • Swapping predictor and response. Clearly identify \(x\) and \(y\) before substituting values, and write the final equation as \(\hat{y}=a+bx\).

For full credit, show both coefficient calculations with the values substituted, write the equation with the correct predictor and response, and explain the slope in context with units if interpretation is requested. A quick check that \(a+b\bar{x}\) is approximately \(\bar{y}\) can catch an error before you finish.

Key takeaway: Calculate \(b=r(s_y/s_x)\) first and \(a=\bar{y}-b\bar{x}\) second. Then write \(\hat{y}=a+bx\) and check that the line predicts \(\bar{y}\) at \(\bar{x}\), allowing for rounding.

Check Your Understanding

For each question, treat \(x\) as the predictor and \(y\) as the response.

  1. Given \(r=0.40\), \(s_x=5\), and \(s_y=8\), calculate the slope and state its units if \(x\) is measured in minutes and \(y\) in points.
  2. If \(\bar{x}=6\), \(\bar{y}=20\), and \(b=-1.5\), calculate the intercept.
  3. A summary gives a negative \(r\) and positive \(s_x\) and \(s_y\). What must be true about the sign of the slope?
  4. Why should the intercept calculation use the slope before it is rounded?
  5. A proposed line is \(\hat{y}=5+2x\), with \(\bar{x}=3\) and \(\bar{y}=10\). Does the line pass through the mean point? Show the check.