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

后端 未结 3 1105
执笔经年
执笔经年 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:35

    Here an option:

    1. put your data in the long format using regressor as an id key.
    2. do your regression against value by group of variable.

    For example , using mtcars data set:

    library(reshape2)
    dat.m <- melt(mtcars,id.vars='mpg')  ## mpg is my regressor
    library(plyr)
    ddply(dat.m,.(variable),function(x)coef(lm(variable~value,data=x)))
      variable (Intercept)         value
    1       cyl           1  8.336774e-18
    2      disp           1  6.529223e-19
    3        hp           1  1.106781e-18
    4      drat           1 -1.505237e-16
    5        wt           1  8.846955e-17
    6      qsec           1  6.167713e-17
    7        vs           1  2.442366e-16
    8        am           1 -3.381738e-16
    9      gear           1 -8.141220e-17
    10     carb           1 -6.455094e-17
    

提交回复
热议问题