View source: R/S05_Statistics.R
yeo_johnson_transform | R Documentation |
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)
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. |
The transformation parameter to use is estimated via maximum likelihood using the base:optimize and stats:dnorm functions.
A numeric vector, the transformed values of x.
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
# 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
x_transformed <- yeo_johnson_transform(x)
# Extract results of maximum likelihood estimation
attributes(x_transformed)$mle_for_yeo_johnson
shapiro.test( x_transformed ) # Test of normality shows improvement
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.