Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[paper] writing #332

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

[paper] writing #332

wants to merge 12 commits into from

Conversation

DominiqueMakowski
Copy link
Member

Let's get this bad boi out.

@mattansb @bwiernik what would you write about the two backends, emmeans and marginaleffects, their main differences etc.

Do they both rely on the delta method?

@DominiqueMakowski
Copy link
Member Author

@strengejacke I think I'll need your help for the marginal section, the different types of marginalization etc. it's quite blurry in my head to be honest ^^

@DominiqueMakowski DominiqueMakowski linked an issue Jan 13, 2025 that may be closed by this pull request
@DominiqueMakowski
Copy link
Member Author

@easystats/core-team remaining bits:

  • add details about types of marginalization
  • Drawbacks/benefits of both backends
  • Polishing

@mattansb
Copy link
Member

emmeans relies on the delta method for non-linear transformations when those are done as part of the estimation.

@DominiqueMakowski where do you want my input, and what should it include? I must admit I have 0 familiarity with modelbased - I use marginaleffects, emmeans and ggeffects directly for plotting and estimation, so I have no idea what would be relevant here.

@DominiqueMakowski
Copy link
Member Author

I must admit I have 0 familiarity

Your torment over you can make the switch now 😛

Mostly if you could take a look at the technical details section that talks about the backends

@strengejacke
Copy link
Member

strengejacke commented Jan 14, 2025

I must admit I have 0 familiarity with modelbased

modelbased currently covers classical predict() (non-focal held constant at representative values) or estimates marginal means (non-focal averaged/weighted), the latter using emmeans resp. marginaleffects via estimate_means(). estimate_means() should return identical results for both emmeans and marginaleffects backends, i.e. currently we support marginaleffects by mimicking the emmeans-approach of marginalzation.

@DominiqueMakowski DominiqueMakowski mentioned this pull request Jan 14, 2025

The modelbased package simplifies the extraction of these effects, providing a clear interface to understand how different predictors interact with outcomes in various scenarios.

[details about types of marginalization]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strengejacke I think here we could mention our 2 main types of marginalization (essentially copypasta our nice docs on that)

Copy link
Member

@strengejacke strengejacke Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can start working/helping on this paper by mid of February, or earlier if it's just minor stuff.

The term "Least-Squares Means" was somewhat misleading as it suggested a method specific to least-squares estimation, hence its renaming to `emmeans` in 2016 to clarify its scope for a wider range of models including generalized linear models, mixed models, and Bayesian models.
- `marginaleffects` (REF) was more recently introduced and also employs the delta method to approximate variance estimation. It is compatible with a wider range of models and allows for more flexibility in the specification of the marginal effects to be estimated.

[What's the difference / benefits / drawbacks of using one or ther other?]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattansb any other interesting facts to mention here?

Copy link
Member

@strengejacke strengejacke Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference for marginaleffects would be https://www.jstatsoft.org/article/view/v111i09

Arel-Bundock, V., Greifer, N., & Heiss, A. (2024). How to Interpret Statistical Models Using marginaleffects for R and Python. Journal of Statistical Software, 111(9), 1–32. https://doi.org/10.18637/jss.v111.i09

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh there's a lot that I can add.

I think the biggest difference would be:

  • emmeans used a reference grid (that has by default a "complete" combination of all predictors) to generate expected values, by default conditioning on the mean of numeric values and marginalizing over categorical/binary variables, using a linear function of the model's coefficients (and v-cov matrix to get SEs) to give "predictions at the mean" (predictions for an average observation).
  • marginaleffects uses unit level predictions to generate two counterfactual values - the difference of which is then taken (with SEs computed using the delta method), and averaged across all units. By default, the original model frame is used.

Of course, emmeans can also the delta method and can build complex reference grids (that aren't actually "grid" like), and marginaleffects can also generate linear perditions at the mean.

Using the delta method is more computationally costly than using a linear combination (though marginaleffects is very efficient). Using linear combinations with orthogonal "grids" also often means that results from emmeans directly correspond to a models coefficients (which is a benefit for those who are used to looking at regressions tables to understand their models - this can be shown with an example).

...

Would you like me to add all of this in? Just some of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like me to add all of this in? Just some of this?

Anything you think is relevant, but I think it'll be good to be quite thorough and detailed here as the inner workings of marginal stuff are not often clearly explained so having details is good!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright - I'll give it some time tomorrow.

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.

Contrasting slopes: differences between backends
3 participants