Learn R Programming

alr3 (version 1.1.12)

bctrans: Univariate and multivariate transformations to normality

Description

Estimates multivariate power transformations to multinormality by a maximum likelihood-like method. The univariate case is obtained when only one variable is specified.

Usage

bctrans(formula, data = NULL, subset, na.action = na.omit, ...)

## Use when you have a matrix or data.frame:
bctrans1(X, Y = NULL, start = NULL, family = "box.cox", call=NULL,...) 

## S3 methods for class 'bctrans'
lrt.bctrans(object, lrt=NULL, ones=TRUE, zeroes=TRUE)

Arguments

formula
A formula, giving the variables to be transformed. The formula can be one-sided, of the form ~ X1+X2+X3, or two-sided, of the form Y~X1+X2+X3. In the latter case, the response is not used in the transfor
data
a data.frame (or list) from which the variables in the formula should be taken.
subset
an optional vector specifying a subset of observations to be used.
na.action
If set to na.omit, the default, missing values are permitted. If set to na.fail, missing values are not permitted.
...
In bctrans, these are additional arguments passed to bctrans1, and described below. In bctrans1, these are additional arguments passed to the function maximizer optim.
X
A vector, matrix, or data frame whose columns are to be transformed.
Y
If present this vector will be part of the object created, and will be used in drawing plots. It is not used for finding transformations.
start
Starting values for the power transformation parameters; if NULL (the default), univariate transformations will be computed and used as the start values.
family
The family of transformations. The most common is "box.cox" for the Box-Cox transformation. The "yeo.johnson" transformations are used if some elements of X are negative or zero. The family "power" is used o
object
In lrt.bctrans, the name of a bctrans object.
lrt
In the lrt.bctrans command, a list of vectors each of length equal to the number of columns in X. A Likelihood ratio test that the transformation parameters equal each of these vectors will be performed.
ones
In lrt.bctrans, if TRUE test all the transformation parameters equal to one against a general alternative.
zeroes
In lrt.bctrans, if TRUE test all the transformation parameters equal to zero against a general alternative.
call
Not to be set by the user.

Value

  • bctrans returns an object of class bctrans, which may be printed or summarized. It is a list with components X containing the input data, family the family used, start the starting values, and, optim, the results from a call to optim, the function optimizer used in the routine.

Details

Given a matrix $X$ with columns $X_1\ldots,X_p$, this routine selects transformation parameters $\lambda_1,\ldots,\lambda_p$ from a one-parameter family of transformations such that the transformed variables $\psi(X_1,\lambda_1),\ldots,\psi(X_p,\lambda_p)$ are as close to multivariate normal as possible. The function uses the family of transformation you specify. If you use the family box.cox to select a transformation, it is usual to use standard power transformations in further calculations.

References

Box, G. E. P. and Cox, D. R. (1964) An analysis of transformations. Journal of the Royal Statisistical Society, Series B. 26 211-46. Cook, R. D. and Weisberg, S. (1999). Applied Regression Including Computing and Graphics. Wiley. Fox, J. (2002). R and S-Plus Companion to Applied Regression. Sage. Velilla, S. (1993). A note on the multivariate Box-Cox transformation to normality. Statistics and Probability Letters, 17, 259-263. Weisberg, S. (2005) Applied Linear Regression, third edition. Wiley. Yeo, I. and Johnson, R. (2000). A new family of power transformations to improve normality or symmetry. Biometrika, 87, 954-959.

See Also

powtran, optim, pairs,inv.res.plot, plot.bctrans

Examples

Run this code
data(highway)
b <- highway[,c(8,1,2,10,5)] # select interesting columns
summary(ans <- bctrans1(b,family="yeo.johnson")) # zeros ==> use yeo.johnson
# or, compute using a formula and get the same answer.
summary(ans2 <-
bctrans(~Len+ADT+Trks+Shld+Sigs,data=highway,family="yeo.johnson"))
# or, first fit an lm, and extract the formula
m1 <- lm(Rate~Len+ADT+Trks+Shld+Sigs,data=highway)
summary(ans3 <- bctrans(m1,data=highway,family="yeo.johnson"))
# work with the response
b$Sigs <- (round(b$Sigs*b$Len)+1)/b$Len # redefine so no zeroes
summary(ans <- bctrans1(b)) # fit with box.cox
lrt.bctrans(ans,lrt=list(c(0,0,-1,1,0)))
plot(ans,family="power") # plot, but use ordinary powers
b <- cbind(b,powtran(ans)) # add transformed variables to data frame

Run the code above in your browser using DataLab