# Get a range of values (val_1 to val_2) instead of one value in linear regression

So, the idea is that I use linear regression and I get an equation y = a * x + b. So when I give a value x I get a predicted value y. However, what I want to achieve is instead of a single value y to get a range of values, such as [val_1 - val_2].Can this be done? Also I have found this question: Regression analysis with range (instead of single value) as independent variable which did not help...

• Can you explain what your val_1 and val_2 would be? Sep 10, 2022 at 10:45
• The values of the range: [min to max]... Sep 10, 2022 at 10:46
• Hm. Linear regression usually assumes normally distributed errors, which go from minus to plus infinity, and your regression will not tell you that there is a max value your $y$ cannot exceed, so the best you can do would be to always output $(-\infty,\infty)$. This is probably not helpful. Would a prediction-interval work for you, i.e., an interval that contains the future realization with (say) 95% probability? Sep 10, 2022 at 10:54
• @Stephan Kolassa: If I calculate the MSE of my model and get the SD = sqrt(MSE) so a range: [y-SD, y+SD] ? Do we say the same thing? Sep 10, 2022 at 10:57
• Yes, that is a prediction interval. It will be too narrow, though, since it only includes one source of uncertainty, namely residual uncertainty - but not parameter uncertainty. Let me write up an answer. Sep 10, 2022 at 10:58

What you are looking for is a prediction interval, i.e., an interval $$[a,b]$$ such that a new observation falls within it with a certain prespecified probability, e.g., 95%. (Of course, there are multiple such intervals. The typical convention is to have "prediction interval" refer to a symmetric PI, such that $$P(yb)=0.025$$.)

You can find the formulas and explanation in Faraday (2002), section 3.5. Note that Faraday calls PIs "confidence intervals for predictions", which I find unfortunate, because it risks confusion with "normal" confidence intervals, which pertain to unobservable parameters. There is a difference between CIs and PIs.

Your favorite statistics package can probably give you prediction intervals. For instance, here is some toy data in R, and we calculate a central 95% PI at a IV of $$x=0.7$$:

set.seed(1)
xx <- runif(20)
yy <- 1+xx+rnorm(20)
model <- lm(yy~xx)
xx_pred <- 0.7
predict(model,newdata=data.frame(xx=xx_pred),interval="prediction",level=0.95)
#        fit        lwr      upr
# 1 1.527059 -0.4707293 3.524847


You will get a prediction of the expectation of $$y$$ of $$1.53$$, and a prediction interval of $$(-0.47, 3.52)$$.