Amelia + CEM + Zelig错误

时间:2017-02-27 23:30:34

标签: r statistics matching

我目前正在尝试撰写一篇论文,其中我需要匹配多次推算数据集中包含的关键预处理协变量,然后对此数据进行线性回归。我已经能够编写代码让zelig对我从amelia得到的乘法估算数据进行线性回归。然而,当我尝试使用cem来匹配关键的治疗前协变量时,我无法让zelig来运行模型。这是我的控制台的输出:

> # 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

我不明白最后一个错误的含义以及为什么我在使用多次插补后对匹配的数据集进行回归。对此问题的任何见解都将受到高度赞赏!

1 个答案:

答案 0 :(得分:0)

我最近在多重插补数据帧上使用zelig的logit时遇到了此错误。我的解决方案是正确指定data =参数。你可以试试这个:

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

我记得zelig的旧版本并不需要这种格式,而是似乎处理了#34; amelia&#34;类对象按原样。