# Lecture 19: Correlation

## Statistics / Biostatistics

---

## Learning Objectives

By the end of this lecture, students will be able to:

1. Define correlation and distinguish it from causation
2. Calculate and interpret the Pearson correlation coefficient (r)
3. Describe the properties and limitations of Pearson's r
4. Apply Spearman's rank correlation for non-normal or ordinal data
5. Test the significance of a correlation coefficient

---

## Lecture Content

### I. The Concept of Correlation

**Correlation** measures the strength and direction of the linear association between two quantitative variables. A positive correlation means that as one variable increases, the other tends to increase as well. A negative correlation means that as one variable increases, the other tends to decrease. A zero correlation indicates no linear relationship. It is essential to remember that correlation does NOT imply causation. Confounding, reverse causation, and coincidence can all produce correlations. The classic example is that ice cream sales and drowning deaths are correlated, but only because both are driven by hot weather.

### II. Pearson Correlation Coefficient (r)

The Pearson correlation coefficient is a unitless measure of linear association between two continuous variables X and Y. Its formula is r = [sum of (x_i - x-bar)(y_i - y-bar)] / [sqrt(sum of (x_i - x-bar)^2) * sqrt(sum of (y_i - y-bar)^2)], or equivalently r = S_xy / (S_x * S_y), where S_xy is the sample covariance.

Pearson's r has several important properties. It ranges from -1 to +1, where r = +1 indicates a perfect positive linear relationship, r = -1 indicates a perfect negative linear relationship, and r = 0 indicates no linear relationship (though a nonlinear relationship could still exist). The correlation is symmetric, meaning corr(X, Y) = corr(Y, X), and it is unitless, so it is not affected by changes in scale or units. Cohen's guidelines for interpretation suggest that |r| between 0.1 and 0.3 represents a small (weak) correlation, between 0.3 and 0.5 represents a medium (moderate) correlation, and between 0.5 and 1.0 represents a large (strong) correlation.

<image>A six-panel scatterplot grid. Each panel shows a different correlation value with the corresponding scatterplot. Panel A: r = +1.0 (perfect positive, points on a line). Panel B: r = +0.7 (strong positive, tight elliptical cloud). Panel C: r = +0.3 (weak positive, diffuse cloud). Panel D: r = 0.0 (no correlation, circular cloud). Panel E: r = -0.7 (strong negative). Panel F: r = 0.0 but with a clear U-shaped nonlinear pattern, demonstrating that r = 0 does not mean "no relationship." Each panel is labeled with its r value.</image>

### III. Coefficient of Determination (r-squared)

The value r^2 represents the proportion of variance in Y explained by the linear relationship with X. It ranges from 0 to 1. For example, if r = 0.70, then r^2 = 0.49, meaning 49% of the variability in Y is explained by X, with the remaining 51% unexplained (due to other factors, random variation, or nonlinear relationships). The coefficient of determination is more directly interpretable than r in terms of practical importance.

### IV. Assumptions for Pearson's r

For Pearson's r to be valid, both variables should be continuous and measured on interval or ratio scales. The relationship between X and Y should be approximately linear. For inference and hypothesis testing, data should come from a bivariate normal distribution. There should be no significant outliers, as these can dramatically inflate or deflate r. Observations must be independent.

It is crucial to always examine a scatterplot before computing r. A scatterplot reveals whether the relationship is linear, whether outliers are present, and whether heteroscedasticity exists. A strong nonlinear relationship may yield an r value near 0, which would be misleading without visual inspection.

### V. Hypothesis Test for Correlation

The hypothesis test for correlation uses H0: rho = 0 (no linear correlation in the population) versus H1: rho does not equal 0. The test statistic is t = r * sqrt(n - 2) / sqrt(1 - r^2), with df = n - 2.

As an example, with r = 0.45 and n = 30, the test statistic is t = 0.45 * sqrt(28) / sqrt(1 - 0.2025) = 0.45 * 5.292 / 0.893 = 2.667. With df = 28, the p-value is approximately 0.013 (two-sided), so we reject H0 and conclude the correlation is statistically significant. A confidence interval for rho can be constructed using Fisher's z-transformation: z_r = 0.5 * ln[(1+r)/(1-r)], with SE(z_r) = 1/sqrt(n-3). The CI is constructed for z_r and then back-transformed to obtain a CI for rho.

### VI. Spearman's Rank Correlation (r_s)

Spearman's rank correlation is a nonparametric alternative to Pearson's r that is based on ranks rather than raw values. The procedure involves ranking both variables independently and then computing Pearson's r on the ranks. It should be used when one or both variables are ordinal, when the relationship is monotonic but not necessarily linear, or when data are not normally distributed or contain outliers. The shortcut formula (when there are no ties) is r_s = 1 - [6 * sum(d_i^2)] / [n(n^2 - 1)], where d_i is the difference between ranks of x_i and y_i. Spearman's r_s is interpreted similarly to Pearson's r but measures monotonic rather than strictly linear association.

<image>A two-panel comparison. Panel A: A scatterplot of two variables with a clear linear relationship; both Pearson r and Spearman r_s are shown and are similar (e.g., r = 0.82, r_s = 0.80). Panel B: A scatterplot with a monotonic but nonlinear (exponential-like) relationship; Pearson r is modest (e.g., r = 0.65) while Spearman r_s is much higher (e.g., r_s = 0.90), demonstrating Spearman's advantage for nonlinear monotonic relationships. Each panel includes the fitted linear line (for Pearson) and a monotonic curve.</image>

### VII. Other Correlation Measures

The **point-biserial correlation** measures the correlation between a binary variable and a continuous variable and is mathematically equivalent to Pearson's r when one variable is coded 0/1. **Kendall's tau (tau_b)** is another rank-based correlation measure that is more robust than Spearman's r_s for small samples with many ties, though its values tend to be smaller in magnitude. The **intraclass correlation coefficient (ICC)** measures agreement between raters or repeated measurements and is used in reliability studies, where values closer to 1 indicate high agreement or reliability.

### VIII. Common Pitfalls

Several pitfalls can lead to misinterpretation of correlations. The **ecological fallacy** occurs when correlations computed on group-level data (such as country averages) are assumed to apply to individuals. **Restriction of range** means that if the sample is restricted to a narrow range of X, the observed r will underestimate the true correlation. **Outlier influence** is important because a single extreme point can create a spurious correlation or mask a real one -- always examine the scatterplot. Testing many pairs of variables simultaneously (**multiple correlations**) inflates the chance of finding a spurious significant correlation. **Nonlinearity** is a concern because Pearson's r captures only linear association. And above all, **correlation is not causation** -- a point worth repeating.

<image>A cautionary figure on correlation pitfalls. Panel A: A scatterplot showing no correlation among the main cluster of points but one extreme outlier that produces a misleadingly high r value (e.g., r = 0.75 with outlier vs. r = 0.05 without). Panel B: A scatterplot demonstrating restriction of range -- the full population shows a strong correlation, but a subgroup (highlighted) selected on a narrow range of X shows a near-zero correlation. Both panels show the r values with and without the pitfall for comparison.</image>

---
