rmodelingglmmtmb

Error when using MuMIn dredge function: could not find function glmmTMB


I'm attempting to dredge a model fitted with glmmTMB and keep getting the following warning for each model subset: "In glmmTMB(... : could not find function "glmmTMB"" and subsequent error: "Error in .dredge.par(global.model = m, evaluate = T, rank = "AIC", m.lim = c(0, : the result is empty"

I've tried searching this error but it seems like I'm the only one getting it. I have both the glmmTMB (version 1.1.7) and MuMIn (version 1.47.5) packages loaded and I've updated both of them.

Here is the code I have for the dredge function:

library(MuMIn)
library(glmmTMB)
library(parallel)

#first create a cluster to parallelize dredge 
nCores <- detectCores() - 1
clusterType <- if(length(find.package("snow", quiet = TRUE))) "SOCK" else "PSOCK"
clust <- try(makeCluster(getOption("cl.cores", nCores), type = clusterType))

#model
m <- glmmTMB(Used ~ x1 + x2 + x3 + x4 + x5 + x6 +  
                 x7 + x8 + x1*x2 + (1|group), data = data, 
                 family = binomial)

options(na.action = "na.fail")
dredged43 <- dredge(m, beta = "sd", evaluate = T, rank = "AIC", m.lim = c(0,9),
                    trace = 2, cluster = clust)
options(na.action = "na.omit")

And here is some data for reproducibility:

set.seed(101)
data <- data.frame(Used = factor(sample(0:1,size=200,replace=T)),
                   x1=factor(sample(0:1,size=200,replace=T)),x2=rnorm(200),x3=rnorm(200),
                   x4=rnorm(200),x5=rnorm(200),x6=rnorm(200),x7=rnorm(200),
                   x8=rnorm(200), group=factor(rep(1:10,each=20)))

I feel like this is probably just some weird error with one of the package versions I have but any advice would be useful. Thanks!


Solution

  • You almost certainly need something like

    clusterEvalQ(clust, library('glmmTMB'))
    

    before you issue the dredge command. As the help file pointed out in the comments indicates,

    All the dependencies for fitting the global.model, including the data and any objects that the modelling function will use must be exported to the cluster worker nodes (e.g. via clusterExport). The required packages must be also loaded thereinto (e.g. via clusterEvalQ(..., library(package)), before the cluster is used by pdredge.