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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

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

Fix boxcox_trans equations and docs
implements Modulus generalization, Closes r-lib#103

@dpseidel dpseidel added wip and removed reprex labels Jun 27, 2018

dpseidel added a commit that referenced this issue Jun 29, 2018

Fix boxcox_trans equations and docs (#135)
implements Modulus generalization, Closes #103
@statist7

This comment has been minimized.

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