2

Rmice包含一个函数 ,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

听起来方差 - 协方差矩阵不包括交互项作为其自己的变量。解决这个问题的最佳方法是什么?

4

1 回答 1

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的统计学家。

于 2015-04-21T15:41:23.710 回答