Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 407
user1888582 Avatar asked Oct 31 '22 05:10

user1888582


1 Answers

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:

  1. Change the combine function and then use the modified version:

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

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

  2. Or use:

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

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

like image 103
Mike.Gahan Avatar answered Nov 13 '22 06:11

Mike.Gahan