Repository navigation
Latent-scale effect sizes for ordinal models, and effect sizes on the rows of their own contrasts (emmeans backend) - #698
Open
jmgirard wants to merge 7 commits into
Conversation
…ect sizes of reordered contrasts
…atched to their contrasts
…r shifts them; correct effect-size docs
…lear errors for nominal clm models and joint tests
…t polynomial contrasts with 6 levels
…rescale, and clarify effect-size docs and NEWS
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Omnibus tests are not fully covered by the effect-size guard and require correction.
No open issues 🎉
1 file not reviewed
man/estimate_contrasts.Rd: Generated file
What changed in this PR
Adds emmeans latent-scale effect sizes for ordinal models and fixes effect-size row alignment, confidence limits, and grouping behavior.
Changes:
- Supports logit/probit effect sizes for
polrandclm. - Corrects contrast-to-effect-size ordering and CI handling.
- Adds tests, documentation, NEWS, and a version bump.
| File | Summary |
|---|---|
tests/testthat/test-ordinal.R |
Tests ordinal effect sizes and validation errors. |
tests/testthat/test-estimate_contrasts_effectsize_order.R |
Tests ordering and confidence limits. |
R/get_emcontrasts.R |
Preserves contrast-row mappings. |
R/estimate_contrasts.R |
Forwards CI and rescaling options. |
R/estimate_contrasts_effectsize.R |
Implements ordinal effect sizes and validation. |
NEWS.md |
Documents the changes. |
man/estimate_contrasts.Rd |
Updates reference documentation. |
DESCRIPTION |
Bumps the development version. |
Review effort: Lite
Contributor
Author
|
Contributor
|
This should work for marginaleffects backend too |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
backend = "emmeans",effectsize = "emmeans"now works forpolrandclmmodels withpredict = "latent"and a logit or probit link. Before, everyeffectsizeoption stopped with "We strongly recommend not using theeffectsizeargument with non-Gaussian models" for these models. The contrasts of the latent variable are divided by the SD of its error distribution. This SD ispi / sqrt(3)for the logit link (the standard logistic distribution,?stats::Logistic). It is1for the probit link (?stats::Normal). Sigma is taken as known (edf = Inf), so the effect sizes and their limits are the contrasts and their limits divided by sigma.This also fixes effect sizes that were on the wrong rows, for Gaussian models too.
Example, with
m <- MASS::polr(Sat ~ Infl + Type, weights = Freq, data = MASS::housing, Hess = TRUE),d <- iriswithd$Species <- factor(d$Species, levels = c("virginica", "setosa", "versicolor")),g <- lm(Sepal.Length ~ Species, data = d), andmt <- lm(mpg ~ cyl * am, data = mtcars)withcylandamas factors. All calls usebackend = "emmeans"andeffectsize = "emmeans":estimate_contrasts(m, "Infl", predict = "latent")partial_d0.682 forHigh - Low(1.237 / 1.814, equal tocoef(m)["InflHigh"] / (pi / sqrt(3)))method = "probit"inpolr()partial_dequal toDifferenceestimate_contrasts(m, "Infl")(defaultpredict)predict = "latent"estimate_contrasts(g, "Species")partial_d-1.267 on theversicolor - setosarowsigma(g))estimate_contrasts(mt, "cyl", by = "am")partial_dheld theamcodes (0, 1)cyl6 - cyl4atam0 (-3.775 /sigma(mt))estimate_contrasts(m, "Infl", by = "Type", comparison = "joint", predict = "latent")@What changed:
.estimate_contrasts_effectsize()skips the Gaussian check forpolrandclmwitheffectsize = "emmeans". It requirespredict = "latent"and a logit or probit link, and passes the matching sigma andedf = Inftoemmeans::eff_size().clmmodels with ascaleformula (the latent SD differs between observations) or anominalformula (the thresholds differ between groups) give an error. Arescaleargument for emmeans multiplies sigma byabs(rescale[2]), so the size of the effect sizes does not change..format_emmeans_contrasts()sorts the contrasts withmerge(), so it now keeps the row of each contrast in the emmeans grid. The effect sizes are reordered by it. This fixes factor levels that are not in alphabetical order, andcomparison = "poly"with 4 or more levels.eff_size()columns are selected by name, because abyvariable adds a column.ci. Before, they were always 95% limits. They are not adjusted for multiple comparisons, as before.effectsizegive a clear error. Before, the emmeans effect sizes gave an internal error andeffectsize = "marginal"returnedNA.effectsize = "marginal"and"boot"still give the non-Gaussian error for ordinal models.effectsizedocs and Details, NEWS entries, and the version bump.Tests in
test-ordinal.Rcheck the logit and probit effect sizes againstcoef(m)divided by the latent SD, andclmagainstpolr. They also coverby,ci,p_adjust,rescale, and every error. A new file,test-estimate_contrasts_effectsize_order.R, checks the row order for Gaussian models (reordered levels,by,polywithchickwts, andci). It has noskip_on_os(), so it also runs on macOS.About the design: in #227, the discussion agreed on no standardized effect sizes by default and noted that the choice of sigma is not settled. In #501, effect sizes were kept to families with a variance parameter. The default here stays
NULL. The link fixes the latent SD of a logit or probit ordinal model. So this SD plays the role of the residual SD in the Gaussian case, with the same caveat about covariates. To keep effect sizes Gaussian-only, the ordinal part can be dropped from this PR.Not fixed here, the same as on main:
emmeans::eff_size()with "non-conformable arguments", and so do models with non-estimable cells.effectsize = "boot"withbackend = "emmeans"can put effect sizes on the wrong rows, as above, and"boot"and"marginal"ignoreci.effectsize = "none"still gives the non-Gaussian error for non-Gaussian models.