I just created 40 imputed data sets using the Amelia package, and they are stored in a.out.
I then used the lapply function to create randomforest models on the data sets:
rf.amelia.out = lapply(a.out$imputations, function(i) randomForest(y + x1+x2, data = i) )
Now I would like to combine these models to make a prediction on a bunch a.test.out, which is a list of amelia imputed data testing data.
I can't figure out how to combine these random forest models. I've tried randomforest combine function like combine(rf.amelia.out)
but that didn't work. The problem is that rf.amelia.out
is not a model object, but neither is rf.amelia.out[1]
.
I also tried to use zelig to automatically combine multiple models:
rf.z.out = zelig(y~x1+x2, data = a.out, model = "rf")
But I don't think zelig supports random forest models.
How do I access and combine the multiple random forest models so that I can make one prediction?
Since rf.amelia.out
is 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:
Change 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 easier (and much less manual).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With