# normBoxCox

normBoxCox computes (normalized) Box-Cox transformation

## Syntax

• Ytra=normBoxCox(Y,ColtoTra,la)example
• Ytra=normBoxCox(Y,ColtoTra,la,Name,Value)example

## Description

 Ytra =normBoxCox(Y, ColtoTra, la) Comparison between Box-Cox and Yeo-Johnson transformation.

 Ytra =normBoxCox(Y, ColtoTra, la, Name, Value) Mussels data.

## Examples

expand all

### Comparison between Box-Cox and Yeo-Johnson transformation.

close all
y=(-2:0.1:2)';
n=length(y);
la=-1:1:3;
nla=length(la);
YtraYJ=zeros(n,nla);
YtraBC=nan(n,nla);
posy=y>0;
for j=1:nla
YtraYJ(:,j)=normYJ(y,1,la(j),'Jacobian',false);
YtraBC(posy,j)=normBoxCox(y(posy),1,la(j),'Jacobian',false);
end
subplot(1,2,1)
plot(y,YtraYJ)
for j=1:nla
text(y(1), YtraYJ(1,j),['\lambda=' num2str(la(j))])
end
xlabel('Original values')
ylabel('Transformed values')
title('Yeo-Johnson transformation')
subplot(1,2,2)
plot(y,YtraBC)
xlim([y(1) y(end)])
for j=1:nla
text(y(16), YtraBC(22,j),['\lambda=' num2str(la(j))])
end
xlabel('Original values')
ylabel('Transformed values')
title('Box-Cox transformation')

### Mussels data.

load('mussels.mat');
Y=mussels{:,:};
la=[0.5 0 0.5 0 0];
% Transform all columns of matrix Y according to the values of la
Y=normBoxCox(Y,[],la);

## Related Examples

expand all

### Check the inverse tranformation.

load('mussels.mat');
Y=mussels{:,:};
la=[0.5 0 0.5 0 0];
% Transform all columns of matrix Y according to the values of la
Ytra=normBoxCox(Y,[],la,'Jacobian',false);
Ychk=normBoxCox(Ytra,[],la,'inverse',true);
disp(max(max(abs(Y-Ychk))))

## Input Arguments

### Y — Input data. Matrix.

n x v data matrix; n observations and v variables. Rows of Y represent observations, and columns represent variables.

Missing values (NaN's) and infinite values (Inf's) are allowed, since observations (rows) with missing or infinite values will automatically be excluded from the computations.

Data Types: single|double

### ColtoTra — Variable to transform. Vector.

k x 1 integer vector specifying the variables which must be transformed. If it is missing and length(la)=v all variables are transformed

Data Types: single|double

### la — transformation parameters. Vector.

k x 1 vector containing set of transformation parameters for the k ColtoTra.

Data Types: single|double

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as  Name1,Value1,...,NameN,ValueN.

Example:  'inverse',true , 'Jacobian',true 

### inverse —Inverse transformation.logical.

If inverse is true, the inverse transformation is returned. The default value of inverse is false.

Example:  'inverse',true 

Data Types: Logical

### Jacobian —Requested Jacobian of transformed values.true (default) | false.

If true (default) the transformation is normalized to have Jacobian equal to 1

Example:  'Jacobian',true 

Data Types: Logical

## Output Arguments

### Ytra —transformed data matrix.  Matrix

n x v data matrix containing transformed observations 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.

## References

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.