Reputation: 2095
We got a lm object from and want to extract the standard error
lm_aaa <- lm(aaa ~ x + y + z)
I know the function summary, names and coefficients.
However, summary seems to be the only way to manually access the standard error.
Have you any idea how I can just output se?
Upvotes: 36
Views: 93785
Reputation: 455
I think that the following lines can also provide you with a quick answer:
lm_aaa<- lm(aaa~x+y+z)
se <- sqrt(diag(vcov(lm_aaa)))
Upvotes: 5
Reputation: 487
If you don't want to get the standard error/deviation of the model, but instead the standard error/deviation of the individual coefficients, use
# some data (taken from Roland's example)
x = c(1, 2, 3, 4)
y = c(2.1, 3.9, 6.3, 7.8)
# fitting a linear model
fit = lm(y ~ x)
# get vector of all standard errors of the coefficients
coef(summary(fit))[, "Std. Error"]
For more information on the standard error/deviation of the model, see here. For more information on the standard error/deviation of the coefficients, see here.
Upvotes: 8
Reputation: 5351
To get a list of the standard errors for all the parameters, you can use
summary(lm_aaa)$coefficients[, 2]
As others have pointed out, str(lm_aaa)
will tell you pretty much all the information that can be extracted from your model.
Upvotes: 14
Reputation: 60522
The output of from the summary
function is just an R list. So you can use all the standard list operations. For example:
#some data (taken from Roland's example)
x = c(1,2,3,4)
y = c(2.1,3.9,6.3,7.8)
#fitting a linear model
fit = lm(y~x)
m = summary(fit)
The m
object or list has a number of attributes. You can access them using the bracket or named approach:
m$sigma
m[[6]]
A handy function to know about is, str
. This function provides a summary of the objects attributes, i.e.
str(m)
Upvotes: 29
Reputation: 132999
#some data
x<-c(1,2,3,4)
y<-c(2.1,3.9,6.3,7.8)
#fitting a linear model
fit<-lm(y~x)
#look at the statistics summary
summary(fit)
#get the standard error of the slope
se_slope<-summary(fit)$coef[[4]]
#the index depends on the model and which se you want to extract
#get the residual standard error
rse<-summary(fit)$sigma
Upvotes: 11