easystats / effectsize

:dragon: Compute and work with indices of effect size and standardized parameters
https://easystats.github.io/effectsize/
Other
337 stars 23 forks source link

Issue with ranktransform for correlations #87

Closed DominiqueMakowski closed 4 years ago

DominiqueMakowski commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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)

DominiqueMakowski commented 4 years ago

🙉

mattansb commented 4 years ago

Fixing (: