Skip to content

Conversation

learbuehrer
Copy link
Collaborator

Closing #224

Copy link

codecov bot commented Sep 4, 2025

Codecov Report

❌ Patch coverage is 41.83673% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.71%. Comparing base (d7b018c) to head (d27227e).
⚠️ Report is 47 commits behind head on main.

Files with missing lines Patch % Lines
R/fitabn_mle.R 33.33% 56 Missing ⚠️
R/build_score_cache_mle.R 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
+ Coverage   66.30%   66.71%   +0.41%     
==========================================
  Files          53       49       -4     
  Lines       10399    10378      -21     
==========================================
+ Hits         6895     6924      +29     
+ Misses       3504     3454      -50     
Files with missing lines Coverage Δ
R/build_score_cache.R 74.53% <100.00%> (+0.11%) ⬆️
R/fitabn.R 85.64% <100.00%> (+0.07%) ⬆️
R/build_score_cache_mle.R 59.02% <91.66%> (+2.75%) ⬆️
R/fitabn_mle.R 56.47% <33.33%> (+0.27%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@matteodelucchi matteodelucchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

@matteodelucchi
Copy link
Contributor

What's still missing is to have the same behaviour in fitAbn. This is necessary to have functional equivalence in the two steps.

  • extend fit.control(method = "mle") with the corresponding argument.
  • implement the conditional logic in fitAbn.mle()'s regression loop:

    abn/R/fitabn_mle.R

    Lines 384 to 432 in a906b2d

    poisson = {
    if (verbose) {message(paste("using glmer with model:", deparse1(model)))} else NA
    tryCatch({
    fit <- lme4::glmer(model, data = data.df.grouping, family = "poisson")
    }, error=function(e)NULL)
    if (is.null(fit)){
    # relax tolerances for change in parameter values and objective function.
    tryCatch({fit <- lme4::glmer(model, data = data.df.grouping, family = "poisson",
    control = lme4::glmerControl(tolPwrss = control[["tolPwrss"]],
    check.rankX = control[["check.rankX"]],
    check.scaleX = control[["check.scaleX"]],
    check.conv.grad = lme4::.makeCC(action = control[["check.conv.grad"]]),
    check.conv.singular = lme4::.makeCC(action = control[["check.conv.singular"]]),
    check.conv.hess = lme4::.makeCC(action = control[["check.conv.hess"]]),
    optCtrl = list(xtol_abs = control[["xtol_abs"]],
    ftol = control[["ftol_abs"]])))
    }, error=function(e)NULL)
    }
    if (is.null(fit)) {
    # if fit is still NULL, try other (all available) optimizer:
    # fit same as above (not very elegant)
    fit <- lme4::glmer(model, data = data.df.grouping, family = "poisson",
    control = lme4::glmerControl(tolPwrss = control[["tolPwrss"]],
    check.rankX = control[["check.rankX"]],
    check.scaleX = control[["check.scaleX"]],
    check.conv.grad = lme4::.makeCC(action = control[["check.conv.grad"]]),
    check.conv.singular = lme4::.makeCC(action = control[["check.conv.singular"]]),
    check.conv.hess = lme4::.makeCC(action = control[["check.conv.hess"]]),
    optCtrl = list(xtol_abs = control[["xtol_abs"]],
    ftol = control[["ftol_abs"]])))
    # refit with all available optimizers
    fit_all <- lme4::allFit(fit)
    # keep only results from optimizers that were reported as OK
    fit_all_OK <- fit_all[sapply(fit_all, methods::is, "merMod")]
    # extract messages from each optimizer
    convergence_results <- lapply(fit_all_OK, function(x) x@optinfo$conv$lme4$messages)
    # Get only results from optimizer without any message (meaning they did converge etc.)
    converged_idx <- sapply(convergence_results, is.null)
    # Keep only results from first optimizer (arbitrarily) that did converge without any message
    if(sum(converged_idx) == 0){
    if(verbose){message("No algorithms from allFit converged. You may still be able to use the results, but proceed with extreme caution.")}
    fit <- NULL
    } else {
    fit <- fit_all[converged_idx][[1]]
    }
    }
    },

@learbuehrer learbuehrer merged commit 4c1ac6b into main Sep 9, 2025
48 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Addition of glmmTMB to improve convergency for Poisson in mixed-effect models

2 participants