Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boxcox_trans functions not always valid #103

Closed
BenOnEarth opened this issue Oct 7, 2017 · 2 comments
Closed

boxcox_trans functions not always valid #103

BenOnEarth opened this issue Oct 7, 2017 · 2 comments
Labels

Comments

@BenOnEarth
Copy link

@BenOnEarth BenOnEarth commented Oct 7, 2017

In boxcox_trans, trans and inv functions include sign() and abs() (maybe for preserving order of values when 0<x<1 ?), but this then passes not totally correct functions to the transformer.

 trans <- function(x) (x^p - 1)/p * sign(x - 1)
inv <- function(x) (abs(x) * p + 1 * sign(x))^(1/p)

Using this form, for data 0 < x < 1, inv(trans(x)) != x

Eliminating those and using the basic formula for Box-Cox Power transformations:

trans <- function(x) (x^p - 1)/p
inv <- function(x) (x * p + 1)^(1/p)

I've confirmed this works for all of my data x>0, and that inv(trans(x)) == x. I've also used this to scale my axes successfully.
I'm new to git, so I'm just reporting this here.

@statist7
Copy link

@statist7 statist7 commented May 17, 2018

trans and inv are wrong - they should be:

trans <- function(x) (x^p - 1)/p * sign(p)
inv <- function(x) (x * p * sign(p) + 1)^(1/p)

With these changes, for all x >= 0, inv(trans(x)) == x.

dpseidel added a commit to dpseidel/scales that referenced this issue Jun 27, 2018
implements Modulus generalization, Closes r-lib#103
@dpseidel dpseidel added wip and removed reprex labels Jun 27, 2018
dpseidel pushed a commit that referenced this issue Jun 29, 2018
Dana Paige Seidel
implements Modulus generalization, Closes #103
@statist7
Copy link

@statist7 statist7 commented Jun 29, 2018

The Box-Cox and modulus transformations are distinct, yet this treats mt as generalising Box-Cox.

Box-Cox uses x^p while mt uses sign(x) * (abs(x) + 1)^p, which for positive x is (x + 1)^p.

So a proper solution should provide Box-Cox and mt as two distinct functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants