interlace: Closing the Mixed-Effects Modelling Gap in Python
Helio Pais
The StepStone Group
Mixed-effects models are central to applied statistics, yet Python’s ecosystem for fitting them remains limited compared to R. The most widely used Python option, statsmodels’ MixedLM [3], cannot accommodate crossed random effects and offers no influence diagnostics beyond residuals. Practitioners who need these capabilities must either bridge to R via rpy2 (incurring computational overhead) or turn to Bayesian frameworks whose cost can be orders of magnitude higher. This leaves a large class of routine mixed-model analyses inaccessible from a Python workflow.
We present interlace, an open-source Python library for mixed-effects modelling. interlace implements profiled restricted maximum likelihood (REML) estimation with sparse Cholesky factorisation—the same algorithmic strategy underlying R’s lme4 [1]—and supports both crossed and nested random intercepts and slopes through a formula interface. Beyond point estimation, the library provides estimated marginal means, Type I–III ANOVA tables, profile likelihood confidence intervals, parametric bootstrap, and group-level cross-validation—none of which are available together in any existing Python package.
interlace also provides regression diagnostics for hierarchical models: leverage, Cook’s distance, MDFFITS, and COVTRACE at both the observation and group level, mirroring R’s HLMdiag package [2]. These measures allow practitioners to assess the influence of individual observations and clusters on fixed-effect estimates and variance components—functionality that has been largely absent from the Python ecosystem.
Systematic benchmarks against lme4 confirm numerical parity: fixed-effect estimates agree within . Computationally, interlace is competitive with or faster than lme4 on problems involving nested random effects (approximately faster at observations) and operates within the same order of magnitude as fixest [4] on high-dimensional fixed-effects specifications. interlace is available on PyPI and GitHub under a BSD-3 licence.
Keywords: Mixed-effects models, REML estimation, regression diagnostics.
References
- [1] D. Bates, M. Mächler, B. Bolker, and S. Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1–48.
- [2] A. Loy and H. Hofmann (2014). HLMdiag: A Suite of Diagnostics for Hierarchical Linear Models in R. Journal of Statistical Software, 56(5), 1–28.
- [3] S. Seabold and J. Perktold (2010). statsmodels: Econometric and Statistical Modeling with Python. In Proceedings of the 9th Python in Science Conference, 92–96.
- [4] L. Bergé (2018). Efficient estimation of maximum likelihood models with multiple fixed-effects: the R package fixest. CREA Discussion Papers, 13.