0

I am having a hard time wrapping my head around this problem. I have a list, results4 which contains 5 elements, all of which are mer objects from the zelig package. The mer objects are the result of ls.mixed regressions on each of five imputed datasets. I am trying to combine the results using Rubin's Rules for Multiple Imputation.

I can extract the coefficients and standard errors using summary(results4[[1]])@coefs, which returns a 16x3 vector (16 variables, each with a point estimate, standard error, and t-statistic).

I am trying to loop over the five sets of results and automate the process of combining the point estimates and standard errors, but unfortunately I seem to be staring at it with no solution arising. Any suggestions?

The code that produces the mer objects follows (variable names changed):

for (i in 1:5) {
  results4[i] <- zelig(DV ~ V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 +
  V9 + V10 + V11 + V12 + V13 + V14 + V15 + tag(1 | L2),
  data = as.data.frame(w4[,,i]), model = "ls.mixed", REML = FALSE) 
}
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • How can a coerced array with only 2 dimensions (after dropping) end up having that many variables? You should look at the structure of `as.data.frame(w4[,,1])`. – IRTFM Jul 08 '11 at 21:10
  • should that be `results4[[i]]` ? – Ben Bolker Jul 08 '11 at 21:55
  • Yes, should be results4[[i]]. DWin -- not sure what you're talking about, the regression has 15 predictor variables. The regressions run fine. –  Jul 08 '11 at 23:31

1 Answers1

0

I'm not going to take the time to code up the multiple-imputation rules (someone who wants the credit can what I show here and build on it), but I think you should be able to do what you want by building a 16x3x5 array containing the results:

resultsList <- lapply(results,function(x) summary(x)@coefs)
library(abind)
resultsArr <- abind(resultsList,along=3)

and then using apply appropriately across the margins.

There's probably a plyr-based solution as well.

You could also do this less fancily by just defining the array up front and filling it in as you go:

sumresults <- array(dim=c(16,3,5))
for (...) {
   ...
   sumresults[,,i] <- summary(results4[[i]])@coefs
}
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Ah, yes, I wasn't looking to have anyone actually code up the rules, just point me int he right direction for the iteration. I'll give this a shot and update. Thanks! –  Jul 08 '11 at 23:24