用 R 中的 MICE 乘以估算数据后的列联表

Contingency tables after multiply imputated data with MICE in R

使用 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) 只是使用 "Rubin's rules" 计算标量估计值的估计值和标准误差,因为它依赖于通常使用 coef(object) 提取估计值这一事实,并且这些估计的标准误差通常在 vcov(object) 的对角线上可用。它旨在与 类 的对象一起使用,例如 lm,它们具有整齐定义的 coefvcov 方法。

在你的例子中,鲁宾的规则不适用。意外 table 中条目的 "estimates" 和 "standard errors" 是什么?出于这个原因,pool 抱怨没有可用的方法从您的 fit.

中提取系数

因此,如果您的 "estimate" 只是被认为是 "average" 偶然事件 table,请试试这个:

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

不管"average"table有没有用,不过,大概是debatable.