# Linear Regression confidence interval bounds

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.

• 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 – Subhash C. Davar Apr 18 '19 at 0:11
• 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. – Subhash C. Davar Apr 18 '19 at 0:24
• @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 – AlexK Apr 18 '19 at 1:40
• 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. – Ole Apr 18 '19 at 5:30
• I updated the question with the new terminology. – Ole Apr 18 '19 at 5:34

## 1 Answer

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}}$$

• Any chance that the book has a simple example to go along with the formula? – Ole Apr 18 '19 at 0:59
• 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. – Ole Apr 18 '19 at 5:45
• 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/… – Ole Apr 19 '19 at 0:52