8
$\begingroup$
            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?

Sorry for the elementary question!

Thanks in advance...

$\endgroup$

closed as off-topic by Sven Hohenstein, Greenparker, John, gung, Sean Easter Jun 16 '16 at 13:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Sven Hohenstein, Greenparker, John, gung, Sean Easter
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ 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] $\endgroup$ – Macro Apr 18 '12 at 2:56
  • $\begingroup$ 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 $\endgroup$ – Aaron Apr 18 '12 at 3:37
  • 1
    $\begingroup$ 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]. $\endgroup$ – guest Apr 18 '12 at 3:46
9
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

To extract without performing any other calculations, while using the object$model syntax:

summary(model)$coefficients["rprice2","Std. Error"]
$\endgroup$
3
$\begingroup$

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 
$\endgroup$
1
$\begingroup$

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

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