Search code examples
rlme4r-micemodel-comparisonlmertest

mice's pool.compare gives "Error: No glance method for objects of class call" for lmerTest models


I'm trying to compare two models built using multiple imputations. When I try to compare the models, mice's pool.compare() gives the error that Error: No glance method for objects of class call or Error: unequal number of imputations for 'fit1' and 'fit0', even though I'm using the same imputed dataset. Here is a reproducible example:

library(mice)
library(miceadds)
library(lmerTest)

imp <- mice(nhanes, maxit = 2, m = 4)

summary(m0 <- pool(with(imp, lmerTest::lmer(bmi ~ 1 + (1 | chl)))))

summary(m1 <- pool(with(imp, lmerTest::lmer(bmi ~ 1 + hyp + (1 | chl)))))

pool.compare(m0, m1)

Error: No glance method for objects of class call

Solution

  • You need to compare the objects before pooling. And the order matters, m1 > m0. (Note: I used lme4 here.)

    library(mice)
    library(miceadds)
    
    set.seed(42)
    imp <- mice(nhanes, maxit = 2, m = 4)
    
    summary(pool(m0 <- with(imp, lme4::lmer(bmi ~ 1 + (1 | chl)))))
    # boundary (singular) fit: see ?isSingular
    # estimate std.error statistic       df      p.value
    # (Intercept) 26.60791 0.9722573  27.36715 18.24326 4.440892e-16
    summary(pool(m1 <- with(imp, lme4::lmer(bmi ~ 1 + hyp + (1 | chl)))))
    # boundary (singular) fit: see ?isSingular
    # estimate std.error  statistic       df      p.value
    # (Intercept) 27.2308286  3.759095  7.2439857 5.181367 0.0006723643
    # hyp         -0.5310514  2.746281 -0.1933711 4.928222 0.8543848658
    
    pool.compare(m1, m0)
    # $call
    # pool.compare(fit1 = m1, fit0 = m0)
    # 
    # $call11
    # with.mids(data = imp, expr = lme4::lmer(bmi ~ 1 + hyp + (1 | 
    #                                                            chl)))
    # 
    # $call12
    # mice(data = nhanes, m = 4, maxit = 2)
    # 
    # $call01
    # with.mids(data = imp, expr = lme4::lmer(bmi ~ 1 + (1 | chl)))
    # 
    # $call02
    # mice(data = nhanes, m = 4, maxit = 2)
    # 
    # $method
    # [1] "wald"
    # 
    # $nmis
    # age bmi hyp chl 
    # 0   9   8  10 
    # 
    # $m
    # [1] 4
    # 
    # $qbar1
    # (Intercept)         hyp 
    # 27.2308286  -0.5310514 
    # 
    # $qbar0
    # (Intercept) 
    # 26.60791 
    # 
    # $ubar1
    # [1] 6.916910 3.560812
    # 
    # $ubar0
    # [1] 0.8786098
    # 
    # $deviances
    # NULL
    # 
    # $Dm
    # [,1]
    # [1,] 0.03739239
    # 
    # $rm
    # [1] 1.118073
    # 
    # $df1
    # [1] 1
    # 
    # $df2
    # [1] 10.76621
    # 
    # $pvalue
    # [,1]
    # [1,] 0.850268