1
$\begingroup$

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.)

$\endgroup$
1
  • 1
    $\begingroup$ 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? $\endgroup$
    – bluepole
    Commented Nov 7, 2023 at 12:21

1 Answer 1

1
$\begingroup$

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)] $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.