Perform a Yeo-Johnson Transformation and center/scale a vector to attempt normalization
A vector to normalize with Yeo-Johnson
A value to compare lambda against to see if it is equal to zero
If TRUE, the transformed values are also centered and scaled, such that the transformation attempts a standard normal
Additional arguments that can be passed to the estimation of the lambda parameter (lower, upper)
an object of class 'yeojohnson'
a vector of data to be (reverse) transformed
if TRUE, performs reverse transformation
A list of class yeojohnson
with elements
transformed original data
original data
mean after transformation but prior to standardization
sd after transformation but prior to standardization
estimated lambda value for skew transformation
number of nonmissing observations
Pearson's P / degrees of freedom
Was the transformation standardized
The predict
function returns the numeric value of the transformation
performed on new data, and allows for the inverse transformation as well.
yeojohnson
estimates the optimal value of lambda for the
Yeo-Johnson transformation. This transformation can be performed on new
data, and inverted, via the predict
function.
The Yeo-Johnson is similar to the Box-Cox method, however it allows for the
transformation of nonpositive data as well. The step_YeoJohnson
function in the recipes
package is another useful resource (see
references).
Yeo, I. K., & Johnson, R. A. (2000). A new family of power transformations to improve normality or symmetry. Biometrika.
Max Kuhn and Hadley Wickham (2017). recipes: Preprocessing Tools to Create Design Matrices. R package version 0.1.0.9000. https://github.com/topepo/recipes
x <- rgamma(100, 1, 1)
yeojohnson_obj <- yeojohnson(x)
yeojohnson_obj
#> Standardized Yeo-Johnson Transformation with 100 nonmissing obs.:
#> Estimated statistics:
#> - lambda = -0.6285334
#> - mean (before standardization) = 0.4860509
#> - sd (before standardization) = 0.2433941
p <- predict(yeojohnson_obj)
x2 <- predict(yeojohnson_obj, newdata = p, inverse = TRUE)
all.equal(x2, x)
#> [1] TRUE