简体   繁体   中英

extract exponential coefficients from models MuMIn::dredge

I'm trying to exponentiate coefficients and standard errors from multiple Poisson models from a MuMIn::dredge object to use with texreg::screenreg . In the case of one model we can do this :

library(MuMIn)
library(texreg)
data(Cement)
m1 <- glm(X1 ~ y, data = Cement, na.action = "na.fail", family = poisson())
screenreg(m1)
# ==========================
#                 Model 1   
# --------------------------
# (Intercept)      -2.39 ** 
#                  (0.88)   
# y                 0.04 ***
#                  (0.01)   
# --------------------------
# AIC              76.03    
# BIC              77.16    
# Log Likelihood  -36.02    
# Deviance         26.76    
# Num. obs.        13       
# ==========================
# *** p < 0.001, ** p < 0.01, * p < 0.05



#EXP VERSION:
tr <- texreg::extract(m1)
screenreg(m1, override.coef = exp(tr@coef), override.se = exp(tr@se))
# ==========================
#                 Model 1   
# --------------------------
# (Intercept)       0.09 ** 
#                  (2.41)   
# y                 1.05 ***
#                  (1.01)   
# --------------------------
# AIC              76.03    
# BIC              77.16    
# Log Likelihood  -36.02    
# Deviance         26.76    
# Num. obs.        13       
# ==========================
# *** p < 0.001, ** p < 0.01, * p < 0.05
# Warning message:
# In override(models, override.coef, override.se, override.pvalues,  :
#   Standard errors were provided using 'override.se', but p-values were not replaced!

Now, if we use dredge to look at all combinations and get output without exponential values :

  fm1 <- glm(X1 ~ ., data = Cement, na.action = "na.fail", family = poisson())
dd <- dredge(fm1)
#shorten output
dd <- dd[1:4, ]
screenreg(dd)
# =============================================================
#                 Model 1    Model 2     Model 3     Model 4   
# -------------------------------------------------------------
# (Intercept)       0.98       3.95 ***    7.74 **     3.45 ***
#                  (1.02)     (0.33)      (2.07)      (0.23)   
# X3               -0.12 **   -0.16 ***   -0.15 ***   -0.15 ***
#                  (0.03)     (0.03)      (0.03)      (0.03)   
# y                 0.02 *                                     
#                  (0.01)                                      
# X4                          -0.02       -0.06 *              
#                             (0.01)      (0.03)               
# X2                                      -0.05                
#                                         (0.03)               
# -------------------------------------------------------------
# Log Likelihood  -24.98     -25.95      -24.22      -28.48    
# AICc             58.62      60.56       61.44       62.16    
# Delta             0.00       1.94        2.82        3.55    
# Weight            0.56       0.21        0.14        0.09    
# Num. obs.        13         13          13          13       
# =============================================================
# *** p < 0.001, ** p < 0.01, * p < 0.05

Now I'm not sure how to get all exponential values of the dd object, something like this is what I was thinking:

tr <- texreg::extract(dd)
screenreg(dd, override.coef = exp(tr@coef), override.se = exp(tr@se))

this wont work and I'm guessing theres a quick work around?

thanks

texreg 's extract method for the "averaging" object returns a list of texreg objects, with one element for each model. You need to apply @coef and @se to each element. For example:

library(MuMIn)
library(texreg)

dd <- dredge(lm(y ~ X1 * X2, Cement, na.action = na.fail))
tr <- extract(dd)

screenreg(x, override.coef = lapply(lapply(tr, slot, 'coef'), exp))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM