I have several predictive features in my data which was randoemly sampled from a population. I've trained a linear regression model and got the coefficients vector.

Coefficients:  [ 0.05695075  0.56977067  2.43343221  4.14751194  1.20493825  0.63284814
  6.00986742  5.12038658 -1.92726791  7.23478794  4.32105771  2.45407473
  0.3934679   5.66396219  4.01368824]

However, the coefficients are random variables and of course might change, and we don't know them we can just estimate them.

I have an assignemt to find the conficance intervals for the coefficients $\beta_0^* .. \beta_k^*$ (those are the real coefficients which we don't know and want to calculate their CI).

The formula to calculate the CI, assuming $\alpha = 0.05$ ,is as follows:

$$[\hat{\beta}_j - 1.96 * \hat{S.E}(\hat{\beta}_j)]$$


$$[\hat{\beta}_{j} - 2 * \hat{\sigma_{\epsilon}} \sqrt{(X^TX)_{jj}^{-1}}, \hat{\beta}_{j} + 2 * \hat{\sigma_{\epsilon}} \sqrt{(X^TX)_{jj}^{-1}} ]$$

Now what should I do? how do I find the CI for each coefficient in the data?


1 Answer 1


This looks like it could be a homework assignment, in that case it depends on what your teacher wants you to do. The textbook should have a formula for estimating the standard errors to put into the equation, or the teacher may just expect you to find the SE or CI from the same software that you used to get the coefficient estimates above.

If this is not homework or similar, then you can find the formula for the standard errors in many places on the internet, but the formulas are built into many software programs and it is simplest to have the software compute these for you. How depends on what software you are using. Many statistical software programs will give you the standard errors in a table with the coefficient estimates, t-values, p-values, etc. and you can just plug those into the formula above. Some software will compute the confidence intervals for you (for example the confint function in R will compute these for a fitted model).

Without more detail it is hard for us to give any specific advice.

  • $\begingroup$ I can use this forumula: $\hat{\sigma_{\epsilon}} = 1/(n-p) \sum e_i^2$ , while $e_i$ is the residuals. and also $e = y - \hat{y} = (I - P)y$. I should find the sigma, I just don't know how to use those in order to do it. I know this function in R but I use python, and I'm not allowed to do it like that, I must do it according to the formula... $\endgroup$
    – CORy
    Dec 22, 2022 at 19:21
  • $\begingroup$ That formula is for the mean square error or variance of the residuals, which is part of the standard error of the coefficients, but not all of it. I don't know python, so cannot be a big help there, but I did find one example using the statsmodels package that printed the full table including a column labelled std err with the standard errors that could be plugged into the confidence interval formula. Maybe a python user can give better details. $\endgroup$
    – Greg Snow
    Dec 22, 2022 at 19:54

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.