Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Reject glmmTMB models fitted with priors in likelihood-ratio tests

Open
#28 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Domain
data

Research direction

Start at the validation block in R/compare_nested_models.R (lines 94-135, linked in the issue) and determine how a stored glmmTMB fit exposes its priors, since logLik includes them. Add a check that stops when either fitted model carries priors, including identical priors on both sides. Cover it in the testthat suite with the issue's reproduction plus no-prior, NULL and empty-prior cases, and document the restriction in the roxygen help; done means the reproduction now errors while prior-free comparisons are unchanged.

Written by the indexing model from the issue text.

Description

bug priority: high

Problem

compare_nested_models() reports an ordinary likelihood-ratio test for models fitted with priors. That test requires maximum-likelihood (ML) fits without priors; glmmTMB uses maximum a posteriori (MAP) estimation when priors are supplied.

The current check accepts these fits. glmmTMB explains MAP here. Its logLik method returns a value that includes priors, so the usual chi-squared calculation is not the required ML test.

Reproduction

set.seed(123)
dat <- data.frame(x = rep(c(-1, 1), each = 50))
dat$y <- 2 * dat$x + rnorm(nrow(dat))
prior <- data.frame(prior = "normal(0,1)", class = "fixef", coef = "x")

restricted <- glmmTMB::glmmTMB(y ~ 1, data = dat)
regularised <- glmmTMB::glmmTMB(y ~ x, data = dat, priors = prior)
dyadMLM::compare_nested_models(restricted, regularised)

Suggested fix

  • Check stored fitted models for active priors. If either has priors, stop and ask the user to refit without them.
  • Test one fit with priors against one without, and two fits with identical or different priors. Identical priors do not make this test valid.
  • Keep fits without priors working, including NULL and empty prior specifications.
  • Explain the restriction in the help. Comparing models with priors is a separate task.

Reproduced on 2026-09-10 at c92eb46 with glmmTMB 1.1.14: the converged MAP fit passes validation and produces a chi-squared p-value.

Related: #33.

Dominant language
R
Stars
1
Forks
2
Avg merge
9h 28m
Merged PRs (30d)
21

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Pascal-Kueng/dyadMLM

All issues in Pascal-Kueng/dyadMLM

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.