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?
In R, the lm summary produces the standard deviation of the error with a slight twist. Standard deviation is the square root of variance. Standard Error is very similar. The only difference is that instead of dividing by n-1, you subtract n minus 1 + # of variables involved.
The formula for standard error of mean is the standard deviation divided by the square root of the length of the data. It is relatively simple in R to calculate the standard error of the mean. We can either use the std. error() function provided by the plotrix package, or we can easily create a function for the same.
The standard error of the regression (S), also known as the standard error of the estimate, represents the average distance that the observed values fall from the regression line. Conveniently, it tells you how wrong the regression model is on average using the units of the response variable.
The lm() function is used to fit linear models to data frames in the R Language. It can be used to carry out regression, single stratum analysis of variance, and analysis of covariance to predict the value corresponding to data that is not in the data frame.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With