rnagammumin

MuMIn dredge gam error using default na.omit


I have a global model I'm trying to dredge, but I keep getting the error "Error in dredge(myglobalmod, evaluate = TRUE, trace = 2) : 'global.model' uses 'na.action' = "na.omit"

I tried running the global model with na.action="na.omit" within the gam() call and leaving it out (since it's the default).

myglobalmod <- gam(response~ s(x1) + s(x2) + s(x3) + offset(x4), data=mydata, family="tw", na.action="na.omit")

options(na.action=na.omit)
mydredge <- dredge(myglobalmod, evaluate=TRUE, trace=2)

When I didn't include na.action="na.omit" within the gam, I got a similar error. I then tried with a subset of the data that has all the NA rows removed, but same error.

I've gotten dredge to work before so I'm not sure why it doesn't like the na.omit now, I'm using the same code.


Solution

  • MuMIn insists that you use na.action = na.fail, in order to ensure that the same data set is used for every model (if NA values were left in the data set, different subsets could be used for different models depending on which variables were used). You can use na.omit(mydata) or mydata[complete.cases(mydata), ] to get rid of NA values before you start (assuming that the NA values in your data set occur only in variables you will be using for the full model).

    > library(MuMIn)
    > m1 <- lm(mpg ~ ., data = mtcars)
    > d0 <- dredge(m1)
    

    Error in dredge(m1) : 'global.model''s 'na.action' argument is not set and options('na.action') is "na.omit"

    > m1 <- lm(mpg ~ ., data = mtcars, na.action = na.fail)
    > d1 <- dredge(m1)
    Fixed term is "(Intercept)"