8 Correlation between Two Continuous Variables
To quantify the relationship between two continuous variables, the most common method is to use a Pearson correlation coefficient (denoted with the letter \(r\)). The pearson correlation takes the covariance between a continuous independent (\(X\)) and dependent (\(Y\)) variable and standardizes it by the standard deviations of \(X\) and \(Y\),
\[ r = \frac{\text{Cov}(X,Y)}{S_{X} S_{Y}}. \]
We can visualize what a correlation between two variables looks like with scatter plots. Figure 8.1 shows scatter plots with differing levels of correlation.
The standard error of the Pearson correlation coefficient is,
\[ SE_r = \sqrt{\frac{\left(1-r^2\right)^2}{n-1}} \]
Unlike Cohen’s \(d\) and other effect size measures, The correlation coefficient is bounded by -1 and positive 1, with positive 1 being a perfectly positive correlation, -1 being a perfectly negative correlation, and zero indicating no correlation between the two variables. The bounding has the consequence of making the confidence interval asymmetric around \(r\) (e.g., if the correlation is positive, the lower bound is farther away from \(r\) than the upper bound is). It is important to note that with a correlation of zero, the confidence interval is symmetric and approximately normal. Instead, to obtain the confidence intervals of \(r\), we first need to apply a Fisher’s Z transformation. A Fisher’s Z transformation is a hyperbolic arctangent transformation of a Pearson correlation coefficient and can be computed as,
\[ Z_r = \text{arctanh}(r) \]
The Fisher Z transformation ensures \(Z_r\) has a symmetric and approximately normal sampling distribution. This then allows us to calculate the confidence interval from the standard error of \(Z_r\) (\(SE_{Z_r} = \frac{1}{\sqrt{n-3}}\)). We can also back-transform the confidence into a Pearson correlation scale,
\[ CI_{r} = \text{tanh}(Z_r \pm 1.96\times SE_{Z_r}) \]
We can then back-transform the upper bound and lower bound into the upper and lower bound of \(r\) by taking the hyperbolic tangent (the inverse of the arctangent).
In R, the full process of obtaining confidence intervals can be done quite easily. Note if you have raw data for \(X\) and \(Y\), then you can compute the correlation with base R, cor(X,Y)
.
# example: r = .50, n = 50
<- .50
r <- 50
n
# compute Zr
<- atanh(r)
Zr
# calculate standard error of Zr
<- 1/sqrt(n-3)
SE_Zr
# compute confidence interval of Zr
<- Zr - 1.96 * SE_Zr
Zlow <- Zr + 1.96 * SE_Zr
Zhigh
# backtransform CI of Z to CI of Pearson correlation
<- tanh(Zlow)
rlow <- tanh(Zhigh)
rhigh
# print pearson correlation and confidence intervals
data.frame(r = MOTE::apa(r),
rlow = MOTE::apa(rlow),
rhigh = MOTE::apa(rhigh))
r rlow rhigh
1 0.500 0.257 0.683
The output shows that the correlation and its confidence intervals are \(r\) = 0.50, 95% CI [0.26, 0.68].