# Prediction interval from regression, variance question

I'm struggling a bit with the notation to get the prediction interval from a maximum likelihood regression.

Having 2 random variables $$X, Y$$, where they relate as $$y = f(x; \beta) + \epsilon$$, where $$\epsilon \sim N(0, \sigma^2)$$ and $$\beta$$ are coefficients that relate $$X$$ to $$Y$$, we do not know how the function $$f$$ uses the coefficients.

So i want to predict a new value $$y_{new}$$ given $$x_{new}$$, and give an interval around $$y_{new}$$.

The prediction should then be: $$\hat y_{new} = f(x_{new}; \hat \beta) + \epsilon$$

Then, the interval should be $$[\mu_{new} - z\sigma_{pred}, \mu_{new} + z\sigma_{pred}]$$

Here is where my doubts start, since we do not know $$\mu_{new}$$ nor $$\sigma_{pred}$$ we have to estimate them. We estimate $$\mu_{new}$$ with $$\hat y_{new}$$, so far so good. For $$\sigma_{pred}$$ i think it should be $$\hat \sigma_{pred}^2 = Var(\hat y_{new}) + \hat \sigma^2$$ where $$Var(\hat y_{new})$$ is the variance of the predictions and $$\hat \sigma^2$$ is the MSE from the random noise. Since we say they are a random independent sample we get no covariance.

So would the prediction interval end up like this? $$\hat y_{new} \pm t_{n-2}\hat \sigma_{pred}$$ $$\hat y_{new} \pm t_{n-2}\sqrt{Var(\hat y_{new}) + \hat \sigma^2}$$

Or should i use the standard error? $$s.e = \sqrt\frac{Var(\hat y_{new}) + \hat \sigma^2}{n}$$ $$\hat y_{new} \pm t_{n-2}s.e$$

I'm a bit confused with why i should use the standard error and not the first interval, also i'm not sure where the $$n-2$$ from the t-student comes from.