Skip to content

Save the effects argument so group-level estimates print as random effects - #1245

Merged
strengejacke merged 2 commits into
easystats:mainfrom
haomeng797-ship-it:fix-grouplevel-header
Aug 5, 2026
Merged

Save the effects argument so group-level estimates print as random effects#1245
strengejacke merged 2 commits into
easystats:mainfrom
haomeng797-ship-it:fix-grouplevel-header

Conversation

@haomeng797-ship-it

Copy link
Copy Markdown
Member

Fixes #1098.

With effects = "grouplevel" the Effects column carries a single unique value, so it is dropped before formatting, and both header paths then fall through to fixed effects. The clearest case is a zero-inflated brms model, where the group-level estimates printed as # Fixed Effects (persons) and # Zero-Inflation Parameters (persons); with this PR they print as # Random Effects: conditional (persons) and # Random Effects: Zero-Inflation (persons), matching what the equivalent glmmTMB model already did.

As suggested in the issue, .add_model_parameters_attributes() now stores the effects argument as an attribute. Two details:

  • Several methods (glmmTMB, coxme, and the merMod path) resolve the "grouplevel" alias into effects = "random" plus group_level = TRUE before the attributes are added, so the attribute is normalized back to "grouplevel" from that pair, and it always records what the user asked for.
  • The mixed-capable call sites (default method, brms, glmmTMB, coxme, rstanarm, stanfit) now forward effects; for other methods the attribute is NULL and nothing changes.

.format_columns_multiple_components() and .print_caption() consult the attribute as a fallback when the Effects column is gone, so lmer keeps its # Random Effects caption and the multi-component tables get the random. prefix they were missing.

Tests: a new test-print-grouplevel.R covers the lmer caption and the brms case (header lines only, no value snapshots, since brms_zi_3 snapshots were already flagged as unstable in test-printing-stan.R). Existing printing and stan-printing suites pass unchanged, so no snapshots move.

…fects

The header decision keyed on the Effects column, which is removed
whenever it carries a single unique value, exactly the situation
effects = 'grouplevel' produces. The argument is now stored as an
attribute (normalized back from the random + group_level rewrite some
methods apply) and both header paths consult it as a fallback.

Fixes easystats#1098
@haomeng797-ship-it

Copy link
Copy Markdown
Member Author

CI note: the R-CMD-check, pkgdown and coverage failures reproduce on current main (a range validation error coming from a dependency, plus a lavaan warning), and the styling/spelling flags predate this diff; the spelling hit is the word "errored" in the 0.29.2 section of the changelog. The jobs that gate on the changed code itself (lint, check-all-examples) pass.

@strengejacke

Copy link
Copy Markdown
Member

Thanks for this PR! Yes, please ignore the CI checks. The one that breaks packagedown website building is already fixed in the performance package, and the other test with lavaan only works interactively - I'll skip that one.

Let me review this PR after I triggered the Co-pilot AI review.

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.

Pull request overview

This PR fixes printing/captioning for model_parameters(..., effects = "grouplevel") by persisting the user-requested effects value as an attribute on the returned parameters object, allowing downstream formatting/printing to correctly recognize group-level estimates as random effects even when the Effects column was dropped for being single-valued.

Changes:

  • Store the requested effects argument as an attribute via .add_model_parameters_attributes() (including normalization back to "grouplevel" for call paths that internally rewrite it to effects = "random" + group_level = TRUE).
  • Update formatting and caption logic to fall back to the saved effects attribute when the Effects column is absent.
  • Add new test coverage for lme4 and brms group-level printing headers, and document the fix in NEWS.md.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/testthat/test-print-grouplevel.R Adds regression tests ensuring group-level estimates print with “Random Effects” headers even without an Effects column.
R/utils_model_parameters.R Saves the requested effects as an attribute (with normalization to preserve the user-facing "grouplevel" intent).
R/utils_format.R Uses the saved effects attribute to correctly apply random. prefixes when the Effects column is missing.
R/print.parameters_model.R Uses the saved effects attribute to choose “Random” vs “Fixed” captions when Effects is absent.
R/methods_rstanarm.R Forwards effects into .add_model_parameters_attributes() so printing/formatting can rely on the attribute.
R/methods_rstan.R Forwards effects into .add_model_parameters_attributes() for stanfit outputs.
R/methods_glmmTMB.R Forwards effects into .add_model_parameters_attributes() (enabling normalization back to "grouplevel" for that path).
R/methods_coxme.R Forwards effects into .add_model_parameters_attributes() (enabling normalization back to "grouplevel" for that path).
R/methods_brms.R Forwards effects into .add_model_parameters_attributes() for brms outputs.
R/1_model_parameters.R Forwards effects from .model_parameters_generic() into .add_model_parameters_attributes().
NEWS.md Documents the bug fix for effects = "grouplevel" printing headers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@strengejacke

Copy link
Copy Markdown
Member

Thanks a lot, looks good to me!
Can you please increase the version number in the DESCRIPTION file (increase fourth digit by 1). You also may add yourself as contributor, if you like (unless you would like to stay incognito).

@haomeng797-ship-it

Copy link
Copy Markdown
Member Author

Done, version bumped to 0.29.2.4. And thanks for the offer! I am already in the DESCRIPTION from #1244, so nothing to add there.

@strengejacke
strengejacke merged commit 71754b2 into easystats:main Aug 5, 2026
4 of 19 checks passed
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.

Fix printing for effects = "grouplevel"

3 participants