Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

boxcox_trans

Box-Cox & modulus transformations


Description

The Box-Cox transformation is a flexible transformation, often used to transform data towards normality. The modulus transformation generalises Box-Cox to also work with negative values.

Usage

boxcox_trans(p, offset = 0)

modulus_trans(p, offset = 1)

Arguments

p

Transformation exponent, λ.

offset

Constant offset. 0 for Box-Cox type 1, otherwise any non-negative constant (Box-Cox type 2). modulus_trans() sets the default to 1.

Details

The Box-Cox power transformation (type 1) requires strictly positive values and takes the following form for y > 0:

y^(λ) = (y^λ - 1)/λ

When y = 0, the natural log transform is used.

The modulus transformation implements a generalisation of the Box-Cox transformation that works for data with both positive and negative values. The equation takes the following forms, when y != 0 :

y^(λ) = sign(y)*((|y|+1)^λ - 1)/λ

and when y = 0:

y^(λ) = sign(y) * ln(|y| + 1)

References

Box, G. E., & Cox, D. R. (1964). An analysis of transformations. Journal of the Royal Statistical Society. Series B (Methodological), 211-252. https://www.jstor.org/stable/2984418

John, J. A., & Draper, N. R. (1980). An alternative family of transformations. Applied Statistics, 190-197. http://www.jstor.org/stable/2986305

See Also

Examples

plot(boxcox_trans(-1), xlim = c(0, 10))
plot(boxcox_trans(0), xlim = c(0, 10))
plot(boxcox_trans(1), xlim = c(0, 10))
plot(boxcox_trans(2), xlim = c(0, 10))

plot(modulus_trans(-1), xlim = c(-10, 10))
plot(modulus_trans(0), xlim = c(-10, 10))
plot(modulus_trans(1), xlim = c(-10, 10))
plot(modulus_trans(2), xlim = c(-10, 10))

scales

Scale Functions for Visualization

v1.1.1
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], Dana Seidel [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.