View source: R/S05_Statistics.R
boxcox_transform | R Documentation |
Wrapper function to the boxcox
function; estimates the optimal parameter
for the Box-Cox power transformation and
then applies the appropriate power transformation
to the outcome variable.
boxcox_transform(
x,
outcome = NULL,
parameter_grid = seq(-3, 3, 0.01),
output = TRUE
)
x |
Either
|
outcome |
An optional character string with
the column name for the outcome variable in |
parameter_grid |
Vector specifying the grid of parameters to explore for maximum likelihood estimation. |
output |
Logical; if |
The Box-Cox power transformation for a vector of
positive values x
and parameter \lambda
is:
f(x) = \frac{x^{\lambda} - 1}{\lambda}.
For \lambda = 0
, one simply uses the log transform.
Either the maximum likelihood estimate for the power transformation parameter or a vector for the outcome variable following the transformation.
# Simulate 100 values from the normal distribution
set.seed(3)
z <- rnorm(100)
# Transform the simulated values
x <- (z * .5 + 1)^(1 / .5)
# Maximum likelihood estimate for
# transformation parameter
boxcox_transform(x, output = FALSE)
# Histogram of x, transform of x, and
# original simulated values
layout(rbind(1, 2, 3))
hist(x)
hist(boxcox_transform(x))
hist(z)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.