将嵌套小鼠模型与交互项进行比较
Comparing nested mice models with interaction terms
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")
然后returns出现以下错误:
Error in pool(fit1) :
Different number of parameters: coef(fit): 6, vcov(fit): 5
听起来方差-协方差矩阵不包括交互项作为它自己的变量。最好的解决方法是什么?
问题似乎是您的某些参数在您估算的 data.sets 中无法估计。当我 运行 代码时,我看到
( 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.
咨询统计学家
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")
然后returns出现以下错误:
Error in pool(fit1) :
Different number of parameters: coef(fit): 6, vcov(fit): 5
听起来方差-协方差矩阵不包括交互项作为它自己的变量。最好的解决方法是什么?
问题似乎是您的某些参数在您估算的 data.sets 中无法估计。当我 运行 代码时,我看到
( 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.
咨询统计学家