Skip to content

Fix the link-scale footer text for transform, and the transform = exp error in estimate_contrasts() - #689

Merged
strengejacke merged 12 commits into
easystats:mainfrom
jmgirard:link-footer-transform
Oct 18, 2026
Merged

strengejacke merged 12 commits into
easystats:mainfrom
jmgirard:link-footer-transform

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

For non-linear models, the footer of link-scale output printed "FALSE-transformed link-scale" or "TRUE-transformed link-scale". .table_footer() (R/table_footer.R) pasted transform into the text. But most callers store transform as TRUE or FALSE, and the emmeans code always stores TRUE.

Example, with d <- mtcars; d$cyl <- factor(d$cyl) and g <- glm(am ~ wt + cyl, data = d, family = binomial):

Call Before Now
estimate_link(g, by = "cyl") FALSE-transformed link-scale link-scale
estimate_means(g, "cyl", predict = "link", backend = "emmeans") TRUE-transformed link-scale link-scale
estimate_means(g, "cyl", predict = "link", transform = exp) TRUE-transformed link-scale transformed link-scale
estimate_contrasts(g, "cyl", predict = "link", transform = exp) error: cannot coerce type 'builtin' to vector of type 'character' transformed link-scale
estimate_contrasts(g, "cyl", predict = "link", transform = "exp") exp-transformed link-scale exp-transformed link-scale
estimate_expectation(g, data = estimate_link(g, by = "cyl")) FALSE-transformed link-scale response-scale

What changed:

  • A new attribute transform_arg keeps the transform argument as the user passed it. get_marginalmeans(), get_marginalcontrasts() and .estimate_predicted() set it. The new helper .link_transform_label() reads it for the link-scale line. A name such as "exp" gives "exp-transformed", and a function gives "transformed". If insight::find_transformation() finds a response transformation, transform = TRUE gives "transformed". Otherwise it gives "link-scale", because nothing changes. The logical transform attribute stays as it was, because the plot code and the linear-model hint read it.
  • An earlier output passed as data brings its own predict and transform attributes into .estimate_predicted(). Before, c(grid_specs, list(predict = predict), ...) put them first, so info$predict took the old value. Now the values of the call replace them.

Tests in test-table_footer.R cover the calls above with both backends, and transform = TRUE. They also cover an earlier output as data in both directions, contrasts of estimate_link() output, and contrasts of slopes.

Not fixed here:

  • On the response scale, the footer does not say that a transform function changed the values.
  • estimate_link(g, transform = "exp") with a string stops with "could not find function trans_fun".
  • backend = "emmeans" ignores a transform function in estimate_means().
  • With an earlier output of another model as data, the footer reads the model_info of that output.

devtools::test() gives 0 failures and 0 errors locally. devtools::check() gives 0 errors and 0 warnings. The version is bumped to 0.17.0.17.

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

Add coverage for transformed-response footer labeling and correct the remaining comment typo.

1 open issue
What changed in this PR

Fixes link-scale footer labels and preserves user-supplied transformations across prediction and contrast workflows.

Changes:

  • Adds transformation-aware footer labeling.
  • Preserves transformation metadata and corrects precedence when reusing outputs.
  • Adds regression tests and bumps the package version.
File Summary
tests/​testthat/​test-table_footer.R Adds footer regression coverage.
R/​table_footer.R Generates corrected link-scale labels; transformed-response coverage is still needed.
R/​get_marginalmeans.R Stores the original transform argument; includes a comment typo.
R/​get_marginalcontrasts.R Propagates transformation metadata.
R/​estimate_predicted.R Corrects inherited metadata precedence.
NEWS.md Documents the fixes.
DESCRIPTION Bumps the development version.

Review effort: Lite

Comment thread R/get_marginalmeans.R Resolved
@strengejacke
strengejacke merged commit 1b44dd9 into easystats:main Oct 18, 2026
8 of 18 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.

3 participants