Skip to content

Use link derivative for back-transformed SE and order CI bounds - #725

Merged
strengejacke merged 2 commits into
easystats:mainfrom
chenyangsu:fix/backtransform-se-and-ci
Nov 27, 2026
Merged

strengejacke merged 2 commits into
easystats:mainfrom
chenyangsu:fix/backtransform-se-and-ci

Conversation

@chenyangsu

Copy link
Copy Markdown
Contributor

In .backtransform_predictions(), exp(means$estimate) * means$std.error applies the log-link derivative to all link functions. With predict = "inverse_link", estimate_means(glm(am ~ factor(cyl) + wt, mtcars, binomial), by = "cyl") returns SE = 3.17 for cyl = 8 instead of 0.25 from emmeans(..., type = "response") (abs(mu.eta(eta)) * SE). On Gamma("inverse"), SE is 0.0018 instead of 1.24 and the 95% CI is inverted ([29.47, 24.34]).

.link_inverse() now attaches mu.eta (including the bias-adjusted derivative), .backtransform_predictions() multiplies SE by abs(mu.eta(estimate)) with a finite-difference fallback, and inverted CI bounds are swapped. Happy to pass mu_eta in predict_args instead of an attribute if you prefer.

Testing: test-backtransform_se.R (15 passed, 8 failed before), test-bias_correction.R (4 passed), test-estimate_means.R (167 passed), test-offset.R (34 passed).

@strengejacke

Copy link
Copy Markdown
Member

Attaching as attributes is finde. LGTM, thanks!

@strengejacke

Copy link
Copy Markdown
Member

Thanks. Two things:

  • could you increase the dev-version number, so that easystats::install_latest() will recognize a new update? Whenever we have "user-visible" changes or changes that affect behaviour, we increase that number in the DESCRIPTION file, in this case 0.19.0.2 to 0.19.0.3.
  • could you add a NEWS item?

@strengejacke
strengejacke merged commit fdc7de1 into easystats:main Nov 27, 2026
1 check failed
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.

2 participants