Obtain standard errors of regression coefficients for an “mlm” object returned by `lm()`

后端 未结 3 1114
执笔经年
执笔经年 2020-12-21 05:08

I\'d like to run 10 regressions against the same regressor, then pull all the standard errors without using a loop.

depVars <- as.matrix(         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 05:24

    If you put your data in long format it's very easy to get a bunch of regression results using lmList from the nlme or lme4 packages. The output is a list of regression results and the summary can give you a matrix of coefficients, just like you wanted.

    library(lme4)
    
    m <- lmList( y ~ x | group, data = dat)
    summary(m)$coefficients
    

    Those coefficients are in a simple 3 dimensional array so the standard errors are at [,2,2].

提交回复
热议问题