pm_boxcox: Box-Cox and Yeo-Johnson Transformations of a Response

View source: R/back-transform.R

pm_boxcoxR Documentation

Box-Cox and Yeo-Johnson Transformations of a Response

Description

Power transformations to use for the response in a model formula, e.g. lm(pm_boxcox(y, 0.25) ~ A). predictmeans and covariatemeans recognise them (as they recognise log(y), log(y + c), log10(y), log2(y), log1p(y), sqrt(y), y^p, 1/y, qlogis(y) and asin(sqrt(y))) and give the means back-transformed to the original scale as well; bias_adjust = TRUE there gives the mean rather than the median of the original scale.

Usage

pm_boxcox(y, lambda)
pm_yeojohnson(y, lambda)

Arguments

y

A numeric vector; positive for pm_boxcox(), any values for pm_yeojohnson().

lambda

The power: one number. Box-Cox: 1 leaves the shape of y as it is, 0.5 is like a square root, 0 is the logarithm, -1 like a reciprocal. pm_check reports the value the data suggest for an lm fit.

Details

Box-Cox: (y^\lambda - 1)/\lambda, and \log y for \lambda = 0. Yeo-Johnson (2000): the same for y + 1 when y \ge 0, and -((1 - y)^{2 - \lambda} - 1)/(2 - \lambda) (-\log(1 - y) for \lambda = 2) when y < 0, so zero and negative values are allowed.

Choose a transformation from the residuals of the model, not from the raw response, and prefer a generalized linear (mixed) model for counts and proportions.

Value

The transformed values.

Author(s)

Dongwen Luo, Siva Ganesh and John Koolaard

References

Box, G. E. P. and Cox, D. R. (1964), An analysis of transformations, Journal of the Royal Statistical Society B, 26(2), 211-252.

Yeo, I.-K. and Johnson, R. A. (2000), A new family of power transformations to improve normality or symmetry, Biometrika, 87(4), 954-959.

See Also

predictmeans, pm_check

Examples

  library(predictmeans)
  Oats <- as.data.frame(nlme::Oats)
  Oats$nitro <- factor(Oats$nitro)
  fm <- lm(pm_boxcox(yield, 0.5) ~ Block + nitro, data = Oats)
  predictmeans(fm, "nitro", plot = FALSE)$means

predictmeans documentation built on Nov. 24, 2026, 5:10 p.m.