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

ggally_cor: argument "use" is meaningless #484

Open
alvinwmtan opened this issue Jan 5, 2024 · 0 comments
Open

ggally_cor: argument "use" is meaningless #484

alvinwmtan opened this issue Jan 5, 2024 · 0 comments

Comments

@alvinwmtan
Copy link

In ggally_cor(), one of the arguments is use, which ostensibly affects how NAs are handled by passing the argument to cor. However, cor is not in fact used for the calculation of the correlation; instead, cor.test is used, which crucially does not have an argument called use.

https://github.com/ggobi/ggally/blob/3918c50808458dec0c1dfb17fcdc846e9bda80f3/R/gg-plots.R#L354C21-L354C21

test_df <- data.frame(a = c(0, 1, 0, 1, 1, NA),
                      b = c(0, 1, 0, 1, NA, 1),
                      c = c(0, 1, 0, 1, 0, 0))
# these two are exactly the same...
ggpairs(test_df, upper = list(continuous = wrap(ggally_cor, use = "complete.obs")))
ggpairs(test_df, upper = list(continuous = wrap(ggally_cor, use = "pairwise.complete.obs")))
# ...even though these two are not
cor(test_df, use = "complete.obs")
cor(test_df, use = "pairwise.complete.obs")

Two additional notes:

  • Because of how cor.test is called, the function actually only receives the two vectors for which the correlation is calculated. Hence, use is somewhat superfluous, because the only possible way to handle NAs is to exclude any incomplete observations for those two vectors. cor.test has no information about NAs in other variables, which would be needed in order to exclude observations that have NAs elsewhere (for "complete.obs").
  • The documentation should also be changed to reflect the use of cor.test instead of cor.
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

1 participant