1

This question may be dumb for you, but I'm a newbie who has searched online without any good answer. I've read every related post, online examples and explanation of terminology in summary(). Please help.

I've build a multiple linear regression model and have predicted the prediction interval using predict(). Now I want to transfer my linear model to the excel which requires me to manually calculate the prediction interval. In the tutorial videos that show the calculation in excel use "Standard Error" to calculate. However, the $summary() in R doesn't include any number with the same name as "Standard Error". All I find is Residual standard error: 0.53 on 7899 degrees of freedom and Std. Error for each coefficient.

I've tried prediction=1.96 * 0.53 + fitted value to get the result, but the result is different from the result using predict(model,interval="prediction"):

> tttt$manual_lwr<-tttt$fit-(summary(model)$sigma*1.96)
> tttt$manual_upr<-tttt$fit+(summary(model)$sigma*1.96)

          fit        lwr         upr        manual_lwr   manual_upr
----------------------------------------------------------------------
7983    2.178983    1.134940    3.223025    1.1400892   3.217876
7891    3.711812    2.672044    4.751579    2.6729182   4.750705
503     3.911262    2.868349    4.954175    2.8723685   4.950155
8038    2.951495    1.910701    3.992289    1.9126020   3.990389
4147    3.612402    2.572248    4.652556    2.5735087   4.651295

And the table below is the output using predict(model, interval="confidence")

          fit          lwr         upr
7983    2.178983    2.076833    2.281132
7891    3.711812    3.672752    3.750871
503     3.911262    3.821391    4.001133
8038    2.951495    2.890984    3.012006
4147    3.612402    3.564135    3.660670

Please tell me how to fix this problem or how to calculate manually in a correct way. Thank you!

Fangyuan
  • 25
  • 6
  • 1
    You can use `predict()` with interval argument set to "confidence" and get the intervals for each prediction `predict(model,interval="confidence")`. Also you can use `tidy` function from `broom` package to get the std.error for each coefficient. `broom::tidy(model)` – Johan Rosa Jun 07 '19 at 20:39
  • 1
    @JohanRosa. Thanks for you answer. If the interval="confidence", the result is way too different. Also, can you tell me if there is any stand error for the entire model? – Fangyuan Jun 07 '19 at 20:47
  • Duplicate question: see https://stackoverflow.com/questions/38109501/how-does-predict-lm-compute-confidence-interval-and-prediction-interval – ThetaFC Jun 07 '19 at 21:40

0 Answers0