一种方法是遍历complete
数据集,然后将mira
类分配给列表,这应该允许pool
。(这真的是什么mice:::with.mids
)
没有抽样的例子
library(mice)
imp <- mice(nhanes,m=2, maxit=5, seed=1)
# With in-built pooling
pool(with(imp, lm(bmi ~ chl + age)))
# Pooled coefficients:
# (Intercept) chl age
# 21.38496144 0.05975537 -3.40773396
#
# Fraction of information about the coefficients missing due to nonresponse:
# (Intercept) chl age
# 0.6186312 0.1060668 0.7380962
# looping manually
mod <- list(analyses=vector("list", imp$m))
for(i in 1:imp$m){
mod$analyses[[i]] <- lm(bmi ~ chl + age, data=complete(imp, i))
}
class(mod) <- c("mira", "matrix")
pool(mod)
# Pooled coefficients:
# (Intercept) chl age
# 21.38496144 0.05975537 -3.40773396
#
# Fraction of information about the coefficients missing due to nonresponse:
# (Intercept) chl age
# 0.6186312 0.1060668 0.7380962
看起来不错,所以添加一个采样程序
mod <- list(analyses=vector("list", imp$m))
set.seed(1)
for(i in 1:imp$m){
rand <- (1:nrow(nhanes))*rbinom(nrow(nhanes),size=1,prob=0.7)
mod$analyses[[i]] <- lm(bmi ~ chl + age, data=complete(imp, i)[rand,])
}
class(mod) <- c("mira", "matrix")
pool(mod)
# Pooled coefficients:
# (Intercept) chl age
# 21.72382272 0.06468044 -4.23387415
#
# Fraction of information about the coefficients missing due to nonresponse:
# (Intercept) chl age
# 0.1496987 0.4497024 0.6101340