Juliacon 2024

BoxCox.jl -- A lightweight package with nice extensions
2024-07-12 , Method (1.5)

BoxCox.jl is a lightweight package implementing the Box-Cox transformation. It natively supports transformations of unconditional distributions and distributions conditional on a linear predictor. Via package extensions, it also has specialized support for the Wilkinson-Roger formula syntax, GLM.jl, and MixedModels.jl. Diagnostic plots are provided via a package extension for Makie.jl.


BoxCox.jl provides a StatsAPI.jl-compatible implementation of the Box-Cox transformation, with plans for supporting additional power transformations such as the Yeo-Johnson transformation and Bickel-Doksum transformation. The struct representing the fitted Box-Cox transformation is callable, such that the call fit(BoxCoxTransformation, y).(y) fits and transforms the data in single step. Implementations of the Box-Cox transformation differ in their normalization of the log-likelihood; BoxCox.jl's implementation is normalized to match the behavior of the MASS package in R. The transformation is fit via nonlinear optimization, which can be applied to either the unconditional distribution or to a conditional distribution. The core package supports a conditional distribution from linear regression when passed a suitable model matrix. The core package is kept lightweight by placing specialized functionality in package extensions on Julia 1.9+. For example, the package also provides support for the StatsModels.jl-based implementation of the Wilkinson-Roger formula syntax and linear mixed-effects models from MixedModels.jl. All of these packages are used to compute a conditional distribution. No extension support is provided for GLM.jl-based models because the package-internal linear regression implementation is optimized for the repeated regression-model fitting done while fitting the Box-Cox transformation. The resultant transformation can nonetheless be used to fit a model with GLM.jl. The package was motivated by mixed-effects models and the desire for a fast, easy-to-use implementation. The tight integration with MixedModels.jl provides for exactly this: a very fast implementation of the Box-Cox transformation compared to offerings in other languages. Via a Makie.jl-based extension, the package also provides a profile plot of the likelihood for different values of the λ parameter, including confidence intervals. These plots provide the analyst with the ability to more easily choose a parameter value that has a natural interpretation but is statistically indistinguishable from the maximum likelihood estimate -- for example, a transformation of time to speed.

See also: