Learn R Programming

geoR (version 1.5-6)

boxcox: The Box-Cox Transformed Normal Distribution

Description

Functions related with the Box-Cox family of transformations. Density and random generation for the Box-Cox transformed normal distribution with mean equal to mean and standard deviation equal to sd, in the normal scale.

Usage

rboxcox(n, lambda, lambda2 = NULL, mean = 0, sd = 1)

dboxcox(x, lambda, lambda2 = NULL, mean = 0, sd = 1)

Arguments

lambda
numerical value(s) for the transformation parameter $\lambda$.
lambda2
logical or numerical value(s) of the additional transformation (see DETAILS below). Defaults to NULL.
n
number of observations to be generated.
x
a vector of quantiles (dboxcox) or an output of boxcox.fit (print, plot, lines).
mean
a vector of mean values at the normal scale.
sd
a vector of standard deviations at the normal scale.

Value

  • The functions returns the following results:
  • rboxcoxa vector of random deviates.
  • dboxcoxa vector of densities.

concept

Box-Cox trransformation

Details

Denote $Y$ the variable at the original scale and $Y'$ the transformed variable. The Box-Cox transformation is defined by: $$Y' = \left{ \begin{array}{ll} log(Y) \mbox{ , if $\lambda = 0$} \cr \frac{Y^\lambda - 1}{\lambda} \mbox{ , otherwise} \end{array} \right.$$. An additional shifting parameter $\lambda_2$ can be included in which case the transformation is given by: $$Y' = \left{ \begin{array}{ll} log(Y + \lambda_2) \mbox{ , $\lambda = 0$ } \cr \frac{(Y + \lambda_2)^\lambda - 1}{\lambda} \mbox{ , otherwise} \end{array} \right.$$.

The function rboxcox samples $Y'$ from the normal distribution using the function rnorm and backtransform the values according to the equations above to obtain values of $Y$. If necessary the back-transformation truncates the values such that $Y' \geq \frac{1}{\lambda}$ results in $Y = 0$ in the original scale. Increasing the value of the mean and/or reducing the variance might help to avoid truncation.

References

Box, G.E.P. and Cox, D.R.(1964) An analysis of transformations. JRSS B 26:211--246.

See Also

The parameter estimation function boxcox.fit, the function boxcox in the package MASS and the function boxcox in the package car.

Examples

Run this code
## Simulating data
simul <- rboxcox(100, lambda=0.5, mean=10, sd=2)
##
## Comparing models with different lambdas,
## zero  means and unit variances
curve(dboxcox(x, lambda=-1), 0, 8)
for(lambda in seq(-.5, 1.5, by=0.5))
  curve(dboxcox(x, lambda), 0, 8, add = TRUE)

Run the code above in your browser using DataLab