title: Pooling glmers of imputed datasets
body: <p>The problem:</p>
  
  <p>I have a dataset, with some missing predictor values. I'd like to pool <code>glmer</code> models together which have been applied to these imputation sets. I'm using the <code>mice</code> package to create the imputations (I've also used <code>amelia</code> and <code>mi</code> too with no success). I'd like to extract the fixed effects primarily.</p>
  
  <p>Using the <code>pool()</code> function within the mice package returns the error:</p>
  
  <pre><code>Error in qhat[i, ] : incorrect number of dimensions
  </code></pre>
  
  <p>I've tried to use and adapt a previous rewrite of the <code>pool()</code> function here:</p>
  
  <p><a href="https://github.com/stefvanbuuren/mice/pull/5" rel="nofollow">https://github.com/stefvanbuuren/mice/pull/5</a></p>
  
  <p>There's probably an obvious solution I'm overlooking!</p>
  
  <p>Here's an example:</p>
  
  <pre><code># 1. create data (that can be replicated and converge later)
  
  data = data.frame(x1=c(rep("1",0.1*1000), rep("0",0.5*1000), 
                         rep("1",0.3*1000), rep("0",0.1*1000)), 
                    x2=c(rep("fact1",0.55*1000), rep("fact2",0.1*1000), 
                         rep(NA,0.05*1000), rep("fact3",0.3*1000)),
                    centre=c(rep("city1",0.1*1000), rep("city2",0.2*1000), 
                             rep("city3",0.15*1000), rep("city1",0.25*1000), 
                             rep("city2",0.3*1000)                          ))
  
  # 2. set factors
  data = sapply(data, as.factor)
  
  # 3. mice imputation 
  library(mice)
  imp.data = mice(data, m=5, maxit=20, seed=1234, pri=F) 
  
  # 4. apply the glmer function
  library(lme4)
  mice.fit = with(imp.data, glmer(x1~x2+(1|centre), family='binomial'))
  
  # 5. pool imputations together
  pooled.mi = pool(mice.fit)
  </code></pre>
  
  <p>The other function I've applied at step 4 is below, in the hope it'd create an object amenable to <code>pool()</code>.</p>
  
  <pre><code>mice.fit = lapply(imp.data$imp, function(d){ glmer(x1~x2+(1|centre), data=d, 
                                                     family='binomial')        })
  </code></pre>
  
  <p>I've got a work around that involves using a meta-analysis model to pool the results of each of the fixed effects of the <code>glmer</code> models. That works- but it'd be much better to have the Rubin model working.</p>