laresbernardo / lares

Analytics & Machine Learning R Sidekick
https://laresbernardo.github.io/lares/
233 stars 49 forks source link

different p-values for correlations #34

Closed michellekee closed 3 years ago

michellekee commented 3 years ago

Hi, I'm new and happened to chance upon your package. :)

I love the corr_var function, but realised that it gives me different p-values.

A <- tibble(x=1:4,y=c(0,1,2,7),z=c(5,9,7,3))
corr_var(A,x, plot =F, type = "spearman")

variables corr pvalue 2 y 0.9135 1 3 z -0.4000 1

cor.test(A$x, A$z, method = "spearman", exact = F)

Spearman's rank correlation rho

data: A$x and A$z S = 14, p-value = 0.6 alternative hypothesis: true rho is not equal to 0 sample estimates: rho -0.4

Could you please kindly advise? Thank you so much!

laresbernardo commented 3 years ago

Hi @michellekee The code was passing a matrix with 1s when pvalues parameter was not set. I've explicitly added the pvalues parameter to corr_var now, which is TRUE by default, ignored when plot = TRUE. Thanks for reporting this and let me know if that works out for you. Note: you can now also pass the exact parameter from cor.test to corr_var() in case you'd need to.

michellekee commented 3 years ago

Thank you very much! This works perfectly! :)