| normBoxCox | R Documentation |
Computes (normalized) Box-Cox transformation
normBoxCox(
X,
Col2Tra,
la,
Jacobian = TRUE,
inverse = FALSE,
bsb,
trace = FALSE,
...
)
X |
The data matrix: |
Col2Tra |
Which variables to transform. An integer vector of length |
la |
Transformation parameters. A vector of lenghth |
Jacobian |
Requested Jacobian of transformed values. If |
inverse |
Wheather to return the inverse transformation. The default is |
bsb |
Units to be used in the computation of the Jacobian, a vector of length |
trace |
Whether to print intermediate results. Default is |
... |
potential further arguments passed to lower level functions. |
When \lambda \ne 0 if Jacobian=TRUE,
ytra = (y^\lambda-1)/ (G^{(\lambda-1)} \lambda)
else if Jacobian=FALSE
ytra = (y^\lambda-1)/ \lambda
where G is the geometric mean of the observations.
When \lambda = 0 if Jacobian=TRUE,
ytra = G log(y)
else if Jacobian=FALSE
ytra = log(y)
where G is the geometric mean of the observations.
The transformed data matrix.
FSDA team, valentin.todorov@chello.at
Box, G.E.P. and Cox, D.R. (1964), An analysis of transformations (with Discussion), "Journal of the Royal Statistical Society Series B", Vol. 26, pp. 211-252.
## Not run:
## Mussels data.
data(mussels)
X <- mussels
la <- c(0.5, 0, 0.5, 0, 0)
## Transform all columns of the matrix X according to the values of la
(Y <- normBoxCox(X, la=la))
## Check the inverse tranformation.
data(mussels)
X <- mussels
la <- c(0.5, 0, 0.5, 0, 0)
## Transform all columns of matrix Y according to the values of la
Ytra <- normBoxCox(X, la=la, Jacobian=FALSE)
Ychk <- normBoxCox(Ytra, la=la, inverse=TRUE)
print(max(max(abs(X-Ychk))))
## Comparison between Box-Cox and Yeo-Johnson transformation.
y <- seq(from=-2, to=2, by=0.1)
n <- length(y)
la <- seq(from=-1, to=3, by=1)
nla <- length(la)
YtraYJ <- matrix(0, nrow=n, ncol=nla)
YtraBC <- matrix(NA, nrow=n, ncol=nla)
posy <- y>0
for(j in 1:nla) {
YtraYJ[,j] <- normYJ(y, 1, la[j], Jacobian=FALSE)
YtraBC[posy, j] <- normBoxCox(y[posy], 1, la[j],Jacobian=FALSE)
}
oldpar <- par(mfrow=c(1,2))
plot(y, YtraYJ[,1], type="n", xlab="Original values",
ylab="Transformed values", main="Yeo-Johnson transformation")
for(j in 1:nla)
lines(y, YtraYJ[,j], col=j)
for(j in 1:nla) {
text(y[1], YtraYJ[1,j], paste0("la=", la[j]))
}
plot(y, YtraBC[,1], type="n", xlab="Original values",
ylab="Transformed values", main="Box-Cox transformation")
for(j in 1:nla)
lines(y, YtraBC[,j], col=j)
for(j in 1:nla) {
text(y[16], YtraBC[22,j], paste0("la=", la[j]))
}
par(oldpar)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.