amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
444 stars 107 forks source link

pool.compare () with glmer models #80

Closed guqian7 closed 6 years ago

guqian7 commented 6 years ago

Hi,

I tried to use pool.compare ( ) with the likelihood ratio test to compare two nested generalized linear mixed models and received the error below, not meaningful for factors Error in model.matrix(formula, data) %*% coefs : non-conformable arguments

Looking at the MICE documentation, I understand that pool.compare ( ) can be used to compare glm models. I am wondering if it can be applied to compare models that use glmer () function.

Thank you very much in advance!

Best, Christina

gerkovink commented 6 years ago

Dear Christina,

I assume you are using method = 'likelihood'. If you change method to method = 'Wald', pooling should be without error.

All the best,

Gerko

Example. (ignore the warnings as this model is for demonstration purposes only and makes no sense)

set.seed(123) require(mice) require(lme4) imp <- mice(boys, maxit = 2, print = FALSE) fit1 <- with(imp, glmer(gen > levels(gen)[1] ~ hgt + hc + (1 | reg), family = binomial)) fit0 <- with(imp, glmer(gen > levels(gen)[1] ~ hgt + (1 | reg), family = binomial)) pool.compare(fit1, fit0, method = 'Wald', data = imp)

$call pool.compare(fit1 = fit1, fit0 = fit0, data = imp, method = "Wald")

$call11 with.mids(data = imp, expr = glmer(gen > levels(gen)[1] ~ hgt + hc + (1 | reg), family = binomial))

$call12 mice(data = boys, maxit = 2, printFlag = FALSE)

$call01 with.mids(data = imp, expr = glmer(gen > levels(gen)[1] ~ hgt + (1 | reg), family = binomial))

$call02 mice(data = boys, maxit = 2, printFlag = FALSE)

$method [1] "Wald"

$nmis age hgt wgt bmi hc gen phb tv reg 0 20 4 21 46 503 503 522 3

$m [1] 5

$qhat1 (Intercept) hgt hc 1 -2.1666612 0.06117918 -0.10797576 2 -4.2998347 0.05765916 -0.05784833 3 -1.4824611 0.05910641 -0.11514007 4 -2.7783433 0.05201541 -0.07235910 5 -0.4613964 0.05797049 -0.13051348

$qhat0 (Intercept) hgt 1 -6.280756 0.04961243 2 -6.544764 0.05173511 3 -5.847635 0.04660007 4 -5.525704 0.04422668 5 -5.348243 0.04338951

$qbar1 (Intercept) hgt hc -2.23773932 0.05758613 -0.09676735

$qbar0 (Intercept) hgt -5.90942031 0.04711276

$ubar1 (Intercept) hgt hc (Intercept) 3.360560697 8.394187e-03 -0.0848306001 hgt 0.008394187 3.799082e-05 -0.0002566967 hc -0.084830600 -2.566967e-04 0.0022743883

$ubar0 (Intercept) hgt (Intercept) 0.203090231 -1.226681e-03 hgt -0.001226681 9.296925e-06

$Dm [,1] [1,] 2.763751

$rm [1] 0.4896841

$df1 [1] 1

$df2 [1] 37.01829

$pvalue [,1] [1,] 0.104868

gerkovink commented 6 years ago

I'll look into the error you've received when using method = 'likelihood'. Can you give me some details on the model you're trying to run? Perhaps your issue is the same as the one mentioned in #77?

All the best,

Gerko

guqian7 commented 6 years ago

Dear Gerko,

Thank you very much for your prompt reply! I just tried to compare the models using the Wald method, and it worked perfectly. I am a beginner in statistics. When I looked at the MICE documentation, I thought the Wald test could only be used when the outcome is continuous, while the likelihood ratio test should be used when the outcome is binary. I just learned that both can be applied to compare generalized models although the hypotheses are slightly different.

The models I tried to compare were two random intercept models with binary outcomes, similar to the example you provided above. fit1 <- with(imp, glmer(HEIC_cat~BMI_cat+age_cat+gender + (1| FSA), family= "binomial", nAGQ = 0, control=glmerControl(optimizer = "bobyqa", optCtrl=list(maxfun=2e4))))

fit2 <- with(imp, glmer(HEIC_cat~BMI_cat+age_cat+gender+income+(1|_FSA), family= "binomial", nAGQ = 0, control=glmerControl(optimizer = "bobyqa", optCtrl=list(maxfun=2e4))))

test<-pool.compare(fit2, fit1, method = "likelihood", data =imp)

As I mentioned earlier, using method = "Wald" did solve my problem. However, method = "likelihood" resulted in the error messages that were the same as the one in #77. Unfortunately, I do not have a strong statistics and coding background, so I am not sure how to alter that piece of code to compare glmm using the likelihood ratio test.

Thank you very much for your time!

Best, Christina