Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tk3369/BoxCoxTrans.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
tk3369 committed Sep 9, 2018
2 parents 5568f86 + 7df55a3 commit 753585c
Showing 1 changed file with 73 additions and 38 deletions.
111 changes: 73 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![Coverage Status](https://coveralls.io/repos/github/tk3369/BoxCoxTrans.jl/badge.svg?branch=master)](https://coveralls.io/github/tk3369/BoxCoxTrans.jl?branch=master)

This package provides an implementation of Box Cox transformation.
See [Wikipedia - Power Transform](https://en.wikipedia.org/wiki/Power_transform)
for more information.

Requires Julia 0.7/1.0.

Expand All @@ -16,64 +18,97 @@ Requires Julia 0.7/1.0.

## Usage

The simplest way is to just call the `transform` function with an array of numbers.

```
julia> using Distributions, UnicodePlots, BoxCoxTrans
julia> x = rand(Gamma(2,2), 10000) .+ 1;
julia> histogram(x)
┌────────────────────────────────────────┐
(0.0,2.0] │▇▇▇▇▇▇▇▇▇ 899 │
(2.0,4.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3458 │
(4.0,6.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2725 │
(6.0,8.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1497 │
(8.0,10.0] │▇▇▇▇▇▇▇▇ 794 │
(10.0,12.0] │▇▇▇ 336 │
(12.0,14.0] │▇▇ 161 │
(14.0,16.0] │▇ 75 │
(16.0,18.0] │ 31 │
(18.0,20.0] │ 11 │
(20.0,22.0] │ 8 │
(22.0,24.0] │ 4 │
(24.0,26.0] │ 1 │
┌──────────────────────────────────────────┐
(0.0,2.0] │▇▇▇▇▇▇▇▇ 852 │
(2.0,4.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3554 │
(4.0,6.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2655 │
(6.0,8.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1524 │
(8.0,10.0] │▇▇▇▇▇▇▇▇ 798 │
(10.0,12.0] │▇▇▇ 316 │
(12.0,14.0] │▇▇ 170 │
(14.0,16.0] │▇ 76 │
(16.0,18.0] │ 35 │
(18.0,20.0] │ 14 │
(20.0,22.0] │ 5 │
(22.0,24.0] │ 1 │
└────────────────────────────────────────┘
julia> histogram(BoxCoxTrans.transform(x))
┌────────────────────────────────────────┐
(0.0,0.5] │▇▇▇▇▇ 429 │
(0.5,1.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1598 │
(1.0,1.5] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2916 │
(1.5,2.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3077 │
(2.0,2.5] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1614 │
(2.5,3.0] │▇▇▇▇ 344 │
(3.0,3.5] │ 22 │
(0.0,0.2] │▇▇ 64 │
(0.2,0.4] │▇▇▇▇ 166 │
(0.4,0.6] │▇▇▇▇▇▇▇▇▇▇ 386 │
(0.6,0.8] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 559 │
(0.8,1.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 887 │
(1.0,1.2] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1091 │
(1.2,1.4] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1257 │
(1.4,1.6] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1298 │
(1.6,1.8] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1281 │
(1.8,2.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1103 │
(2.0,2.2] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 877 │
(2.2,2.4] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 541 │
(2.4,2.6] │▇▇▇▇▇▇▇ 272 │
(2.6,2.8] │▇▇▇▇ 153 │
(2.8,3.0] │▇ 50 │
(3.0,3.2] │ 14 │
(3.2,3.4] │ 1 │
└────────────────────────────────────────┘
```

You can examine the power transform paremeter dervied by the program:
You can examine the power transform parameter (λ) dervied by the program:
```
julia> BoxCoxTrans.lambda(x).value
0.024021300279245223
0.013544484565969775
```

You can transfrom the data using your own λ:
```
julia> histogram(BoxCoxTrans.transform(x, 0.03))
julia> histogram(BoxCoxTrans.transform(x, 0.01))
┌────────────────────────────────────────┐
(0.0,0.5] │▇▇▇▇▇ 425 │
(0.5,1.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1584 │
(1.0,1.5] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2898 │
(1.5,2.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3051 │
(2.0,2.5] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1647 │
(2.5,3.0] │▇▇▇▇ 366 │
(3.0,3.5] │ 29 │
(0.0,0.2] │▇▇ 64 │
(0.2,0.4] │▇▇▇▇ 166 │
(0.4,0.6] │▇▇▇▇▇▇▇▇▇▇ 386 │
(0.6,0.8] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 563 │
(0.8,1.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 894 │
(1.0,1.2] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1094 │
(1.2,1.4] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1261 │
(1.4,1.6] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1302 │
(1.6,1.8] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1289 │
(1.8,2.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1111 │
(2.0,2.2] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 868 │
(2.2,2.4] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 534 │
(2.4,2.6] │▇▇▇▇▇▇▇ 268 │
(2.6,2.8] │▇▇▇▇ 142 │
(2.8,3.0] │▇ 47 │
(3.0,3.2] │ 11 │
└────────────────────────────────────────┘
```

## Reference

* [Wikipedia - Power Transform](https://en.wikipedia.org/wiki/Power_transform)


There's an option to scale the results by the geometric mean.
```
julia> histogram(BoxCoxTrans.transform(x; scaled = true))
┌────────────────────────────────────────┐
(0.0,1.0] │▇▇ 81 │
(1.0,2.0] │▇▇▇▇▇▇ 258 │
(2.0,3.0] │▇▇▇▇▇▇▇▇▇▇▇▇ 540 │
(3.0,4.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 868 │
(4.0,5.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1234 │
(5.0,6.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1467 │
(6.0,7.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1521 │
(7.0,8.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1488 │
(8.0,9.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1133 │
(9.0,10.0] │▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 806 │
(10.0,11.0] │▇▇▇▇▇▇▇▇ 359 │
(11.0,12.0] │▇▇▇▇ 188 │
(12.0,13.0] │▇ 50 │
(13.0,14.0] │ 7 │
└────────────────────────────────────────┘
```

0 comments on commit 753585c

Please sign in to comment.