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

Issue with ranktransform for correlations #87

Closed
DominiqueMakowski opened this issue Jun 23, 2020 · 5 comments
Closed

Issue with ranktransform for correlations #87

DominiqueMakowski opened this issue Jun 23, 2020 · 5 comments

Comments

@DominiqueMakowski
Copy link
Member

in your R package 'correlation' the function 'cor_test' uses the following procedure to rank-transform the data if both the 'bayesian' and the 'robust' arguments are set to TRUE.

effectsize::ranktransform(data[c(x,
y)], sign = TRUE, method = "average")

I am not sure whether you intended to use signed ranks. Using signed ranks, original values are rank-transformed in ascending order and signs are preserved. For instance, a vector with values -10, -8, -5, -1 and 3 is rank-transformed to -1 -2 -3 -4 5.

effectsize::ranktransform(c(-10, -8, -5, -1, 3), sign = TRUE)
[1] -1 -2 -3 -4 5

In my calculations I found that, due to this signed rank-transformation, the robust bayesian estimate differed considerably from the spearman coefficient (which is based on unsigned ranks). This may also result in flipped correlations. Maybe you want to have a look at the ranktransform code snippet in the cor_test function.


Should we address it here or in correlation? 🤔

@mattansb
Copy link
Member

I would expect ranktransform(sign = TRUE) to behave this way - the problem is that correlation sets sign = TRUE where it would be sign = FALSE as suggested.

(I don't know any correlation that uses a signed rank variable... maybe some weird point biserial something?)

(why was that happening? It does seem like a mistake to me too...)

@DominiqueMakowski
Copy link
Member Author

DominiqueMakowski commented Jun 23, 2020

I'm not sure, indeed an error, I'll set signed to False (additionally I misread the email so I thought there was something wrong with the computation itself)

@mattansb
Copy link
Member

Oh, I see, it is a double issue:

  1. correlation should use sign = FALSE
  2. ranktransform(sign = TRUE) does not return the signed ranks!
x <- c(-1,2,-3,4)

effectsize::ranktransform(x, sign = TRUE)
#> [1] -2  3 -1  4

# should be:
abs(x) * sign(x)
#> [1] -1  2 -3  4

Created on 2020-06-23 by the reprex package (v0.3.0)

@mattansb mattansb reopened this Jun 23, 2020
@DominiqueMakowski
Copy link
Member Author

🙉

@mattansb
Copy link
Member

Fixing (:

mattansb added a commit that referenced this issue Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants