简体   繁体   English

Amelia + CEM + Zelig错误

[英]Amelia + CEM + Zelig errors

I am currently trying to write a paper where I need to match on key pre-treatment covariates contained in a multiply imputed data set, and then run a linear regression on this data. 我目前正在尝试写一篇论文,在这里我需要匹配多重插补数据集中包含的关键预处理协变量,然后对该数据进行线性回归。 I've been able to write code to get zelig to run a linear regression on the multiply imputed data that I got from amelia . 我已经能够编写代码以使zelig对从amelia获得的多重估算数据进行线性回归。 Yet, when I try to use cem to match on key pre-treatment covariates, I cannot get zelig to run the model. 但是,当我尝试使用cem匹配关键的预处理协变量时,我无法让zelig运行该模型。 Here is the output rom my console: 这是我的控制台的输出:

> # Run Amelia, 5 imputations!      
>   complete <- amelia(clean, m = 5, ts = "wave", cs = "country", idvars = c("idnum", "strata", "weight"))     
-- Imputation 1 --

  1  2  3  4  5  6  7  8  9 10 11 12

-- Imputation 2 --

  1  2  3  4  5  6  7  8  9 10 11

-- Imputation 3 --

  1  2  3  4  5  6  7  8  9 10 11 12

-- Imputation 4 --

  1  2  3  4  5  6  7  8  9 10 11 12

-- Imputation 5 --

  1  2  3  4  5  6  7  8  9 10 11 12

>   
> # Estimate naive and controlled linear models with MI data sets using Zelig
>   
>   lm.out.naive <- zelig(dv ~ treat*year + treat + year,  data = complete, model = "ls")

>   lm.out.control <- zelig(dv~ treat*year + treat + year + age + gender + ideo + married, data = complete, model = "ls")

> # Estimate CEM linear model
> 
>   # First, generate matched data set
>     imputed <- complete$imputations[1:15]
>     matched <- cem("treat", drop = c("pais", "wave", "year", "idnum", "strata"),
+                         datalist = imputed, data = clean)
> 
>   # Then, run regression
>     lm.out.match <- zelig(dv ~ treat*year + treat + year + age + gender + ideo + married, data = matched, model = "ls")

Error in resolve_vars(new_groups, tbl_vars(.data)) : 
  unknown variable to group by : by

I am not understanding what the last error means and why I can't run a regression on the matched data set after using multiple imputation. 我不明白最后一个错误的含义以及为什么在使用多重插补后不能对匹配的数据集进行回归。 Any insight on this issue would be highly appreciated! 任何对此问题的见解将不胜感激!

I recently experienced this error using zelig 's logit on a multiply imputed data frame. 我最近在多重插补数据帧上使用zelig的logit遇到了此错误。 My solution was to properly specify the data = parameter. 我的解决方案是正确指定data =参数。 You might try this: 您可以尝试以下方法:

lm.out.match <- zelig(dv ~ treat*year + treat + year + 
age + gender + ideo + married, data = mi(matched$imputations), model = "ls")

I recall that an old version of zelig did not require this format, but instead seemed to handle the "amelia" class object as-is. 我记得旧版本的zelig不需要这种格式,而是似乎按原样处理“ amelia”类对象。

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

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