Estimates and applies best-fitting Yeo-Johnson transformation parameter via maximum likelihood for a vector of numeric values.

yeo_johnson_transform(x, lower = -100, upper = 100)

Arguments

x

A numeric vector (values can be positive, negative, or zero).

lower

The smallest value for the transformation parameter to consider.

upper

The highest value for the transformation parameter to consider.

Value

A numeric vector, the transformed values of x.

Details

The transformation parameter to use is estimated via maximum likelihood using the base:optimize and stats:dnorm functions.

References

Yeo, I. K., & Johnson, R. A. (2000). A new family of power transformations to improve normality or symmetry. Biometrika, 87 (4), 954-959. https://doi.org/10.1093/biomet/87.4.954

Examples

# Example from page 958 of Yeo & Johnson (2000)
x <- c(
  6.1, -8.4, 1.0, 2.0, 0.7, 2.9, 3.5,
  5.1, 1.8, 3.6, 7.0, 3.0, 9.3, 7.5, -6.0
)
shapiro.test( x ) # Test of normality
#> 
#> 	Shapiro-Wilk normality test
#> 
#> data:  x
#> W = 0.8994, p-value = 0.09319
#> 
x_transformed <- yeo_johnson_transform(x)
# Extract results of maximum likelihood estimation
attributes(x_transformed)$mle_for_yeo_johnson
#> $maximum
#> [1] 1.305274
#> 
#> $objective
#> [1] -42.08013
#> 
shapiro.test( x_transformed ) # Test of normality shows improvement
#> 
#> 	Shapiro-Wilk normality test
#> 
#> data:  x_transformed
#> W = 0.97474, p-value = 0.9209
#>