I am using R to fit a linear model.
My code is:
rating_lm <- lm(rating\$flow ~ I(rating\$raw^2) + rating\$raw, data = rating, weights = 1/(rating\$flow)
I then use the following code to get prediction intervals:
b <- predict(rating_lm, interval = "prediction")
The graph below shows: the fitted line (red line), the data points and the prediction intervals (blue lines).
I used the weighting 1/rating\$flow because we are much more confident in the low measured Y values.
I need to use the fitted linear model in a predictive way with new X data. However, when doing this, I have found that the predicted intervals for the new data are not close to those of the fitted model.
My question is: how can I ensure that the new predicted values, have the same (or very similar), predicted intervals as the fitted model?