marginaleffects 1.0.0
Big news! marginaleffects 1.0.0 for R is out. It’s a big number and it feels like an important moment, so I wrote a blog.
TLDR: Faster, safer, cool new features, and a promise of stability.
Back Story
I teach an intro to regression course in a social science department at university. It’s a fun class to teach, because it has a really applied focus. The tools we discuss are super useful, and the students come out with some concrete new skills they can apply to various real world problems.
In that class, one thing we often struggle with is what I like to call the “Last Mile” problem of statistics. We spend a lot of time picking the perfect statistical model, the one that best fits our data and question. Then, we learn the right incantation in R to fit the model. But what happens after we fit it? How can we take the last step of the analysis, to go from estimation to interpretation? Coefficient estimates are often expressed on weird scales, so researchers have to do a lot of gymnastics to interpret them. All the tricks we learn in stats class to interpret our results are difficult to remember, inconsistent across models, annoying to write up in code. All of this feels harder than it should be.
Back in 2021, I was a regular user of the margins package, by the great Thomas Leeper. That package was excellent. It was a total game changer for me, because I could fit a bunch of different models, plug them into a common post-estimation machinery, and get results that were easy to intepret. But in one particular application, my laptop hung, and I just couldn’t get margins to spit out the results I needed. After looking at the internals of the package for a bit, I found a simple algebra trick to speed up computation significantly. And after some more poking around, I got ideas for a fundamental rethink of the approach, and a complete re-write of the package. That was the birth of marginaleffects.
That side quest got out of hand. Honestly, I completely lost control and got obsessed. So here we are, five years later. I probably spent hundreds (thousands?) of hours working on marginaleffects, wrote a (free) book, an article with Julia, and another one with Noah and Andrew.
And marginaleffects version 1.0.0 is now out on CRAN! What does it mean?
Version 1.0.0
First, the fun stuff.
Version 1.0.0 comes with lots of new features. For example, marginaleffects now supports over 100 differeent model classes, including the all new svy_vglm, glmgee, mmrm, nestedLogit, gnm, and clmm2.
Pedro Sant’Anna also contributed new “unconditional” standard errors that account for sampling variation in the covariate distribution. That’s an important and long awaited feature. (Thanks to Grant McDermott, Noah Greifer, and Stefan Hansen for enlightening discussion on this topic!)
But the headliner, for me, is internal. The package got a massive refactor that should dramatically improve speed and safety. In particular, we now use analytic derivatives for many common operations, which should make many computations faster, less fickel, and more accurate. There’s also a new internal engine for aggregation that is much more efficient. It also handles a lot tricky alignment issues more robustly.
The upshot is that the package will be much safer and easier to maintain in the future. Users also should see a noticeable speed-up in many calls (think: 5 to 30x).
The Future
marginaleffects is no longer a small side project. A ton of users have filed bug reports and feature requests. 1300 Github Issues have been opened and closed. A bunch of great developers have generously donated code. Researchers in many different fields have used it to interpret their models. Google Scholar tells me that the package has been cited 1000 times!
So I’m calling it: marginaleffects is Mature Technology®.
Of course, there will be new bugs to squash and new features to add, but the core funcationality is there. The interface feels flexible, and I’m happy with it. I want people to feel like they can rely on it: marginaleffects should be “boring software” that just works. Something you don’t need to worry about.
Version 1.0.0 means that development will continue. We’ll support new models, add cool features, and fix bugs. We will also be much more intentional about making changes that that could affect numerical results or user interactions.
Thanks to everyone who has used or contributed to marginaleffects over the years! I really appreciate it!