# How do I reference a regression model's coefficient's standard errors? [closed]

            Estimate Std. Error t value Pr(>|t|)
(Intercept)  10.2758     0.5185  19.817  < 2e-16 ***
rprice2      -1.8581     0.5139  -3.616 0.000696 ***


I would like to use the Std. Error of rprice2 to make other calculations. I know to reference any of the objects in the model, I use the syntax model$object, but what is the syntax for referencing the std errors? • what kind of model object is this? If your model object (call it mod) is a lm or a glm, you can extract the standard errors with summary(mod)$coef[,2] – Macro Apr 18 '12 at 2:56
• it's an lm model, i'm trying to calculate the t-statistic with the following code, using your comment: tstat<-abs(model$coef/summary(model)$coef[2,2])... which seems to work, but i'm not sure how to interpret the output of tstat which is: (Intercept) rprice2 19.99568 3.61563 – Aaron Apr 18 '12 at 3:37
• Note that the coefficients attribute (a 2x4 array) of the summary() output can be extracted using the coef() command. If you just want the estimated standard error for the coefficient of rprice2, use e.g. coef(summary(mod))[2,2]. If you want the corresponding t-statistic, use coef(summary(mod))[2,3]. – guest Apr 18 '12 at 3:46

Quite generally you want the vcov function which provides the complete parameter covariance matrix. To get the regular asymptotic standard errors reported by summary you can use

se <- sqrt(diag(vcov(model)))


btw you would want the off-diagonals of vcov(model) to get marginal effects for interaction terms: see Brambor et al. (2006).

Note also packages like sandwich devoted to constructing different types of standard errors, e.g. ones 'robust' to various types of violations.

To extract without performing any other calculations, while using the object$model syntax: summary(model)$coefficients["rprice2","Std. Error"]


To obtain a matrix with the results of the linear regression:

> coef(summary(f))


To extract a specific value from the matrix:

> coef(summary(f))["rprice2","Std. Error"]
[1] 0.5139


As I understand it you want to do this in R:

f <- lm(speed~dist, data=cars)
coef(f)
confint(f)
sd = sqrt(diag(vcov(f)))
cbind("2.5 %"=-sd*1.96+coef(f),"97.5 %"=sd*1.96+coef(f))


Gives:

> coef(f)
(Intercept)        dist
8.2839056   0.1655676
> confint(f)
2.5 %     97.5 %
(Intercept) 6.5258378 10.0419735
dist        0.1303926  0.2007426
> cbind("2.5 %"=-sd*1.96+coef(f),"97.5 %"=sd*1.96+coef(f))
2.5 %    97.5 %
(Intercept) 6.5701120 9.9976992
dist        0.1312784 0.1998568

• Oops, sorry, I didn't spot your own vcov application nestled in the middle of the code before I wrote my answer. – conjugateprior Apr 18 '12 at 12:48
• @ConjugatePrior: That's Ok. Obviously my answer was a little unclear and your comments on the subject added more body to the answer :-) – Max Gordon Apr 18 '12 at 13:30