normYJ: Computes (normalized) Yeo-Johnson transformation

View source: R/normYJ.R

normYJR Documentation

Computes (normalized) Yeo-Johnson transformation

Description

Computes (normalized) Yeo-Johnson transformation

Usage

normYJ(
  X,
  Col2Tra,
  la,
  Jacobian = TRUE,
  inverse = FALSE,
  bsb,
  trace = FALSE,
  ...
)

Arguments

X

The data matrix: n observations and p variables. The rows of X represent observations, and the columns represent variables. Missing values (NA's) and infinite values (Inf's) are allowed, since observations (rows) with missing or infinite values will automatically be excluded from the computations.

Col2Tra

Which variables to transform. An integer vector of length k specifying the variables which must be transformed. If it is missing and length(la)=p all variables are transformed

la

Transformation parameters. A vector of lenghth k containing set of transformation parameters for the k Col2Tra variables.

Jacobian

Requested Jacobian of transformed values. If Jacobian=TRUE the default, the transformation is normalized to have Jacobian equal to 1. Note that this optional argument is ignored if inverse=TRUE.

inverse

Wheather to return the inverse transformation. The default is inverse=FALSE.

bsb

Units to be used in the computation of the Jacobian, a vector of length m or or a logical vector of length n. The default value is bsb=1:n, i.e. all units are used to compute the Jacobian. Note that this option takes effect only if Jacobian=TRUE.

trace

Whether to print intermediate results. Default is trace=FALSE.

...

potential further arguments passed to lower level functions.

Details

The Yeo-Johnson transformation is the Box-Cox transformation of y+1 for nonnegative values, and of |y|+1 with parameter 2-\lambda for y negative

Value

The transformed data matrix.

Author(s)

FSDA team, valentin.todorov@chello.at

References

Yeo, I.K and Johnson, R. (2000), A new family of power transformations to improve normality or symmetry, "Biometrika", Vol. 87, pp. 954-959.

Examples


 ## Not run: 
 
 ##  Example of use of normYJ() with all default options.
 ##  Transform value -3, -2, ..., 3
 y <- (-3):3
 lambda <- 0
 y1 <- normYJ(y, Col2Tra=1, la=lambda)
 plot(y, y1, xlab='Original values', ylab='Transformed values') 
 
 
 ## 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)


fsdaR documentation built on May 20, 2026, 1:07 a.m.