0

I fitted a mixed model of the following form:

global.mod <- lmer(log(y) ~ 
                       x1 + x2 + x3 + x4 + x5 + (1 + x1|a/b),
                       REML = FALSE, data = lmerDat,
                       na.action = 'na.fail', control = lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e4)))

I then use predge to create combinations of model below which works fine.

require(parallel) || require(snow)
clusterType <- if(length(find.package("snow", quiet = TRUE))) "SOCK" else "PSOCK"
clust <- try(makeCluster(getOption("cl.cores", 4), type = clusterType))
clusterEvalQ(clust, library(lme4))
clusterExport(clust, "lmerDat")

 model.set <- pdredge(global.mod, clust, 
                      m.lim = c(2, NA), rank = AIC, extra = "adjR^2", trace = 2)

I then tried to specify my models in a slightly different format as below:

 PredictorVariables <- names(lmerDat)[c(5:9)] # this is x1 till x5
 fixed.part <- paste("log(y) ~", paste(PredictorVariables, collapse=" + "))
 random.part <- paste('(1 + x1|a/b)')
 Formula <- formula(paste(fixed.part, random.part, sep = " + "))

 global.mod <- lmer(Formula, data = lmerDat, na.action = 'na.fail', control = 
 lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e4)), REML = FALSE)    

 require(parallel) || require(snow)

 clusterType <- if(length(find.package("snow", quiet = TRUE))) "SOCK" else "PSOCK"
 clust <- try(makeCluster(getOption("cl.cores", 4), type = clusterType))
 clusterEvalQ(clust, library(lme4))
 clusterExport(clust, "lmerDat")

 model.set <- pdredge(global.mod, clust, 
                      m.lim = c(2, NA), rank = AIC, extra = "adjR^2", trace = 2)

However, this gives me the follow error

 Error in sprintf(gettext(fmt, domain = domain), ...) : 
 invalid format '%d'; use format %f, %e, %g or %a for numeric objects

Unfortunately the latter is how I want to do the model specification since apriori I do not know what will be the names of the predictors in names(lmerDat)[c(5:9)]. Could anyone help me understand the error and how to resolve it?

EDIT

my traceback output is as follows (please note that this is on my original data instead of the dummy data above).

 7: sprintf(gettext(fmt, domain = domain), ...)     
 6: gettextf(Message, ..., domain = domain)    
 5: structure(list(message = as.character(message), call = call), 
   class = class)      
 4: simpleError(gettextf(Message, ..., domain = domain), Call)
 3: stop(simpleError(gettextf(Message, ..., domain = domain), Call))
 2: cry(, "number of non-fixed predictors [%d] exceeds the allowed maximum of %d (with %d variants)", 
   nov, novMax, nVariants)
 1: pdredge(global.mod, clust)               
89_Simple
  • 3,393
  • 3
  • 39
  • 94
  • I am not familiar with `snow()`, can you create your vector of formulas as a character vector and run it using `lapply()` like this `lapply(formula_vec, function(x) lmer(formula(x), data = lmerDat, etc...)` (I know this works outside of snow). Heads up though, it will stop if you run into converge or misspecification issues with any of the models – Andrew Dec 10 '19 at 13:39
  • Please add a reproducible code or at least a `traceback()` output following the error. – Kamil Bartoń Dec 10 '19 at 14:51
  • Okay. I have added `traceback()` output after I get the error – 89_Simple Dec 11 '19 at 05:57
  • 1
    It is just a glitch with error message formatting. Anyway, the error `dredge` tries to print is due to the excessively large number of terms in your model. The upper limit is 32 (there is no simple way to work it around). – Kamil Bartoń Dec 11 '19 at 16:50
  • Okay thank you very much for the answer. – 89_Simple Dec 12 '19 at 06:38

0 Answers0