Skip to main content

Section 7.5 Running Correlations (r)

Since the cat is out of the bag, it is now time for us to officially run some correlations.
The end result of running a correlation is to get the correlation coefficient (r), which is a number between -1 and 1. There are two things we look for in a correlation coefficient:
  • Direction: this is denoted by whether the coefficient is negative or positive. A negative number does not mean it is bad, and a positive number does not mean it is good. It is simply saying that if it is:
    • Negative- then when one variable increases, the other decreases (Anxiety vs Exam)
    • Positive- when one variable increases, the other also increases (Studying vs Exam)
  • Strength: this is how close to -1 or 1 it is. The closer to -1 or 1, the stronger the correlation between the two variables. The inverse is also true: the closer to 0 the number is, the weaker the correlation is.
By definition, the correlation coefficient measures the strength and direction of a linear relationship between two variables.
We can use the following general guidelines for interpreting correlation strength. However, different disciplines may have different guidelines.
Absolute value of r	     Strength of relationship
r < 0.25	             No relationship
0.25 < r < 0.5	         Weak relationship
0.5 < r < 0.75	         Moderate relationship
r > 0.75	             Strong relationship
Now that we understand what the correlation coefficient (r) represents, let’s calculate it! We can use the cor command for this.
cor(examData$studying_hours, examData$exam_score)     # Study time vs performance

cor(examData$anxiety_score, examData$exam_score)    # Anxiety vs performance

cor(examData$studying_hours, examData$anxiety_score)  # Study time vs anxiety
[1] 0.3900419
[1] -0.4449023
[1] -0.7122237
Success! We have three different correlation coefficients. Let us look at all three:
  1. A positive, somewhat weak correlation
  2. A negative, somewhat weak correlation
  3. A negative, somewhat strong correlation
Now, we can also utilize the cor.test command, which not only will give us the correlation coefficient, but also the p-value, so we can identify if the correlation is statistically significant or not.
cor.test(examData$studying_hours, examData$exam_score)     # Study time vs performance

cor.test(examData$anxiety_score, examData$exam_score)    # Anxiety vs performance

cor.test(examData$studying_hours, examData$anxiety_score)  # Study time vs anxiety
Pearson's product-moment correlation

data:  examData$studying_hours and examData$exam_score
t = 4.1933, df = 98, p-value = 6.034e-05
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.2096883 0.5447277
sample estimates:
      cor 
0.3900419 


	Pearson's product-moment correlation

data:  examData$anxiety_score and examData$exam_score
t = -4.9178, df = 98, p-value = 3.524e-06
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.5897813 -0.2722777
sample estimates:
       cor 
-0.4449023 


	Pearson's product-moment correlation

data:  examData$studying_hours and examData$anxiety_score
t = -10.044, df = 98, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.7971286 -0.5996997
sample estimates:
       cor 
-0.7122237
Turns out all three are statistically significant! There’s something just as important as the r value and p value: the method used to calculate it. By default cor and cor.test use Pearson’s method. Going back to visualizing our data, we can only use Pearson’s method if our data is linear.

Running one by one can take a lot of time..

What if we do not want to run all the correlations one by one...