BoxCox {geoR}R Documentation

Box-Cox transformation related functions

Description

Estimate parameters and plot results , computes density and random generation for the Box-Cox normal transformed distribution.

Usage

boxcox.fit(data, xmat, lambda, lambda2 = FALSE, add.to.data = 0,...)

print.boxcox.fit(x, ...)

plot.boxcox.fit(x, hist = TRUE, data = eval(x$call$data), ...)

lines.boxcox.fit(x, data = eval(x$call$data), ...)

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

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

Arguments

data a vector with data.
xmat a matrix of covariates. Defaults to rep(1, length(y)).
lambda numerical value(s) of the transformation parameter lambda. Used as initial value for the parameter estimation function. If not provided default values are assumed. If multiple values are passed the one with highest likelihood is used as initial value.
lambda2 numerical value(s) of the additional transformation (see DETAILS below). Defaults to FALSE. If TRUE this parameter is also estimated and the initial value is set to the absolute value of the minimum data. A numerical value provided is used as initial value. As for lambda multiple values are allowed.
add.to.data a constant to be added to the data.
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 means at for the normal scale.
sd a vector of standard deviations at the normal scale.
hist logical indicating whether histograms are to be plotted.
... extra parameters to be passed to the minimization function optim (boxcox.fit), hist (plot) or curve (lines).

Details

Denote Y the variable at the original scale. The Box-Cox transformation is defined by:

Y' = log(Y) if lambda = 0 , Y' = ((Y ^ lambda) - 1)/lambda otherwise

.

An additional shifting parameter lambda2 can be included in which case the transformation is given by:

Y' = log(Y + lambda2) if lambda = 0 , Y' = (((Y + lambda2) ^ lambda) - 1)/lambda otherwise

.

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

Value

The functions returns the following results:

boxcox.fit a list with estimated parameters and results on the numerical minimization.
print.boxcox.fit print estimated parameters. No values returned.
plot.boxcox.fit plots histogram of the data (optional) and the model. No values returned. This function is only valid if covariates are not included in boxcox.fit.
lines.boxcox.fit adds a line with the fitted model to the current plot. No values returned. This function is only valid if covariates are not included in boxcox.fit.
rboxcox a vector with simulated observations.
dboxcox a vector of densities.

normal-bracket101bracket-normal

Author(s)

Paulo Justiniano Ribeiro Jr. Paulo.Ribeiro@est.ufpr.br,
Peter J. Diggle p.diggle@lancaster.ac.uk.

References

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

See Also

The minimization function optim, boxcox in the package MASS and boxcox in the package car.

Examples

## Simulating data
simul <- rboxcox(100, lambda=0.5, mean=10, sd=2)
## Finding the ML estimates
ml <- boxcox.fit(simul)
ml
## Ploting histogram and fitted model
plot(ml)
##
## 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)
##
## Another example, now estimating lambda2
##
simul <- rboxcox(100, lambda=0.5, mean=10, sd=2)
ml <- boxcox.fit(simul, lambda2 = TRUE)
ml
plot(ml)
##
## An example with a regression model
##
if(require(MASS)){
  data(trees)
  boxcox.fit(data = trees[,3], xmat = trees[,1:2])
  }


[Package Contents]