0

我正在尝试比较使用多重插补构建的两个模型。当我尝试比较模型时,老鼠的 pool.compare() 给出了错误:错误:没有类调用对象的浏览方法或错误:'fit1'和'fit0'的插补数量不相等,即使我正在使用相同的估算数据集。这是一个可重现的示例:

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
4

1 回答 1

1

您需要在pooling 之前比较对象。顺序很重要,m1> m0。(注:我lme4在这里用过。)

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
于 2020-01-16T16:37:40.667 回答