box_cox()
returns a transformation of the input variable using a Box-Cox
transformation. inv_box_cox()
reverses the transformation.
box_cox(x, lambda) inv_box_cox(x, lambda)
x | a numeric vector. |
---|---|
lambda | a numeric value for the transformation parameter. |
a transformed numeric vector of the same length as x.
The Box-Cox transformation is given by $$f_\lambda(x) =\frac{x^\lambda - 1}{\lambda}$$ if \(\lambda\ne0\). For \(\lambda=0\), $$f_0(x)=\log(x)$$.
Box, G. E. P. and Cox, D. R. (1964) An analysis of transformations. JRSS B 26 211--246.
Rob J Hyndman & Mitchell O'Hara-Wild
library(tsibble) library(dplyr) airmiles %>% as_tsibble() %>% mutate(box_cox = box_cox(value, lambda = 0.3))#> # A tsibble: 24 x 3 [1Y] #> index value box_cox #> <dbl> <dbl> <dbl> #> 1 1937 412 17.0 #> 2 1938 480 17.9 #> 3 1939 683 20.3 #> 4 1940 1052 23.6 #> 5 1941 1385 25.9 #> 6 1942 1418 26.1 #> 7 1943 1634 27.3 #> 8 1944 2178 30.1 #> 9 1945 3362 34.8 #> 10 1946 5948 41.9 #> # … with 14 more rows