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

bug in winsorized Pearson's correlation #151

Closed
IndrajeetPatil opened this issue Mar 19, 2021 · 2 comments
Closed

bug in winsorized Pearson's correlation #151

IndrajeetPatil opened this issue Mar 19, 2021 · 2 comments
Labels
bug 🐛 Something isn't working

Comments

@IndrajeetPatil
Copy link
Member

There are two issues here:

  • the correlation coefficient should be the same across these two contexts, but they are not
  • setting p_adjust = "none" doesn't do anything
library(WRS2)
library(tidyverse)
library(correlation)

correlation(select(msleep, bodywt, sleep_rem), winsorize = 0.2)
#> # Correlation table (pearson-method)
#> 
#> Parameter1 | Parameter2 |     r |         95% CI | t(59) |       p
#> ------------------------------------------------------------------
#> bodywt     |  sleep_rem | -0.37 | [-0.57, -0.14] | -3.10 | 0.003**
#> 
#> p-value adjustment method: Holm (1979)
#> Observations: 61

correlation(keep(.x = msleep, .p = is_bare_numeric), winsorize = 0.2, p_adjust = "none") %>%
  filter(Parameter1 == "sleep_rem", Parameter2 == "bodywt")
#> # Correlation table (pearson-method)
#> 
#> Parameter1 | Parameter2 |     r |        95% CI | t(28) |     p
#> ---------------------------------------------------------------
#> sleep_rem  |     bodywt | -0.35 | [-0.63, 0.01] | -1.97 | 0.059
#> 
#> p-value adjustment method: none
#> Observations: 30

Created on 2021-03-19 by the reprex package (v1.0.0)

@IndrajeetPatil
Copy link
Member Author

IndrajeetPatil commented Mar 19, 2021

Hmm, seems to be due to how NA's are being omitted. The number of observations for the first test is 61, while 30 for the second one.

data <- stats::na.omit(data)

@IndrajeetPatil
Copy link
Member Author

With the PR:

library(WRS2)
library(tidyverse)
library(correlation)

correlation(select(msleep, bodywt, sleep_rem), winsorize = 0.2)
#> # Correlation Matrix (pearson-method)
#> 
#> Parameter1 | Parameter2 |     r |         95% CI | t(59) |       p
#> ------------------------------------------------------------------
#> bodywt     |  sleep_rem | -0.37 | [-0.57, -0.14] | -3.10 | < .01**
#> 
#> p-value adjustment method: Holm (1979)
#> Observations: 61

correlation(keep(.x = msleep, .p = is_bare_numeric), winsorize = 0.2, p_adjust = "none") %>%
  filter(Parameter1 == "sleep_rem", Parameter2 == "bodywt")
#> # Correlation Matrix (pearson-method)
#> 
#> Parameter1 | Parameter2 |     r |         95% CI | t(59) |       p
#> ------------------------------------------------------------------
#> sleep_rem  |     bodywt | -0.37 | [-0.57, -0.14] | -3.10 | < .01**
#> 
#> p-value adjustment method: none
#> Observations: 61

Created on 2021-03-19 by the reprex package (v1.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant