From 742e70ca41fdf681b6d23106bc5db3a0454c1d94 Mon Sep 17 00:00:00 2001 From: sisyphus-jasp Date: Tue, 17 Feb 2026 13:50:27 +0100 Subject: [PATCH] [jaspMixedModels] Fix parametric bootstrap error in Generalized Linear Mixed Models. ... --- R/MixedModelsCommon.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/R/MixedModelsCommon.R b/R/MixedModelsCommon.R index 499952d3..07a3974b 100644 --- a/R/MixedModelsCommon.R +++ b/R/MixedModelsCommon.R @@ -19,6 +19,30 @@ # TODO: Expose priors specification to users in Bxxx? # TODO: Add 3rd level random effects grouping factors ;) (not that difficult actually) +# Workaround for afex::mixed with parametric bootstrap calling glmer with REML argument +# glmer() does not accept REML (GLMMs are always fit with ML), but afex passes REML = FALSE +# Patch lme4::glmer to accept but ignore REML argument +# This runs via .onLoad to ensure namespace is properly unlocked +.glmerPatchEnv <- new.env() +assign(".glmer_patched", FALSE, envir = .glmerPatchEnv) + +.onLoad <- function(libname, pkgname) { + # Only patch once + if (!get(".glmer_patched", envir = .glmerPatchEnv)) { + ns <- asNamespace("lme4") + if (unlockBinding("glmer", ns)) { + .glmer_orig <<- get("glmer", envir = ns, inherits = FALSE) + ns$glmer <- function(...) { + args <- list(...) + args$REML <- NULL + do.call(.glmer_orig, args) + } + lockBinding("glmer", ns) + assign(".glmer_patched", TRUE, envir = .glmerPatchEnv) + } + } +} + .mmRunAnalysis <- function(jaspResults, dataset, options, type) { .setOptions()