boxCox: Box-Cox Power Transform

View source: R/boxCox.R

boxCoxR Documentation

Box-Cox Power Transform

Description

Functions for transforming and back-transforming data using the Box-Cox power transform, with options to preserve the measurement units.

Usage

boxCox(x, lambda = 1, GM, alpha = 0)

IboxCox(x, lambda = 1, GM, alpha = 0)

Arguments

x

a numeric vector to be transformed by boxCox or back-transformed by IboxCox. Must be strictly positive for the forward trasnformation—the argument alpha can be used to force positive values. Missing values are allowed and result in corresponding missing values in the output. See Details.

lambda

the power term in the Box-Cox transformation. The value of 1 is a linear transform, the value of 0 results in a natural log transform.

GM

the value to use for the geometric mean of x. If not supplied, then compute the geometric mean (boxCox) or extract from the attributes of x (IboxCox).

alpha

an offset value for x.

Details

If x contains missing values, then GM is computed after omitting the missing values and the output vector has a missing value wherever x has a missing value.

The function boxCox computes the forward transform and the function IboxCox computes the inverse [boxCox] transform, or back-transform.

Value

A numeric vector of the transformed or back-transformed values in x with an attribute "GM" of the geometric mean.

Note

The original power transform described by Box and Cox (1964) is adjusted by a power transform of the geometric mean to retain the correct dimensional units of the original data as described in section 13.2 by Draper and Smith (1998).

References

Box, G.E.P., and Cox, D.R., 1964, An analysis of transformations: Journal of the Royal Statistical Society, v. 26, Series B, p. 211–243.
Draper, N.R., and Smith, H., 1998, Applied regression analysis: New York, John Wiley and Sons, 706 p.

See Also

hyperbolic

Examples

X.test <- c(1,4,9,16,25,36,49)
boxCox(X.test)
boxCox(X.test, lambda=0)
IboxCox(boxCox(1:3, lambda=0), lambda=0) # verify the back-transform
## Should return
# [1] 1 2 3
# attr(,"GM")
# [1] 1.817121

USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.