Margins.jl and FormulaCompiler.jl: Marginal effects for Julia

Marginal effects analysis is fundamental to interpreting statistical models, yet existing implementations face computational constraints that limit analysis at scale. I introduce two Julia packages that address this gap. Margins.jl provides a clean two-function API organizing analysis around a framework centered on the evaluation context (population vs profile) and the analytical target (effects vs predictions). The package supports interaction analysis through second differences, elasticity measures, categorical mixtures for representative profiles, and robust standard errors. FormulaCompiler.jl provides the computational foundation, transforming statistical formulas into type-specialized evaluators. Together, these packages perform well compared to R’s marginaleffects package, and provide the first comprehensive and efficient marginal effects implementation for Julia’s statistical ecosystem.

See the packages at

13 Likes

Nice! How does this compare to GitHub - beacon-biosignals/Effects.jl: Effects Prediction for Regression Models?

Thank you! Effects.jl calculates adjusted predictions, and is closer to R’s emmeans (estimated marginal means at reference grids – profile-based estimates), while Margins.jl is a bit more comprehensive, also including the functionality of R’s marginaleffects (or margins in Stata), computing both derivatives/contrasts and predictions, with both population-averaged and profile-based evaluation. It is also designed to be very efficient for larger datasets and complex models.

4 Likes