FormulaCompiler.jl and Margins.jl: Efficient Marginal Effects in Julia
By: Eric Feltham
Marginal effects analysis is fundamental to interpreting statistical models, yet existing implementations face computational constraints that limit analysis at scale. We introduce two Julia packages that address this gap. Margins.jl provides a clean two-function API organizing analysis around a 2-by-2 framework: evaluation context (population vs profile) by 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 zero-allocation, type-specialized evaluators that enable O(p) per-row computation independent of dataset size. Together, these packages achieve 622x average speedup and 460x memory reduction compared to R's marginaleffects package, with successful computation of average marginal effects and delta-method standard errors on 500,000 observations where R fails due to memory exhaustion, providing the first comprehensive and efficient marginal effects implementation for Julia's statistical ecosystem.
Similar Papers
A Practical Guide to Estimating Conditional Marginal Effects: Modern Approaches
Methodology
Shows how changes affect different people.
Treatment effects at the margin: Everyone is marginal
Econometrics
Finds true job help effects, not just who got hired.
A Common Interface for Automatic Differentiation
Mathematical Software
Lets scientists easily test different math tools.