Skip to content

Report no LOOIC weights for models fit to different numbers of observations in compare_performance() - #985

Merged
strengejacke merged 5 commits into
easystats:mainfrom
jmgirard:loo-unequal-observations
Oct 18, 2026
Merged

strengejacke merged 5 commits into
easystats:mainfrom
jmgirard:loo-unequal-observations

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

compare_performance() computes LOOIC stacking weights from the pointwise elpd_loo values of each model with cbind(). When the models were fit to different numbers of observations, cbind() recycled the shorter column, and loo::stacking_weights() returned wrong weights. For 32 rows against 150 rows base R warned "number of rows of result is not a multiple of vector length". For 32 rows against 64 rows there was no warning at all.

An example is brms_1 (32 observations) with brms_4 (150 observations) from insight::download_model(). On main the LOOIC weights are 0.000 and 1.000.

What changes

  • If the models with LOOIC have different numbers of pointwise rows, compare_performance() gives NA for all LOOIC weights and, with verbose = TRUE, warns with the counts. Models with the same number of rows keep their weights.
  • The "Model Weights" section of the help says that LOOIC weights are NA in this case.

Tests

  • brms_1 with brms_4, also with rank = TRUE, with a copy of brms_1 as a third model, and with verbose = FALSE.
  • Mocked model_performance() results with 32 and 64 rows, where cbind() recycled without a warning, and with a third model that has no LOOIC.
  • brms_1 with a copy of itself still gets the weights 0.5 and 0.5, as on main.

The new tests fail on main and pass with this change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Matching row counts do not ensure pointwise observations are aligned across models.

1 open issue
1 file not reviewed
  • man/compare_performance.Rd: Generated file
What changed in this PR

This pull request prevents invalid LOOIC stacking weights when models have different pointwise observation counts.

Changes:

  • Returns NA weights and warns when observation counts differ.
  • Preserves weights for matching counts.
  • Adds regression tests, documentation, NEWS, and a version bump.
File Summary
tests/​testthat/​test-compare_performance.R Adds regression coverage.
R/​compare_performance.R Validates pointwise row counts before stacking.
NEWS.md Documents the bug fix.
man/​compare_performance.Rd Documents LOOIC weight behavior.
DESCRIPTION Increments the package development version.

Review effort: Lite

Comment thread R/compare_performance.R Resolved
@jmgirard
jmgirard force-pushed the loo-unequal-observations branch from 3cdc56a to 0302562 Compare October 18, 2026 14:27
@strengejacke
strengejacke merged commit 520e21b into easystats:main Oct 18, 2026
9 of 20 checks passed
@jmgirard jmgirard mentioned this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants