When performing a linear regression we first get a slope and intercept that is the best fit.

How do we compute the confidence interval for predicted values?

Here's an example:

y = 2x + 3

So for x equal to 2 we have y equal to 7. If we also want to be able to say that we are 90% certain that the predicted value of 7 lies within the interval [X, Z], how do we calculate X and Z?

Use Case

Some of the comments asked for the use case. I'd like to show what the confidence interval for a predicted value in an application. I'm using Apache Commons Math and I don't see a method that computes this in the Javadoc, so I'm guessing I'll have to code it myself.


  • $\begingroup$ Suppose we also want to predict the 90% confidence interval bounds on the predicted values. How do we combine the slope confidence interval and the intercept confidence interval? It is vague. please restate your question $\endgroup$
    – user10619
    Commented Apr 18, 2019 at 0:11
  • $\begingroup$ predicted values are based on specific assumptions. Your question does not adequately reflect what is the real statistical problem. State the background of your case. $\endgroup$
    – user10619
    Commented Apr 18, 2019 at 0:24
  • $\begingroup$ @Ole, there are confidence intervals for estimates of slope and intercept coefficients, there are confidence intervals for the mean of y, and there are prediction intervals for new predicted values. Their formulas, derivations, and examples can be found here: newonlinecourses.science.psu.edu/stat414/node/295 and newonlinecourses.science.psu.edu/stat414/node/280 $\endgroup$
    – AlexK
    Commented Apr 18, 2019 at 1:40
  • $\begingroup$ Awesome - @AlexK. The language I was looking for was prediction intervals for predicted values. I'm using the Apache Commons Math linear regression utility and I need to compute prediction intervals. $\endgroup$
    – Ole
    Commented Apr 18, 2019 at 5:30
  • $\begingroup$ I updated the question with the new terminology. $\endgroup$
    – Ole
    Commented Apr 18, 2019 at 5:34

1 Answer 1


One of the books I have seen this explained in details is Pagano's Principles of Biostatistics, in the chapter of "Simple Linear Regression."

The standard error of that particular predicted y, given a certain value for x, is:

$$\hat{se}(\hat{y}) = s_{y|x}\sqrt{\frac{1}{n}+\frac{(x - \bar{x})^2}{\Sigma^n_{i=1}(x_i - \bar{x})^2}}$$

  • $\begingroup$ Any chance that the book has a simple example to go along with the formula? $\endgroup$
    – Ole
    Commented Apr 18, 2019 at 0:59
  • $\begingroup$ It would be nice to see the answer show how to calculate the X and Z values referenced in the question. I have to implement this in an application so if I have a solid example reference point it helps me guarantee application quality. $\endgroup$
    – Ole
    Commented Apr 18, 2019 at 5:45
  • $\begingroup$ Here's a link containing the information for how to go about applying the standard error to get the confidence interval for predicted intervals:real-statistics.com/regression/… $\endgroup$
    – Ole
    Commented Apr 19, 2019 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.