R' mice
包含一个函数pool.compare
,用于比较适合插补对象的嵌套模型。如果我尝试包含交互术语:
library(mice)
imput = mice(nhanes2)
mi1 <- with(data=imput, expr=lm(bmi~age*hyp))
mi0 <- with(data=imput, expr=lm(bmi~age+hyp))
pc <- pool.compare(mi1, mi0, method="Wald")
然后它返回以下错误:
Error in pool(fit1) :
Different number of parameters: coef(fit): 6, vcov(fit): 5
听起来方差 - 协方差矩阵并不包含交互项作为其自己的变量。最好的方法是什么?
答案 0 :(得分:3)
问题似乎是某些参数在某些估算数据集中无法估算。当我运行代码时,我看到了
( fit1<-mi1$analyses[[1]] )
# lm(formula = bmi ~ age * hyp)
#
# Coefficients:
# (Intercept) age2 age3 hyp2 age2:hyp2
# 28.425 -5.425 -3.758 1.200 3.300
# age3:hyp2
# NA
在这一组中,无法估计age3*hyp2
(可能是因为该组中没有观察结果)。
这会导致coef(fit1)
和vcov(fit1)
出现差异,因为无法估算该字词的协方差。
在这种情况下,做什么更多是统计问题,而不是编程问题。如果您不确定哪些内容适合您的数据,建议您在Cross Validated咨询统计员。