Combining multiple random forest models from Amelia Imputed data

I just created 40 imputed data sets using the Amelia package and they are stored in a.out.

Then I used the lapply function to create randomforest models on datasets:

rf.amelia.out = lapply(a.out$imputations, function(i) randomForest(y + x1+x2, data = i) ) 

Now I would like to combine these models in order to make a forecast for a bunch of a.test.out, which is a list of data calculated by amelia data.

I cannot figure out how to combine these random forest models. I tried the randomforest function to combine the function as combine(rf.amelia.out) , but that did not work. The problem is that rf.amelia.out not a model object, but is not rf.amelia.out[1] .

I also tried using zelig to automatically combine multiple models:

 rf.z.out = zelig(y~x1+x2, data = a.out, model = "rf") 

But I do not think that zelig supports random forest models.

How can I access and combine several random forest models so that I can make one prediction?

+5
source share
1 answer

Since rf.amelia.out already a list, the combine function in randomForest loses its methods when it tries to convert it to a list again. I recommend one of two fixes:

  • Modify the combine function, and then use the modified version:

    body(combine)[[4]] <- substitute(rflist <- (...))

    rf.all <- combine(rf.amelia.out)

  • Or use:

    combine(rf.amelia.out[[1]].rf.amelia.out[[2]],...)

I think the first way is simpler (and much less manual).

+2
source

All Articles