parameters icon indicating copy to clipboard operation
parameters copied to clipboard

Bootstrap_model cluster argument missing from parameters 0.18.2 code?

Open plants-22 opened this issue 3 years ago • 0 comments

Hi, just following up about the bootstrap_model function. I know the function was meant to be updated to include the cluster argument, as it is in the source code published on GitHub (https://github.com/easystats/parameters/blob/main/R/bootstrap_model.R)

bootstrap_model.merMod <- function(model,
                                   iterations = 1000,
                                   type = "parametric",
                                   parallel = c("no", "multicore", "snow"),
                                   n_cpus = 1,
                                   cluster = NULL,
                                   verbose = FALSE,
                                   ...) {

...

if (verbose) {
    results <- lme4::bootMer(
      model,
      boot_function,
      nsim = iterations,
      type = type,
      parallel = parallel,
      ncpus = n_cpus,
      cl = cluster
    )
  } else {
    results <- suppressMessages(lme4::bootMer(
      model,
      boot_function,
      nsim = iterations,
      verbose = FALSE,
      type = type,
      parallel = parallel,
      ncpus = n_cpus,
      cl = cluster
    ))
  }

I can't seem to get the cluster argument to work when using parallel = "snow". Was the updated source code carried over to the bootstrap_model() function in parameters 0.18.2?

Here is an example of the function I called and the error message:

nBoot <- 1000
nCores <- 6

cl <- makeCluster(nCores)
  clusterEvalQ(cl, library("glmmTMB"))
  gf_filtered <- all_model_objects[[h]][["data"]] # Tell bootstrap where to find its data set
  clusterExport(cl, varlist = "gf_filtered")

boot_out <- bootstrap_model(model = all_model_objects[[h]][[jobs$model[r]]],
                                         iterations = nBoot, parallel = "snow", n_cpus = nCores, cluster = cl))

stopCluster(cl)

Error in initialize(...) : attempt to use zero-length variable name In addition: Warning message: In lme4::bootMer(model, boot_function, nsim = iterations, verbose = FALSE, : some bootstrap runs failed (1000/1000)

I know the bootstrap_model() or bootstrap_parameters() functions work for parallel operation because I have been using them, from the source code (parameters 0.18.1), successfully on my PC in parallel on 6 CPUs, using parallel = "snow" with the cluster argument modified.

Kind regards,

Neil

plants-22 avatar Sep 05 '22 04:09 plants-22