Estimation of Model-Based Predictions, Contrasts and Means
Overview
Implements a general interface for model-based estimations for a wide variety of models, used in the computation of marginal means, contrast analysis and predictions. For a list of supported models, see 'insight::supported_models()'.
Breaking Changes
- For ordinal models (for example from
MASS::polr(),ordinal::clm()orordinal::clmm()),estimate_contrasts()andestimate_slopes()withbackend = "emmeans"now return probabilities by default and forpredict = "response", asestimate_means()already does. Contrasts compare the focal levels within each response category, and slopes are the slopes of the probability of each response category. Before, both returned values on the latent scale, and the table footer ofestimate_contrasts()said they were on the response scale. The ordinal modes of *emmeans* ("prob","cum.prob","exc.prob","linear.predictor","latent"and"mean.class") can be passed topredict. Usepredict = "latent"to get the former results.
Show all changes in 0.18.0Hide the rest of the changes in 0.18.0
Changes
- Post-processing in
estimate_contrasts()including group-variable (e.g.,post_process = ~ pairwise | group_var) now no longer prints levels fromgroup_varin both the group and comparison columns (i.e. redundant labels have been removed from the output). estimate_contrasts()with custom comparisons (e.g., whencomparison = "(b1 - b12) = (b4 - b18)") can yield incorrect results whenestimate = "average"and predictions are filtered (e.g. whencontrast = c("x=c(2,4)")). This does not happen in general, but may happen. Therefore, now an informative warning is printed in such edge-cases.- Added a new vignette, "The Modelisation Approach", which demonstrates a complete analytical workflow from setting up models using DAGs to extracting meaningful predictions, slopes, and interaction contrasts using modelbased post-estimation functions.
estimate_means()withbackend = "emmeans"now supports ordinal models, e.g. fromMASS::polr()orordinal::clm().predictaccepts the ordinal modes of *emmeans* ("prob","cum.prob","exc.prob","linear.predictor","latent"and"mean.class"). For"prob", the output has one row per response category, in aResponsecolumn. For"cum.prob","exc.prob"and"linear.predictor", the output has one row per threshold, in aThresholdcolumn. For ordinal models, the default is nowpredict = "prob", which returns the same probabilities as the"marginaleffects"backend.- For ordinal models,
plot()ofestimate_means()output withbackend = "emmeans"now maps theResponseorThresholdcolumn to the color with onebyvariable and to the facets with more. The"marginaleffects"backend already does this forResponse. - With
backend = "emmeans",plot()now shows predicted probabilities on a percent y-axis,"cum.prob"and"exc.prob"included. This applies to binomial, beta, ordinal, and multinomial models. comparison = "ratio"is a new shortcut to compute pairwise comparisons as ratios.- The printed footer of
estimate_prediction()and similar functions now names prediction intervals as such (#485).
Bug fixes
estimate_means(),estimate_contrasts()andestimate_slopes()now filter the response categories of ordinal models, for example fromMASS::polr(),ordinal::clm()orordinal::clmm(). The filter is abyterm that names the response with values, for exampleby = c("Infl", "Sat = 'Low'"). The output then has only the rows of these response categories. The filter works withbackend = "emmeans"andpredict = "prob"(the default). Before, means and contrasts of factors ignored the filter, and slopes and contrasts of slopes stopped with an unclear error. Ifpredicthas another value, these functions now stop with a clear error. If a value is not a response category, they also stop with an error.- For non-linear models, the footer of predictions or contrasts on the link-scale no longer says "FALSE-transformed" or "TRUE-transformed". This footer appears, for example, with
estimate_link(), or withestimate_means()andpredict = "link". Withouttransform, the footer now says "link-scale". Except withbackend = "emmeans", a function astransformgives "transformed link-scale".estimate_contrasts()withpredict = "link"and a function astransform(for exampletransform = exp) no longer fails with an error. If the output of an earlier call is thedataargument, the footer ofestimate_expectation(),estimate_prediction()andestimate_link()now names the right scale. - With
backend = "marginaleffects",estimate_means(),estimate_slopes()andestimate_contrasts()no longer drop or rename abyvariable with a name such astype,norvalue. They also no longer mislabel other columns because of such a name. Before, for example,estimate_means()dropped abyvariable namedtypeand renamednton_Obs. It also labeled a variable namedMedianasMean, and the means asCoefficient. This fix does not yet apply to Bayesian models or to inequality comparisons (for examplecomparison = "inequality"). - Fixed printing error for brms-Wiener models without
componentcolumn. - With
backend = "marginaleffects", abyvariable with the name of the estimate column (for exampleMean) or of thetcolumn is now returned as<name>.1. The output column keeps its name. This also holds forpwithestimate_slopes()andestimate_contrasts(), and forSE,CI_lowandCI_highwithestimate_slopes(). Before, for example,estimate_means()kept abyvariable namedMeanand renamed the means toMean.1, andestimate_contrasts()renamed the p-values top.1. As for the fix above, this does not yet apply to Bayesian models or to inequality comparisons. It also does not apply toestimate_contrasts()on the output ofestimate_relation(). - With
backend = "marginaleffects",estimate_means(),estimate_contrasts()andestimate_slopes()now stop with an informative error when a variable has a name that *marginaleffects* uses for its own columns, and ask users to rename the variable. Before, these names gave wrong estimates, standard errors or confidence intervals, missing columns, or unclear errors. The names are: byvariables ofestimate_means(), and ofestimate_contrasts()when the contrast variable is a factor:Predicted,SE,CI_low,CI_high,df,rowidands.value.- a factor
contrastvariable ofestimate_contrasts():SE,CI_low,CI_high,dfandrowid. - other predictors of
estimate_means()andestimate_contrasts():SE,CI_low,CI_highanddf. byvariables ofestimate_slopes():df,rowid,s.value,predicted,predicted_hiandpredicted_lo.
Bayesian models are not checked yet. For them, these names can still give
missing columns or unclear errors.
- With
backend = "marginaleffects",estimate_contrasts()now returns abyvariable namedLevel1orLevel2asLevel1.1orLevel2.1, next to theLevel1andLevel2columns of the contrasts. It also returns the contrasts for abyvariable namedhypothesisand for acontrastvariable namedParameter. Before, the output had two columns with the same name, the contrast labels were not split intoLevel1andLevel2, or the call failed with an unclear error. If<name>.1is already a variable name, the suffix is the next free number, for examplep.2. As for the fixes above, theLevel1,Level2andhypothesisfixes do not yet apply to Bayesian models or to inequality comparisons. - If a variable has the name of an output column,
estimate_contrasts()andestimate_slopes()withbackend = "marginaleffects"now keep the values and the order of that column. This applies to thecontrastvariable, and tobyvariables of contrasts and of contrasts of slopes. It also applies tobyvariables of contrasts with a customcomparison, for examplecomparison = "b2=b1". Before, acontrastvariable namedtturned thetcolumn into a factor. Acontrastvariable namedpreplaced the p-values with missing values and moved thepcolumn to the front. In contrasts, abyvariable namedSlopegave twoDifferencecolumns. In contrasts of slopes, it replaced the differences with missing values. Withcomparison = "ratio", abyvariable namedRatioorSlopegave twoRatiocolumns. Now abyvariable namedRatiobecomesRatio.1there. estimate_slopes()withbackend = "marginaleffects"now adjusts the p-values forp_adjust = "holm","hochberg","hommel","bonferroni","BH","BY","fdr","sidak"and"tukey". Before, all but"tukey"failed with the error "replacement has 0 rows", and"tukey"returned the unadjusted p-values. For"tukey",estimate_slopes()andget_marginaltrends()now use the Sidak adjustment and say so in a message. The Tukey adjustment is only appropriate for pairwise comparisons, but these slopes are each tested against 0.emmeans::test()makes the same substitution. Slopes that are compared, for example with thecomparisonorpost_processargument, keep the Tukey adjustment.estimate_means()withbackend = "emmeans"now shows the response level names for models fromordinal::clmm(). Before, theResponsecolumn showed1,2,3, and theThresholdcolumn showed1|2,2|3.- Fixed issue in
estimate_contrasts()with wrong assignment of estimates in custom comparisons (e.g., whencomparison = "(b1 - b12) = (b4 - b18)"), when some of the indexed coefficients contained the same digit (in this case,1inb1andb12). - Fixed issues in offset handling when the offset was specified via the
offsetargument in the model call instead of inside the formula. - Fixed issues with using offsets and predicting grand mean (i.e. when model contains offset and
by = NULL). plot()now gives an informative error when there is nothing to put on the x-axis, e.g. for predictions from intercept-only models, or forestimate_prediction()without thebyargument.- Fixed an "invalid regular expression" error in
estimate_contrasts()for multivariate models (for example from *brms*) with many observations.estimate_contrasts()now uses the names of the response variables, not their observed values, to find the response in the contrast labels. estimate_contrasts()now returns separateResponse1andResponse2columns for multivariate *brms* models with dots in the response names, for examplemvbind(Sepal.Length, Petal.Length) ~ Species. Before, the response names stayed in theLevel1andLevel2columns, because *brms* removes the dots from the response names.- The
gridargument ofvisualisation_recipe()andplot()now changes the facet grid of plots with four or morebyvariables. Before, these functions applied thefacetargument to the facet grid instead. Iffacetwas not set,gridgave an error.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-07-23
- ERROR12 OK, 1 ERROR2026-07-21
- OK14 OK2026-03-10
Documentation
- Help pages
- 25 (3 internal)includes a package overview page
- Examples that run
- 94%15 run in a plain check (13 of them under a condition) · 1 never run
- Exported functions with examples
- 93%
- Documented parameters
- 99%
- Return-value docs
- 79%
- Help pages citing references
- 28%
Downloads
Repository
- PRs merged (all time)
- 95%
- Median days to close, 50 most recently updated closed issues
- 3
- Median days to close, 50 most recently updated closed PRs
- 0
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
Commits over time
Commit identities over time
15 development-tooling and community-health practices detected across 6 families in the upstream repository
Checks run against github.com/easystats/modelbased on 2026-10-18.
Funding links: GitHub Sponsors
The repository owner accepts GitHub Sponsors
GitHub Pages site last deployed 2026-10-18
pkgdown site last built 2026-10-18
Show all practicesHide 2 practices
This repository shows signs of AI coding tools.
- GitHub Copilotfirst seen 2025-10-05Pull request: opened by its own accountCommits: 4 by its own account · at least 4 crediting it in the message
- Gemini CLIfirst seen 2026-02-05Seen in the repository: GEMINI.mdNamed in .Rbuildignore: GEMINI.md
Dependencies
Installing modelbased adds 4 packages (0 with compiled code, 2.9 MB of source tarballs). Heaviest: insight 1.2 MB, parameters 701 KB, bayestestR 576 KB.
Show all 13 packagesHide all 13 packages
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 0.18.0Latest2026-10-18 · current release · diff ↗ ·
listed once in CRAN's queue
Seen in one reading of CRAN's incoming queue, at 2026-10-18 16:17 UTC, so it stayed less than the time between readings. - 0.17.02026-08-28 · diff ↗
- 0.16.02026-06-30 · diff ↗
- 0.15.02026-05-10 · diff ↗
- RR 4.6.0 released · 2026-04-24
- 0.14.0
- 0.13.12025-12-08 · diff ↗
- 0.13.0
- 0.12.0
- 0.11.22025-05-31 · diff ↗
- 0.11.0
- RR 4.5.0 released · 2025-04-11
- 0.10.02025-03-10 · diff ↗ ·
removed 1 export
visualisation_matrixadded 2 exports
pool_contrasts, pool_predictions - 0.9.02025-02-05 · diff ↗ ·
removed 5 exports
estimate_response, get_marginaleffects, model_emcontrasts, model_emmeans, model_emtrendsadded 4 exports
get_marginalcontrasts, get_marginalmeans, get_marginaltrends, print_html - 0.8.92024-10-26 · diff ↗
- 0.8.82024-06-11 · diff ↗
Show 24 earlier eventsHide 24 earlier events
- RR 4.4.0 released · 2024-04-24
- 0.8.72024-02-15 · diff ↗
- RR 4.3.0 released · 2023-04-21
- 0.8.62023-01-13 · diff ↗
- 0.8.5
- unarchivedReturned to CRAN2022-05-30
- archivedRemoved from CRAN2022-05-30check problems were not corrected in time
- 0.8.12022-05-30 · diff ↗
- RR 4.2.0 released · 2022-04-22
- 0.8.02022-03-31 · diff ↗ ·
removed 2 exports
data_matrix, model_marginaleffectsadded 4 exports
get_emcontrasts, get_emmeans, get_emtrends, get_marginaleffects - 0.7.2
- 0.7.1
- 0.7.02021-06-06 · diff ↗ ·
removed 2 exports
as.numeric_ifnumeric, data_restoretypeadded 6 exports
describe_nonlinear, estimate_expectation, estimate_grouplevel, model_emmeans, reshape_grouplevel, visualisation_recipe - RR 4.1.0 released · 2021-05-18
- 0.6.02021-04-12 · diff ↗ ·
removed 1 export
reshape_drawsadded 3 exports
data_restoretype, estimate_prediction, estimate_relation - 0.5.12021-01-27 · diff ↗
- 0.5.02021-01-15 · diff ↗
- 0.4.02020-12-06 · diff ↗
- 0.3.02020-09-27 · diff ↗
- RR 4.0.0 released · 2020-04-24
- 0.1.22020-03-12 · diff ↗
- 0.1.12020-01-27 · diff ↗
- 0.1.02020-01-12
- RR 3.6.0 released · 2019-04-26
Package metadata
- First published
- 2020-01-12
- Total releases
- 30 / 6 yrs
- License
- GPL-3 OSI
- Minimum R
- ≥ 4.0
- Bundled data
- 33 KB / 5 files
- Download size
- 624 KB
Cite
Cite this package
Run in R for the authors' entry:
citation("modelbased")The package provides a citation file, so citation() returns the authors' own entry.
It points to 10.21105/joss.07969.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-22, which the citation names so these numbers can be found later. More on citing and the projects behind them.