简体   繁体   English

使用鼠标 R 包进行多次插补后聚类稳健标准错误

[英]Cluster robust standard errors after multiple imputation using mice R package

I would like to compute cluster robust standard errors using a mids class object.我想使用 mids 类对象计算集群稳健标准误差。 This arise from multiple imputation of missing values in a column of my original data.这是由于在我的原始数据列中对缺失值进行了多次插补。 A minimal example below.下面是一个最小的例子。

 library(mice)
 y <- c(1,0,0,1,1,1,1,0)
 x <- c(26, 34, 55, 15, 31 ,47, 97, 12)
 z <- c(2, NA, 0, NA, 3 ,7,7, 5)
 mydata <- as.data.frame(cbind(y,x,z))


tempData <- mice(mydata,m=5,maxit=5,meth='pmm',seed=500)

class(tempData)
# [1] "mids"

modelFit <- with(tempData,lm(y ~  x + z))     
summary(modelFit) 

At this point I would like to get the cluster robust standard errors.在这一点上,我想获得集群健壮的标准错误。 Unfortunately miceadds::lm.cluster does not allow "mids" class objects.不幸的是 mouseadds::lm.cluster 不允许“mids”类对象。

The function lm.cluster in miceadds is intended for regular data frames.该功能lm.clustermiceadds适用于常规数据帧。 An example for an application to multiply imputed data is given in the documentation . 文档中给出了一个应用程序来乘以插补数据的示例。

Given below is a version adapted to your question.下面给出的是适合您问题的版本。 I used the first variables as a cluster indicator because your example didn't have one.我使用第一个变量作为集群指标,因为你的例子没有。

library(mice)
library(miceadds)

id <- c(1,0,0,1,1,1,1,0)
y <- c(26,34,55,15,31,47,97,12)
x <- c(2,NA,0,NA,3,7,7,5)

dat <- data.frame(id,y,x)

imp <- mice(dat, m=5, maxit=5, method='pmm', seed=500)
implist <- lapply(1:5, function(i) complete(imp,i))

mod <- lapply( implist, function(i){
  lm.cluster( i, formula=y~x, cluster=i$id )
})
# extract parameters and covariance matrices
betas <- lapply(mod, coef)
vars <- lapply(mod, vcov)
# pool
summary(pool_mi( qhat=betas, u=vars ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM