blog/correlation-coefficient-and-correlation-test-in-r/ #56
Replies: 23 comments 23 replies
-
Comment written by YZurbuchen on October 21, 2020 08:03:49: Hi Antoine, Thanks a lot for your article. I would just have a short question regarding dichotomous variables. If I have a matrix consisting of continuous and dichotomous variables would it still be correct to use the cor.test function in order to subsequently visualise it as a correlation plot? I was unsure about how to handle it, according to this https://stats.stackexchange.com/questions/226157/p-value-for-point-biserial-correlation-in-r article it should automatically compute the point-biserial correlation and would therefore be correct? Thanks a lot for your help! |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on October 21, 2020 08:48:24: Dear YZurbuchen, Thanks for your question. I confirm that you can use It will produce the exact same results than computing the point-biserial correlation, as shown by the following example:
In the StackExchange thread you mentioned, the user Sal Mangiafico suggested (on April 9, 2018) to use the function So now the two functions Hope this helps. Regards, |
Beta Was this translation helpful? Give feedback.
-
Comment written by YZurbuchen on October 21, 2020 14:43:17: Thank you very much for your super quick answer, that's great! Best wishes, |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on October 21, 2020 14:44:40: You're welcome! |
Beta Was this translation helpful? Give feedback.
-
Comment written by madihah manggabarani on October 22, 2020 23:24:51: Dear Antoine, I really appreciate your article, it is easily to be understood and to follow the practice using R ! |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on October 23, 2020 05:11:57: Glad you find it useful Madihah! |
Beta Was this translation helpful? Give feedback.
-
Comment written by vijayarajamanickam on November 30, 2020 22:55:44: Dear Antoine, even after Could you please help me from that? |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on December 01, 2020 12:50:39: Hello, I just tried on my side with the following code:
and it works smoothly. So few things to make it work on your side:
Let me know if this does not fix your issue. Regards, |
Beta Was this translation helpful? Give feedback.
-
Comment written by vijayarajamanickam on December 02, 2020 15:26:04: Dear Antoine, Now it works fine. kind regards |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on December 02, 2020 15:59:28: You're welcome, glad it worked! |
Beta Was this translation helpful? Give feedback.
-
Hi Antoine; Just a simple question that if I have a continuous and three dichotomous variables, and in that case, do you know how to calculate/test their correlation? Cheers - Tao |
Beta Was this translation helpful? Give feedback.
-
Dear Tao, Assuming your three dichotomous variables are qualitative nominal variables, you cannot compute a correlation as defined in this post (even if your second variable is a quantitative continuous variable). Remember that a Pearson, Spearman or Kendall correlation can only be computed between quantitative or qualitative ordinal variables. What you can do:
Last but not least, it is true that there is a lesser known correlation (not covered in this post), referred as point-biserial correlation which can be used when one variable is dichotomous and the other is continuous. Similar to the Pearson, Spearman and Kendall correlations, this coefficient ranges between –1 and +1 and values close to ±1 indicate a strong positive/negative relationship, and values close to 0 indicate no relationship between the two variables. Hope that helps. Regards, |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing all that, I learned a lot from this post. I'll use some methods from package "correlation" in my master's thesis :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for your feedback Rafael, and good luck with your thesis! |
Beta Was this translation helpful? Give feedback.
-
Hi. When I did a combination of correlation, I get this error "Error in tetra.mat(x, y = y, correct = correct, smooth = smooth, global = global, : Tetrachoric correlations require dictomous data". Im pretty much new to this so I wonder what I can do about it. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hi Antonie, says: could be: I think the last 3 , actually would be one. right? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Dear Antoine, thank you so much for this I really learned a lot! May I ask: I inferred from your explanation that to read these scatterplots one reads from left to right or top-down which two variables are linked (that is my confusion and it is such a stupid question that I did not dare openly ask it :/)? |
Beta Was this translation helpful? Give feedback.
-
Hi Antoine, this article was very helpful as well as giving plenty of insights in understanding the main principles of R. However, I have a further question as part of Case Studies we are given we have to check for the correlation of two variables: yi and xi, with xi being the independent variable of which we assume that it is normal distributed. Now we are given an equation of the form yi=a+b*xi+ei, so the relation is clearly non-linear. In order to perform a correlation test can I rely on the one built-in by R? Or do I have to check for the distance correlation? I do know there is an expansion for computing such but would there also be a method to do it in basic R? Thank you so much in advance, Have a great evening, Luisa |
Beta Was this translation helpful? Give feedback.
-
Hello Antoine, Thanks for your blog. I am performing a multiple regression analysis and now I am assessing the correlation between the explanatory/independent variables. I have some continuous variables and a few binary variables as well, however my data does not follow a normal distribution. Which tests should I perform in order to evaluate the correlation to make sure they are independent from each other? |
Beta Was this translation helpful? Give feedback.
-
A question:
are there a lot of > .999 p-value? For example: |
Beta Was this translation helpful? Give feedback.
-
Dear Antoine, You can't image how much that your blog helps me with my research. My gratefulness is totally beyond words! Here there are a couple of questions that I don't understand well. Could you please help me with them? One of my projects is to calculate the correlation between a two-level nominal variable and two-level ordinal variable. I searched online and found someone used the chisq_test function in "coin" package, but I am not sure if it is a good choice. Besides, in your response to YZurbuchen that you confirmed that cor.test() can be used for one continuous and one dichotomous variable. However, in your response to Tao you specified that correlation can only be computed between quantitative or qualitative ordinal variables and you recommended a linear regression for the case of nominal and continuous variables. I am confused, as dichotomous variable is a two-level nominal variable. If I have a dependent nominal variable and an independent continuous variable, should I use the cor.test() or use linear regression to calculate the correlation between them? Looking forward to your response. Best, Yang |
Beta Was this translation helpful? Give feedback.
-
Hello Antoine, Thank you so much for this neat and informative article. May I please ask a question? I have two dataframes of which I want correlation matrix, but without calculating coefficient within the same dataframe. The rcorr function in the Hmis package just does all possible combinations, and then I cannot extract easily. Do you have any advice please? Thank you so much! |
Beta Was this translation helpful? Give feedback.
-
please help me how to calculate prediction in r if the variable is more than two? |
Beta Was this translation helpful? Give feedback.
-
Correlation coefficient and correlation test in R - Stats and R
Learn how to compute a correlation coefficient (Pearson and Spearman) and perform a correlation test in R
https://statsandr.com/blog/correlation-coefficient-and-correlation-test-in-r/
Beta Was this translation helpful? Give feedback.
All reactions