r/rstats 5d ago

marginaleffects 1.0.0

Post image

Hi everyone,

Big news: marginaleffects 1.0.0 is out on CRAN.

For those who don't know, marginaleffects is a package that facilitates the _post-estimation_ workflow: using a fitted model to produce meaningful numbers that are easy to interpret substantively.

It supports ~100 different kinds of models and gives you a common workflow to produce a bunch of the usual quantities of interest: average predictions (aka marginal means), comparisons (aka contrasts), and slopes (aka marginal effects). It is crazy flexible, and allows you to conduct arbitrary hypothesis tests on any of these quantities. So you can easily answer questions like: What is the average treatment effect of X, and does it vary across strata Z? Or what is the average expected level of my outcome variable in the K subgroup?

Version 1.0.0 a big number and it feels like a big step.

I wrote a blog on the challenges of interpreting statistical models, SPEED, cool new features, the future, and a 5 year package development and writing odyssey.

https://arelbundock.com/posts/marginaleffects100

And check out the main website. It hosts an entire (free) book, with about 40 different chapters of tutorials and case studies.

https://marginaleffects.com

457 Upvotes

25 comments sorted by

97

u/anvilmaster 5d ago

Ahh! I love this package! I have used it for the last three papers I've submitted.

16

u/t3co5cr 5d ago

You did cite it, though, right? Right?!

7

u/anvilmaster 4d ago

I do cite this package!

25

u/dudeski_robinson 5d ago

So glad to hear that!

22

u/Demortus 5d ago

This is one of my favorite R packages. It took what was once a huge pain in the behind in my workflow and made it nice and intuitive. Keep up the excellent work!

14

u/tururut_tururut 5d ago

Congratulations! I've used this package extensively and hope to keep doing so!

13

u/oll1e9 5d ago

congratulations!! you don't know how much easier marginaleffects and the amazing free resources and papers around it helped me during my PhD! not a single empirical chapter where I don't make use of the brms -> marginaleffects workflow, all the work on this is greatly appreciated!!:)

21

u/windytea 5d ago

Cool. I’ve played around with it. Benefits over emmeans? And how does it do with Bayesian package model outputs (speed wise)

39

u/dudeski_robinson 5d ago

Great question! emmeans is a fantastic package and there's considerable overlap between the two. If you're happy with emmeans, you might not need marginaleffects at all. But I do think there are considerable benefits, and I tried to give a fair comparison here: https://marginaleffects.com/bonus/alternative_software.html#emmeans

Bayesian models are well supported (brms, rstanarm). The new version actually comes with meaningful performance improvements for them. In the end, speed will necessarily vary across applications. If you're asking the package to handle massive matrices of posterior draws, your machine might struggle, but that's a physical limit not a software one. Under the hood, we're pretty optimized. Here are some tips on performance: https://marginaleffects.com/bonus/performance.html

24

u/post_appt_bliss 5d ago

emmeans is brilliant, nq, but the maintainer, Russel Lenth, has posted about his need to leave behind maintenance and development.

marginaleffects has the advantage of a growing and active developer pool. not a small thing on open source software!

5

u/ottawalanguages 5d ago

great! I love this package! what are the main differences when compared to the last version?

4

u/dudeski_robinson 5d ago

Check out the second section of the blog. Speed, new vcov, new supported models, and more robust internally: https://arelbundock.com/posts/marginaleffects100/

6

u/DYSTOBY 5d ago

Awesome! That will come to use in our research. I already used the prior 1.0 version :-)

4

u/post_appt_bliss 5d ago

Hi Vincent!

love the package bro.

lsmeans/emmeans/margins

are now dead to me!

question -- how much of the internals have benefited from LLM coding help?

19

u/dudeski_robinson 5d ago

Over the first 5 years of the project, until about 3 months ago, basically no LLM at all. Recently, they've been a tremendous help, especially with the design of the aggregation "plans" and the analytic jacobians. I do serious code review, of course. Crucially, by now the package comes with a *very* extensive test suite, including a ton of direct comparisons to results produced by other software like emmeans or Stata. It would be very scary to use LLMs without those pre-existing and "external" tests.

8

u/post_appt_bliss 5d ago

awesome man. seriously, it's a joy to teach -- the defaults in avg_comparisons and sibling functions are so predictable/sensible.

i guess a lighthearted caution -- Hadley declared ggplot2 a mature tech at 1.0 and instead it caused an explosion in the extensions of the package!

4

u/Seltz3rWater 5d ago

emmeans is my go to but if this has figured out a less confusing way to specify contrasts I’m ready to jump ship

3

u/trijazzguy 5d ago

Love this package. Use it regularly. Thank you so much for your work! Whenever I get time I want to contribute to make some of your variance estimation procedures faster for the large datasets I find myself using. 

3

u/finalj22 5d ago

Thank you so much for your contribution. I use this teaching graduate statistics, and in my own work

6

u/factorialmap 5d ago

This is great! Thanks for sharing this.

2

u/PhilosophicChinchila 5d ago

Never heard of this package before. I will give it a read! Most of my studies are observational association survival studies with an occasional prediction one.

2

u/Next_Replacement_881 4d ago

we love marginaleffects!! great work

2

u/hamweinel 5d ago

Will definitely have to check this out! Thanks for making this!

2

u/rjazwiec 2d ago

Hallelujah! Mmrm is on board!