1

I am trying to calculate the confidence band about a regression line using the top answer here: Understanding shape and calculation of confidence bands in linear regression

I don't entirely understand the answer, but I am calculating the confidence interval as:

$\sqrt \frac{\Sigma_i^n (Y_i - \hat{Y})^2}{n-2} \sqrt{\frac{1}{n} + \frac{(X-\bar{X})^2}{\Sigma_i^n (X_i-\bar{X})^2}}$

I assume that this will give me a 1-sigma confidence interval. My question is: Is there a way to include the uncertainty on my data points in my confidence interval expression above? (My best fit line is weighted by the uncertainty on my data points.)

user1551817
  • 1,203
  • 1
    It would be more helpful if you could clarify whether the uncertainty in your data pertains to $X_i$ or $Y_i$. Additionally, could you explain how you estimated the effect through weighting? – bluepole Nov 07 '23 at 12:21

1 Answers1

1

This https://stats.stackexchange.com/a/52712/341520 is a fantastic answer which basically solves your problem, but you have to express the model with linear algebra, which immensely improves notation and makes it much more generalize-able.

$$ \hat y_i = \beta_0 + \beta_1 x_i =\vec \beta'\vec x_i $$ with $\vec x_i = \begin{pmatrix} 1\\ x_i \end{pmatrix}$ and $'$ meaning transpose.

Now the standard deviation for the estimator of $\hat\sigma(\vec \beta'\vec x) = \sqrt{\vec x'\hat{\Sigma}_\beta \vec x}$ and Glen_bs answer i linked provides us with $\hat{\Sigma}_\beta = \hat{\sigma_e^2} X'WX $, $X$ being the design matrix and $W$ the diagonal matrix of weights. The design matrix for the simple regression line is $$ X = \begin{pmatrix} 1 & x_1 \\ 1 & x_2 \\ \vdots & \vdots \\ 1 & x_n \end{pmatrix} $$ Your answer already used: $\hat{\sigma_e^2} = \frac{\Sigma(y_i - \hat y_i)^2}{n-rank(X)}$, where $rank(X) = 2$ in your case.

Put it all together your (pointwise) confidence interval at value $x$ will be $$ [\vec \beta'\vec x - t_{\alpha/2, n - 2}\cdot \hat\sigma(\vec \beta'\vec x), \vec \beta'\vec x + t_{\alpha/2, n - 2}\cdot \hat\sigma(\vec \beta'\vec x)] $$

Lukas Lohse
  • 2,482