How to predict y from x with a regression line

By Jude Wallis · Updated

Substitute the x-value into $\hat{y} = a + bx$ and simplify. The result is a predicted y carrying the units of y, not an actual value. Trust it only for x-values inside the range of the data, and use a residual, $y - \hat{y}$, to see how far a real observation fell from it.

AP Statistics: Unit 5 (topics 5.3 Linear Regression Models, 5.4 Residuals). Calculating a predicted response is Unit 5 topic 5.3 and residuals are topic 5.4 of the Fall 2026 AP Statistics course, where Unit 5 carries 10 to 20 percent of the multiple-choice section, and the redesigned exam no longer includes inference for regression slopes.

Substitute the x-value, then keep the units

A linear regression model uses an explanatory variable xx to predict a response variable yy, and the AP course writes it as y^=a+bx\hat{y} = a + bx, where y^\hat{y} (y-hat) is the predicted response, aa is the y-intercept, and bb is the slope. Making a prediction is one substitution:

  1. Identify which variable is xx. It is the explanatory variable, the one you are predicting from.
  2. Put its value in place of xx in the equation.
  3. Multiply by the slope first, then add or subtract the intercept.
  4. Attach the units of yy and call the number predicted.

A cross-country coach fit the line y^=28.50.35x\hat{y} = 28.5 - 0.35x to data from 24 runners, where xx is average weekly training miles and yy is 5K race time in minutes. For a runner averaging 20 miles per week:

y^=28.50.35(20)=28.57=21.5\hat{y} = 28.5 - 0.35(20) = 28.5 - 7 = 21.5

Write the result as a sentence: the model predicts a 5K time of 21.5 minutes for a runner averaging 20 miles per week. Dropping the units turns a complete answer into a bare number, and dropping the word "predicted" claims more than the model supports.

Read the equation before you substitute

Most prediction errors happen before any arithmetic. Three things are worth confirming every time.

Which variable is which. The line predicts yy from xx and only in that direction. If the equation is y^=28.50.35x\hat{y} = 28.5 - 0.35x with xx in weekly miles, then substituting a race time in place of xx produces a meaningless number. Check the definitions given in the problem, not the letters alone.

The sign of the slope. Here b=0.35b = -0.35, so the term is subtracted. The slope reads as a rate: for each additional weekly training mile, the model predicts the 5K time decreases by 0.35 minutes. Interpreting that coefficient in context is its own skill, covered in how to interpret the slope of a regression line.

The precision of the coefficients. If a calculator reports b=0.3512b = -0.3512, substitute -0.3512 and round only the final prediction. Rounding the slope to -0.35 first and then multiplying by a large xx can shift the answer noticeably.

If you also need to find aa and bb in the first place, least-squares regression line walks through both from summary statistics.

Compute a residual to see how far the prediction missed

A prediction is only useful if you can measure how well it did. That measurement is the residual, the difference between what actually happened and what the model predicted:

residual=yy^=observedpredicted\text{residual} = y - \hat{y} = \text{observed} - \text{predicted}

One runner in the coach's data averaged 30 miles per week and ran a 5K in 19.2 minutes. The prediction at x=30x = 30 is y^=28.50.35(30)=28.510.5=18.0\hat{y} = 28.5 - 0.35(30) = 28.5 - 10.5 = 18.0 minutes, so the residual is 19.218.0=1.219.2 - 18.0 = 1.2 minutes.

The sign carries the meaning, and the AP course states the convention directly. A positive residual means the model underpredicted, so the observed value came in above the prediction. A negative residual means the model overpredicted. This runner's positive residual of 1.2 minutes says she ran 1.2 minutes slower than the model predicted for her training volume.

Residuals are also how you check whether a line belonged there at all. Plot every residual against xx and look for a pattern; apparent randomness supports the linear model, while curvature says a line was the wrong choice. See how to interpret residual plots for what each shape means, and why square the residuals for how they define the line itself.

Extrapolation: the x-values you cannot trust

The line was fit using a particular stretch of x-values, and it earns credibility only there. The coach's 24 runners averaged between 12 and 38 miles per week.

Interpolation means predicting at an x-value inside that stretch. Both 20 and 30 miles per week qualify, so those predictions rest on data.

Extrapolation means predicting beyond it, and the AP course warns that a predicted value gets less reliable the further you push. Nothing in the data says the straight-line pattern continues outside 12 to 38 miles, and often it plainly does not.

Push it far enough and the model says something impossible. At 100 miles per week:

y^=28.50.35(100)=28.535=6.5\hat{y} = 28.5 - 0.35(100) = 28.5 - 35 = -6.5

The model predicts a 5K time of -6.5 minutes, a runner finishing six and a half minutes before the starting gun. The arithmetic is fine and the answer is nonsense, which is the whole warning: a regression equation will hand you a number for any xx you feed it, and it never objects. Compare the two cases in interpolation vs extrapolation.

There is no fixed cutoff for how far is too far. Stay inside the observed range when you can, and label any prediction outside it as an extrapolation whose reliability you cannot vouch for.

A prediction is a model output, not a guarantee

Even a well-behaved prediction from the middle of the data is an estimate of the average response at that x-value, not a promise about any single individual. Two runners both averaging 30 miles per week will not run the same 5K time, yet the line gives them the same y^=18.0\hat{y} = 18.0 minutes.

The scatter around the line is the part the model does not explain, and residuals are exactly its size. The coefficient of determination r2r^2 reports the share of the variation in yy that the linear relationship with xx does explain, so the remainder is variation the prediction cannot account for. Even r2=0.90r^2 = 0.90 leaves 10 percent of the variation unexplained, and because that 10 percent is a share of the variance rather than of the spread, the typical miss is larger than it sounds: the leftover standard deviation is 0.100.32\sqrt{0.10} \approx 0.32 of the original spread in yy, so about a third of it survives the model. See r vs r-squared for what that number does and does not cover.

A prediction also says nothing about cause. The line describes how yy tends to move with xx in the observed data. Concluding that adding 10 weekly miles would cause a given runner's time to drop 3.5 minutes requires an experiment, not a regression fit to observational data. Correlation vs causation covers the gap.

So report a prediction with three hedges built in: the word predicted, the units, and the x-range it came from.

Common mistakes when predicting

These slips cost points on otherwise correct work.

  • **Writing yy where y^\hat{y} belongs.** The hat is what marks the number as a prediction. Without it you are claiming an observed value.
  • Losing the units. "21.5" is not an answer; "21.5 minutes" is.
  • Substituting into the wrong slot. Plugging a y-value into the equation and solving for xx does not give the least-squares prediction of xx, because the line was built to minimize errors in the yy direction only.
  • Rounding the coefficients before substituting. Round the final prediction, not the inputs.
  • Extrapolating without saying so. If xx falls outside the data range, say the prediction is an extrapolation and is unreliable.
  • **Treating a high r2r^2 as a license to extrapolate.** A strong fit inside the data says nothing about behavior outside it.
  • Computing the residual backward. It is observed minus predicted. Reversing the order flips every sign and reverses the underpredict and overpredict reading.

Check your work and practice

Enter a data set in the regression calculator to get aa, bb, rr, and r2r^2, then make a prediction by hand and confirm it against the equation the tool reports. Doing both keeps the arithmetic honest.

To see how fragile a prediction can be, move one point around in the influential point interactive and watch the predicted values shift with the line. Then work the regression practice set, which mixes predictions, residuals, and interpretation in AP-style multi-part questions.

Make two predictions from the same line

A cross-country coach fits y^=28.50.35x\hat{y} = 28.5 - 0.35x to data from 24 runners, where xx is average weekly training miles and yy is 5K race time in minutes. The runners in the data averaged between 12 and 38 miles per week. Predict the 5K time for a runner averaging 20 miles per week and for a runner averaging 30 miles per week.

  1. Identify the explanatory variable. Weekly training miles is xx, so substitute the mileage, not a race time.

  2. Predict at x=20x = 20. Multiply first: 0.35×20=7.00.35 \times 20 = 7.0. Then subtract: y^=28.57.0=21.5\hat{y} = 28.5 - 7.0 = 21.5 minutes.

  3. Predict at x=30x = 30. Multiply first: 0.35×30=10.50.35 \times 30 = 10.5. Then subtract: y^=28.510.5=18.0\hat{y} = 28.5 - 10.5 = 18.0 minutes.

  4. Confirm both are interpolations. Both 20 and 30 fall inside the observed range of 12 to 38 miles per week, so both predictions rest on data.

  5. Check the pair against the slope. The x-values differ by 3020=1030 - 20 = 10 miles, so the predictions should differ by 10×(0.35)=3.510 \times (-0.35) = -3.5 minutes. Indeed 21.53.5=18.021.5 - 3.5 = 18.0, matching step 3.

The model predicts a 5K time of 21.5 minutes for a runner averaging 20 miles per week, and 18.0 minutes for a runner averaging 30 miles per week. Both are predicted times, not actual times, and both are interpolations.

Find a residual, then spot an extrapolation

Using the same line y^=28.50.35x\hat{y} = 28.5 - 0.35x, one runner in the data averaged 30 miles per week and ran her 5K in 19.2 minutes. Find and interpret her residual. Then explain why the coach should not use this line to predict a 5K time for a runner averaging 100 miles per week.

  1. Find the predicted value at x=30x = 30. y^=28.50.35(30)=28.510.5=18.0\hat{y} = 28.5 - 0.35(30) = 28.5 - 10.5 = 18.0 minutes.

  2. Subtract predicted from observed. Residual =yy^=19.218.0=1.2= y - \hat{y} = 19.2 - 18.0 = 1.2 minutes.

  3. Read the sign. The residual is positive, so the model underpredicted: she ran 1.2 minutes slower than the line predicted for a runner training 30 miles per week.

  4. Check whether 100 miles per week is inside the data. The observed range is 12 to 38 miles per week, so 100 is far outside it and any prediction there is an extrapolation.

  5. Compute the prediction anyway to see the damage. 0.35×100=350.35 \times 100 = 35, so y^=28.535=6.5\hat{y} = 28.5 - 35 = -6.5 minutes.

  6. Interpret the result. A predicted race time of -6.5 minutes is impossible, which shows the straight-line pattern cannot hold that far out. The line was only checked between 12 and 38 miles per week.

The residual is 19.218.0=1.219.2 - 18.0 = 1.2 minutes. Because it is positive, the model underpredicted her time by 1.2 minutes. At 100 miles per week the line predicts -6.5 minutes, a negative race time, so the coach should not extrapolate that far beyond the observed range of 12 to 38 miles.

Frequently asked questions

What is the difference between y and y-hat?

The observed value yy is what actually happened for a data point you measured. The predicted value y^\hat{y} (y-hat) is what the regression line estimates at that x-value. Their difference, yy^y - \hat{y}, is the residual, so yy and y^\hat{y} are equal only when a point lands exactly on the line.

Can I run the line backward to predict x from y?

No. The least-squares line is chosen to minimize errors measured vertically, in the yy direction, so it is built for predicting yy from xx. Predicting xx from yy requires fitting a different line with the roles reversed, and that line is generally not the algebraic rearrangement of the first one.

What does a residual of 0 mean?

It means the observed value landed exactly on the line, so the prediction was spot on for that individual. It says nothing about the other points, and it does not make the model good overall; judge that from the residual plot and the scatter as a whole.

How far outside the data range is too far?

There is no fixed number. The AP course says the prediction becomes less reliable the further you extrapolate, so reliability degrades gradually rather than at a cutoff. Stay inside the observed x-values when you can, and if you must go outside, label the prediction an extrapolation.

Does a strong r mean my prediction will be accurate?

A strong rr means the points cluster tightly around the line inside the observed range, so predictions there tend to miss by less. It does not make any single prediction exact, since individuals still scatter, and it gives no protection at all once you leave the range of the data.