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 to predict a response variable , and the AP course writes it as , where (y-hat) is the predicted response, is the y-intercept, and is the slope. Making a prediction is one substitution:
- Identify which variable is . It is the explanatory variable, the one you are predicting from.
- Put its value in place of in the equation.
- Multiply by the slope first, then add or subtract the intercept.
- Attach the units of and call the number predicted.
A cross-country coach fit the line to data from 24 runners, where is average weekly training miles and is 5K race time in minutes. For a runner averaging 20 miles per week:
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 from and only in that direction. If the equation is with in weekly miles, then substituting a race time in place of produces a meaningless number. Check the definitions given in the problem, not the letters alone.
The sign of the slope. Here , 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 , substitute -0.3512 and round only the final prediction. Rounding the slope to -0.35 first and then multiplying by a large can shift the answer noticeably.
If you also need to find and 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:
One runner in the coach's data averaged 30 miles per week and ran a 5K in 19.2 minutes. The prediction at is minutes, so the residual is 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 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:
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 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 minutes.
The scatter around the line is the part the model does not explain, and residuals are exactly its size. The coefficient of determination reports the share of the variation in that the linear relationship with does explain, so the remainder is variation the prediction cannot account for. Even 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 of the original spread in , 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 tends to move with 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 where 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 does not give the least-squares prediction of , because the line was built to minimize errors in the direction only.
- Rounding the coefficients before substituting. Round the final prediction, not the inputs.
- Extrapolating without saying so. If falls outside the data range, say the prediction is an extrapolation and is unreliable.
- **Treating a high 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 , , , and , 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 to data from 24 runners, where is average weekly training miles and 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.
Identify the explanatory variable. Weekly training miles is , so substitute the mileage, not a race time.
Predict at . Multiply first: . Then subtract: minutes.
Predict at . Multiply first: . Then subtract: minutes.
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.
Check the pair against the slope. The x-values differ by miles, so the predictions should differ by minutes. Indeed , 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 , 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.
Find the predicted value at . minutes.
Subtract predicted from observed. Residual minutes.
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.
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.
Compute the prediction anyway to see the damage. , so minutes.
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 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 is what actually happened for a data point you measured. The predicted value (y-hat) is what the regression line estimates at that x-value. Their difference, , is the residual, so and 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 direction, so it is built for predicting from . Predicting from 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 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.