在使用MICE包在 R 中进行插补后,我想生成列联表。拟合显示列表中的表格,但如果我 pool()
是它们,则会引发以下错误:Error in pool(fit) : Object has no coef() method.
我在做什么错?
这个基本示例重现了错误:
library("mice")
imp <- mice(nhanes)
fit <- with(imp, table(bmi, hyp))
est <- pool(fit)
在使用MICE包在 R 中进行插补后,我想生成列联表。拟合显示列表中的表格,但如果我 pool()
是它们,则会引发以下错误:Error in pool(fit) : Object has no coef() method.
我在做什么错?
这个基本示例重现了错误:
library("mice")
imp <- mice(nhanes)
fit <- with(imp, table(bmi, hyp))
est <- pool(fit)
该函数mice::pool(object)
使用“鲁宾规则”简单地计算标量估计值的估计值和标准误差,为此它依赖于经常使用 提取估计值的事实coef(object)
,并且这些估计值的标准误差通常在 的对角线上可用vcov(object)
。它旨在与类的对象一起使用,这些对象lm
具有整齐定义的coef
和方法。vcov
在您的示例中,鲁宾的规则不适用。列联表中条目的“估计”和“标准错误”是什么?出于这个原因,pool
抱怨没有可用于从您的fit
.
因此,如果您的“估计”只是应该是“平均”列联表,试试这个:
library("mice")
imp <- mice(nhanes)
fit <- with(imp, table(bmi, hyp))
est <- pool(fit)
# dimensions
nl <- length(fit$analyses)
nr <- nrow(fit$analyses[[1]])
nc <- ncol(fit$analyses[[1]])
# names
rnames <- rownames(fit$analyses[[1]])
cnames <- colnames(fit$analyses[[1]])
# cast list to array
fit.arr <- array(unlist(fit$analyses), dim=c(nr,nc,nl),
dimnames=list(rnames,cnames))
# get "mean" contingency table
apply(fit.arr, 1:2, mean)
# 1 2
# 20.4 1.8 0.0
# 21.7 1.4 0.0
# 22 1.4 0.2
# 22.5 1.8 0.4
# 22.7 1.2 0.4
# 24.9 1.2 0.0
# 25.5 1.0 1.6
# 26.3 0.0 1.0
# 27.2 0.4 1.0
# 27.4 1.4 0.4
# 27.5 1.6 0.2
# 28.7 0.0 1.0
# 29.6 1.0 0.2
# 30.1 1.8 0.2
# 33.2 1.0 0.0
# 35.3 1.2 0.2
然而,“平均”表是否有用可能是值得商榷的。