Search code examples
rregressionlmstandard-error

Extract standard errors from lm object


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?


Solution

  • 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)