cleo wolfki cleo wolfki - 1 month ago 8
LaTeX Question

Extract average model from MuMIn for latex output

I'm trying to extract two different averaged models from

MuMIn
for output to latex via
texreg
or
stargazer
. I'd like to have one table where I can compare two species' response to different sets of abiotic variables, that looks the same as one created from two model objects using

glmtable <- texreg(list(m1, m2).


The above code will work on glm objects but not on averaged model objects created in
MuMIn
.

I tried following an example at https://sites.google.com/site/rforfishandwildlifegrads/home/mumin_usage_examples, to output a text table that can be output to latex.

Here's a reproducible example using the cement data:

library(MuMIn)
data(cement)

# full model
fm1 <- lm(y ~ ., data = Cement, na.action = na.fail)
# create and examine candidate models
(ms1 <- dredge(fm1))

# average models with delta AICc <5, include adjusted SE
MA.ests<-model.avg(ms1, subset= delta < 5, revised.var = TRUE)


This works fine. However when I call

MA.ests$avg.model


I get >NULL.

Has avg.model been deprecated? Or is there another way to do this?

I can do a workaround using any of these three calls, but they're not exactly what I want.

coefTable(MA.ests)
coef(MA.ests)
modavg.table <- as.data.frame(summary(MA.ests)$coefmat)


(that is, I don't know how to get these objects into latex without a lot more code.)

Thanks in advance for any suggestions.

Answer

The latest version 1.34.3 of the texreg package supports both model.selection and averaging objects.

Your code example:

library("texreg")
library("MuMIn")
data(cement)
fm1 <- lm(y ~ ., data = Cement, na.action = na.fail)
ms1 <- dredge(fm1)

screenreg(ms1)

yields:

==========================================================================================================================================================================================================
                Model 1     Model 2     Model 3     Model 4     Model 5     Model 6     Model 7   Model 8     Model 9     Model 10    Model 11    Model 12  Model 13    Model 14    Model 15    Model 16  
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(Intercept)      52.58 ***   71.65 ***   48.19 ***  103.10 ***  111.68 ***  203.64 ***   62.41    131.28 ***   72.07 ***  117.57 ***   57.42 ***   94.16     81.48 ***   72.35 ***  110.20 ***   95.42 ***
                 (2.29)     (14.14)      (3.91)      (2.12)      (4.56)     (20.65)     (70.07)    (3.27)      (7.38)      (5.26)      (8.49)     (56.63)    (4.93)     (17.05)      (7.95)      (4.17)   
X1                1.47 ***    1.45 ***    1.70 ***    1.44 ***    1.05 ***                1.55 *                                                              1.87 ***    2.31 *                          
                 (0.12)      (0.12)      (0.20)      (0.14)      (0.22)                  (0.74)                                                              (0.53)      (0.96)                           
X2                0.66 ***    0.42 *      0.66 ***                           -0.92 ***    0.51                  0.73 ***                0.79 ***    0.31                                                  
                 (0.05)      (0.19)      (0.04)                              (0.26)      (0.72)                (0.12)                  (0.17)      (0.75)                                                 
X4                           -0.24                   -0.61 ***   -0.64 ***   -1.56 ***   -0.14     -0.72 ***               -0.74 ***               -0.46                                                  
                             (0.17)                  (0.05)      (0.04)      (0.24)      (0.71)    (0.07)                  (0.15)                  (0.70)                                                 
X3                                        0.25                   -0.41 *     -1.45 ***    0.10     -1.20 ***   -1.01 ***                                                  0.49       -1.26 *              
                                         (0.18)                  (0.20)      (0.15)      (0.75)    (0.19)      (0.29)                                                    (0.88)      (0.60)               
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Log Likelihood  -28.16      -26.93      -26.95      -29.82      -27.31      -29.73      -26.92    -35.37      -40.96      -45.87      -46.04      -45.76    -48.21      -48.00      -50.98      -53.17    
AICc             69.31       72.44       72.48       72.63       73.19       78.04       79.84     83.74       94.93      100.41      100.74      104.52    105.08      109.01      110.63      111.54    
Delta             0.00        3.13        3.16        3.32        3.88        8.73       10.52     14.43       25.62       31.10       31.42       35.21     35.77       39.70       41.31       42.22    
Weight            0.57        0.12        0.12        0.11        0.08        0.01        0.00      0.00        0.00        0.00        0.00        0.00      0.00        0.00        0.00        0.00    
Num. obs.        13          13          13          13          13          13          13        13          13          13          13          13        13          13          13          13       
==========================================================================================================================================================================================================
*** p < 0.001, ** p < 0.01, * p < 0.05

And model averaging:

MA.ests <- model.avg(ms1, subset = delta < 5, revised.var = TRUE)

screenreg(MA.ests)

yields:

=======================
             Model 1   
-----------------------
(Intercept)   64.69 ** 
             (22.24)   
X1             1.46 ***
              (0.20)   
X2             0.63 ***
              (0.12)   
X4            -0.48 *  
              (0.22)   
X3            -0.02    
              (0.38)   
-----------------------
Num. obs.     13       
=======================
*** p < 0.001, ** p < 0.01, * p < 0.05

For finetuning, see also the arguments of the two extract methods on the help page: ?extract

Comments