0
votes

I'm using the MuMln package in R to get an averaged model (http://www.inside-r.org/packages/cran/MuMIn/docs/model.avg), and predict from that. The package also includes a predict function specifically for an object returned by model.avg (http://www.inside-r.org/node/123636). I've tried using the examples listed, code as follows:

   # Example from Burnham and Anderson (2002), page 100: 
     fm1 <- lm(y ~ X1 + X2 + X3 + X4, data = Cement)

     ms1 <- dredge(fm1)

  # obtain model average for AIC delta <2
    avgm <- model.avg(ms1, subset=delta<2)

  # predict from the averaged model
    averaged.full <- predict(avgm, full = TRUE)

But I keep getting

Error in predict.averaging(avgm, full = TRUE): can predict only from 'averaging' object containing model list

which I don't understand, because I did follow the examples and used an object returned by model.avg. Am I missing something?

1

1 Answers

3
votes

When you create an "averaging" object directly from "model.selection" object, it does not contain the component models, which are required for predict to work. You can use model.avg(..., fit = TRUE) which will fit the models again.

To avoid fitting the models twice, you can first create a list of all models with lapply(dredge(..., evaluate = FALSE), eval) and afterwards use model.avg(..., subset = ...) on it.