El-
El-

Reputation: 168

Error in lme4::allFit() -- no applicable method for 'isGLMM'

I'm hitting a confusing error while trying to run the lme4::allFit() using some built-in parallelization. I fit an initial model m0, which uses a larger dataframe ckDF (n = 265,623 rows) to model a binary response to a number of categorical and continuous predictors in a logistic framework with a random intercept for year.

I'm interested in determining whether different optimizers yield different results, following some recommendations I've found online (e.g. by @BenBolker here). My data is fairly large and takes ~20 minutes to run usually, so I'm hoping to use the parallel and ncpus parameters of allFit() to speed it up a bit. Here's my relevant code:

require(lme4)
require(parallel)

m0 <- glmer(returned ~ 1 + barge + site + barge:site + 
            (run + rearType + basin)^2 + 
            (tdg + temp + holdingTime)^2 +
            (1|year), 
            data = ckDF, family = 'binomial',
            control = glmerControl(optimizer='bobyqa', 
                                   optCtrl = list(maxfun = 1e5)))
af1 <- allFit(m0, parallel = 'multicore', ncpus = detectCores())

Upon doing this, I encounter the following error:

Error in checkForRemoteErrors(val) : 7 nodes produced errors; first error: no applicable method for 'isGLMM' applied to an object of class "list"

Any ideas? It seems to me that when it constructs a bunch of nodes, somehow some of them don't import the lme4 package and thus do not recognize isGLMM(); but I don't know why allFit() would do this, since it's from lme4(). I tried looking under the hood and altering the function for my own allFit() package, but ran into other errors.

Any help would be appreciated. R Version: 3.6.1; lme4 Version: 1.1-21; platform: Windows 10 64-bit

Upvotes: 2

Views: 238

Answers (1)

El-
El-

Reputation: 168

Thanks to @user20650 & @Ben Bolker for the tips in comments above -- it worked and I was able to get allFit() to run as expected, by ensuring I use parallel = "snow" in my function call since I'm running in Windows. Just posting the edited code here for anyone else who finds this useful:

require(lme4); require(snow)

# Define initial model (switched to defaults here)
m0 <- glmer(returned ~ 1 + barge + site + barge:site + 
            (run + rearType + basin)^2 + 
            (tdg + temp + holdingTime)^2 +
            (1|year), 
            data = ckDF, family = 'binomial')

# Set up cluster for running allFit()
optCls <- makeCluster(detectCores()-1, type = "SOCK")
clusterEvalQ(optCls,library("lme4"))
clusterExport(optCls, "ckDF")

# Use allFit() to look at differences in optimizers
system.time(af1 <- allFit(m0, parallel = 'snow', 
                          ncpus = detectCores()-1, cl=optCls))
stopCluster(optCls)

Ended up taking ~40 minutes using 11 cores on my machine.

Upvotes: 2

Related Questions