# boxcox

Box-Cox transformation

## Syntax

``[transdat,lambda] = boxcox(data)``
``transdat = boxcox(lambda,data)``

## Description

example

````[transdat,lambda] = boxcox(data)` transforms the data vector `data` using the Box-Cox transformation method into `transdat`. It also estimates the transformation parameter λ. ```

example

````transdat = boxcox(lambda,data)` transform the `data` using a certain specified λ for the Box-Cox transformation. This syntax does not find the optimum λ that maximizes the LLF.```

## Examples

collapse all

Use `boxcox` to transform the data series contained in a vector of data into another set of data series with relatively normal distributions.

Load the `SimulatedStock.mat` data file.

`load SimulatedStock.mat`

Transform the nonnormally distributed filled data series `TMW_CLOSE` into a normally distributed one using Box-Cox transformation.

` [Xbc, lambdabc] = boxcox(TMW_CLOSE)`
```Xbc = 1000×1 7.8756 7.8805 7.9173 7.8557 7.8245 7.7844 7.7811 7.8029 7.8015 7.7229 ⋮ ```
```lambdabc = 0.2151 ```

Compare the result of the `TMW_CLOSE` data series with a normal (Gaussian) probability distribution function and the nonnormally distributed `TMW_CLOSE`.

```subplot(2, 1, 1); histogram(TMW_CLOSE); grid; title('Nonnormally Distributed Data'); subplot(2, 1, 2); histogram(Xbc); grid; title('Box-Cox Transformed Data');```

The bar chart on the top represents the probability distribution function of the data series, `TMW_CLOSE`, which is the original data series. The distribution is skewed toward the left (not normally distributed). The bar chart on the bottom is less skewed to the left. If you plot a Gaussian probability distribution function (PDF) with similar mean and standard deviation, the distribution of the transformed data is close to normal (Gaussian). When you examine the contents of the resulting object `Xbc`, you find an identical object to the original object `TMW_CLOSE` but the contents are the transformed data series.

## Input Arguments

collapse all

Data, specified as a positive column vector.

Data Types: `double`

Lambda, specified as a scalar numeric or structure.

If the input `data` is a vector, `lambda` is a scalar. If the input is a financial time series object (`tsobj`), `lambda` is a structure with fields similar to the components of the object. For example, if `tsobj` contains series names `Open` and `Close`, `lambda` has fields `lambda.Open` and `lambda.Close`.

Data Types: `double` | `struct`

## Output Arguments

collapse all

Data Box-Cox transformation, returned as a vector.

Lambda transformation parameter, returned as a numeric.

collapse all

### Box Cox Transformation

`boxcox` transforms nonnormally distributed data to a set of data that has approximately normal distribution. The Box-Cox transformation is a family of power transformations.

If λ is not = `0`, then

`$data\left(\lambda \right)=\frac{dat{a}^{\lambda }-1}{\lambda }$`

If λ is = `0`, then

`$data\left(\lambda \right)=\mathrm{log}\left(data\right)$`

The logarithm is the natural logarithm (log base e). The algorithm calls for finding the λ value that maximizes the Log-Likelihood Function (LLF). The search is conducted using `fminsearch`.

## Version History

Introduced before R2006a

expand all