# Confidence and prediction intervals for forecasted values

The 95% confidence interval for the forecasted values ŷ of x is

where

This means that there is a 95% probability that the true linear regression line of the population will lie within the confidence interval of the regression line calculated from the sample data.

Figure 1 – Confidence vs. prediction intervals

In the graph on the left of Figure 1, a linear regression line is calculated to fit the sample data points. The confidence interval consists of the space between the two curves (dotted lines). Thus there is a 95% probability that the true best-fit line for the population lies within the confidence interval (e.g. any of the lines in the figure on the right above).

There is also a concept called prediction interval. Here we look at any specific value of x, x0, and find an interval around the predicted value ŷ0 for x0 such that there is a 95% probability that the real value of y (in the population) corresponding to x0 is within this interval (see the graph on the right side of Figure 1).

The 95% prediction interval of the forecasted value ŷ0 for x0 is

where the standard error of the prediction is

For any specific value x0 the prediction interval is more meaningful than the confidence interval.

Example 1: Find the 95% confidence and prediction intervals for the forecasted life expectancy for men who smoke 20 cigarettes in Example 1 of Method of Least Squares.

Figure 2 – Confidence and prediction intervals

Referring to Figure 2, we see that the forecasted value for 20 cigarettes is given by FORECAST(20,B4:B18,A4:A18) = 73.16. The confidence interval, calculated using the standard error 2.06 (found in cell E12), is (68.70, 77.61).

The prediction interval is calculated in a similar way using the prediction standard error of 8.24 (found in cell J12). Thus life expectancy of men who smoke 20 cigarettes is in the interval (55.36, 90.95) with 95% probability.

Example 2: Test whether the y-intercept is 0.

We use the same approach as that used in Example 1 to find the confidence interval of ŷ when x = 0 (this is the y-intercept). The result is given in column M of Figure 2. Here the standard error is

and so the confidence interval is

Since 0 is not in this interval, the null hypothesis that the y-intercept is zero is rejected.

### 21 Responses to Confidence and prediction intervals for forecasted values

1. Joaquin says:

Dr. Zaiontz,
Very neat and concise example. I’m particularly interested in a one sided C.I. (lower bound)
Would you agree to use
\hat{y} – t_{crit} s.e.

where t_{crit} should be calculated in Excel using =TINV(2*\alpha,df),
where \alpha = 1-p?

Regards,

Joaquin

• Charles says:

Joaquin,

I believe that what you wrote is correct.

Charles

• Emiel says:

Hi all,

It would be good to point out that the function TINV gives a two-sided confidence interval. The new function T.INV (with a dot) gives a one-sided confidence interval. In case of using the new function, you should take \alpha/2; furthermore, it uses the 1-\alpha/2 value, thus, T.INV(0.975,df).

Emiel

• Charles says:

Emiel,

Actually, more simply you should use the T.INV.2T function for the two-sided critical value. It is equivalent to TINV.

This is explained on the webpage http://www.real-statistics.com/excel-capabilities/built-in-statistical-functions/

I will shortly update this information to better explain the various usages of the functions.

Charles

• Omamz says:

Hi Charles,

Your post has been of tremendous help to me.
Although it took me some time I have applied most of the solutions and they have worked just fine.
I need clarification on example 2. Why did you have to eliminate the # 1 before 1/15?
Would really appreciate your prompt response.
Thanks.

• Charles says:

The test uses the confidence interval and not the prediction interval. This is why a 1 is not inserted before 1/15. Shortly I will update the webpage to explain better when the prediction interval is used and when the confidence interval is used.
Charles

2. Kristian Pedersen says:

Hi,

Whats the formula in J12? Cannot get the same results…

Thanks

/Kristian

• Charles says:

Hi Kristian,
J12 contains the same value as cell E9. The formula in E9 is =FORECAST(E8,B4:B18,A4:A18).
Charles

• Kristian Pedersen says:

Hi Charles,

I’m refering to J12, not J11 J12 contains the formula for se (prediction standard error) and formula result i 8.236857, which I cannot get by using the exact same numbers you do.

What formula is in cell J12??

I think it is in the (x – x_)^2 that something is wrong!

Thanks
/ristian

• Charles says:

Hi Kristian,
The formula in cell J12 is =E10*SQRT(1+1/E5+(E8-E7)^2/E11).
Charles

3. Kristian Pedersen says:

Hi Charles,

Great. Thank u.

/Kristian

4. Anu says:

• Charles says:

Anu,
SSx (cell E11) is calculated by the formula =DEVSQ(A4:A18). It has the value 2171.6.
Charles

5. David says:

Hi Charles,

Thanks for your contributions on this site. I’m a bit confused by your base formula, though. Where you use the sum of squared deviations of x (SSx, calculated as DEVSQ(x) or DEVSQ(A4:A:18), I’ve learned to use the standard deviation of x times (n-1), or STDEV.S(A4:A:18)*(n-1) in Excel speak. This would yield a value of CI SE of 2.090695467 and a PI SE of 8.244184143. The difference is small in your dataset, but where deviations are larger the use of sums of squared deviations instead of the method I’ve heard will yield very different results. That said, I’m not at all certain which method is correct–can you point to some references for your formula, please?

Thanks in advance for taking the time to clarify this issue for me.

David

• Charles says:

Hi David,

Note that for any range R1, the square root of DEVSQ(R1) is STDEV.S(R1)*(n-1). In fact, in the formula for cell E12 in Figure 2 of the referenced page I do take the square root of SSx, and so it seems that we should get the same answer. Can you send me an example of your calculation so that I can see why the results are not the same?

Charles

• Zhang says:

Thanks for your contribution. I would like to know how to calculate CI and PI if there are two independent variables. Thanks.

• Charles says:

Zhang,
Sorry but I haven’t had enough time to figure out or find an answer to your question.
Charles

6. Rizwan says:

Hi Charles,

Is Syx = Sres = STEYX(Y,X)? Is it same as Syx = SQRT((SUM(yi – Yi)^2)/(degrees of freedom)), where (xi,yi) are given data and Y is any nonlinear model (not a straight line, say a sigmoidal or logistic curve), which fits the data.

• Charles says:

Rizwan,
Sorry for the long delay in responding to you. I just realized that I overlooked responding to you.
It is true that Syx = Sres = STEYX(Y,X) = SQRT((SUM(yi – Yi)^2)/df) for linear models. I am not sure what these terms would even mean for non linear models such as logistic regression models.
Charles

7. Elisa says:

Hi Charles,
I am using a exponential/hyperbolic function to fit my data. The model is (a*X+b)-SQRT[(a*X+b)^2-((4*a*X*b*c)/(2*c))].
I wonder if I can calculate prediction intervals in the way you show, or if there is any parameter that is different for this type of models. If so, can you tell me how I should calculate it?
Thank you very much
Elisa

• Charles says:

Elisa,
I can’t think of a way of doing this. Perhaps someone else has suggestion.
Charles