20  Correlation

NoteWhat you’ll be able to do

By the end of this chapter you will be able to:

  1. Run and read Pearson correlation output, and report it correctly.
  2. Compute and interpret r² (the coefficient of determination) — and not confuse it with r.
  3. Choose between Pearson and Spearman, and identify when correlation isn’t appropriate at all.
  4. Explain why correlation does not establish causation — and what can.

Students who study more tend to score higher on the exam — but how strong is that tendency? Is it a tight rule, where every extra hour reliably pays off, or a loose drift that any individual student might buck entirely? Correlation compresses that question into a single number between −1 and +1.

A correlation measures the strength and direction of the relationship between two variables. It is the simplest way to quantify how two continuous measurements move together, and it’s the conceptual ancestor of simple regression (Chapter 22).

20.1 What a correlation is

The correlation coefficient — denoted \(r\) — ranges from \(-1\) to \(+1\):

  • \(r = +1\) — perfect positive relationship. As one variable increases, the other increases proportionally.
  • \(r = -1\) — perfect negative relationship. As one increases, the other decreases proportionally.
  • \(r = 0\) — no linear relationship.

The sign tells you the direction; the magnitude tells you the strength.

20.2 Types of correlation

  • Positive correlation — both variables move in the same direction. Example: hours studied and exam scores.
  • Negative correlation — variables move in opposite directions. Example: exercise time and weight.
  • No correlation — no consistent pattern. Example: shoe size and IQ.

20.3 Interpreting the coefficient

Value of \(r\) Strength Direction
+0.8 to +1.0 Strong Positive
+0.5 to +0.8 Moderate Positive
+0.2 to +0.5 Weak Positive
-0.2 to +0.2 None or very weak —
-0.2 to -0.5 Weak Negative
-0.5 to -0.8 Moderate Negative
-0.8 to -1.0 Strong Negative

These thresholds are rough conventions. In high-noise behavioral data, \(r = 0.3\) can be a meaningful finding. In well-controlled physical sciences, the same \(r\) would be unimpressive.

20.4 The Pearson correlation formula

\[ r = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum (x_i - \bar{x})^2 \cdot \sum (y_i - \bar{y})^2}} \]

Numerator: the sum of cross-products, which is the covariance between x and y before dividing by n − 1. Denominator: a normalization that puts the result on the \(-1\) to \(+1\) scale regardless of the variables’ original units.

R computes this for you.

20.5 When to use Pearson vs. Spearman

Use Pearson when Use Spearman when
Both variables are continuous Either variable is ordinal
Relationship looks roughly linear Relationship is monotonic but curved
Approximately normal Skewed or has outliers
No severe outliers Small samples

Default to Pearson if you have continuous, roughly-normal data. Default to Spearman if either of those fails.

TipTry It: Predict Before You Compute

Before calculating r, try the Rossman/Chance Analyzing Two Quantitative Variables applet.

Predict first: sketch what the scatterplot of your two variables should look like. Is the association positive or negative? Strong or weak? Then plot the real data and compute r — how close was your intuition?

20.6 R syntax

# Pearson (the default)
cor.test(data$x, data$y)

# Spearman (when assumptions are violated)
cor.test(data$x, data$y, method = "spearman")

cor.test() returns the correlation coefficient, a confidence interval, the test statistic, and a p-value testing whether the population correlation differs from zero.

20.6.1 Worked example

A teacher wants to know whether hours studied correlates with test score, for 25 students.

# Step 0: Load the data
data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch20_study_hours.csv")

# Step 1: Inspect
str(data)
summary(data[, c("hours", "score")])

# Step 2: Visualize first — always plot before computing
plot(data$hours, data$score, main = "Hours studied vs. score")
abline(lm(score ~ hours, data = data), col = "red")

# Or with ggplot
library(ggplot2)
ggplot(data, aes(x = hours, y = score)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE)

# Step 3: Check normality of both variables (for Pearson)
shapiro.test(data$hours)
shapiro.test(data$score)

# Step 4: Run Pearson correlation
cor.test(data$hours, data$score)

20.6.2 Reading the output


    Pearson's product-moment correlation

data:  data$hours and data$score
t = 8.4886, df = 23, p-value = 1.528e-08
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.7249052 0.9417881
sample estimates:
      cor 
0.8706529 
  • cor = 0.8706529 — the Pearson coefficient, r = .87. Strong positive correlation.
  • 95 percent confidence interval: 0.72 to 0.94 — plausible range for the population correlation.
  • t = 8.4886, df = 23, p-value = 1.528e-08 — significance test for whether the correlation differs from zero; report it as p < .001.

20.6.3 r²: the coefficient of determination

Square r to get the share of the variation in one variable that goes along with the other. Here r² = .87² = .76: hours studied accounts for about 76% of the variation in scores. “Accounts for” means the two move together, not that hours cause the scores. The common mistake is to skip the squaring and read r itself as a percentage.

NoteInterpret the Output

Read this output carefully. The R code that produced it is not shown.


    Pearson's product-moment correlation

data:  caffeine_mg and reaction_time
t = -4.5295, df = 43, p-value = 4.647e-05
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.7386487 -0.3298332
sample estimates:
       cor 
-0.5683418 
  1. What is the correlation coefficient? What does its sign tell you?
  2. How many participants are in this study? (Hint: df = n − 2.)
  3. Is the result statistically significant? What does that mean here?
  4. A classmate says “caffeine explains 56.8% of the variability in reaction time.” What is the error in this statement, and what is the correct value?
  5. Interpret the 95% confidence interval [−0.74, −0.33] in plain language.
  6. Write one APA 7 sentence reporting this result.
  7. Can you conclude that caffeine causes faster reaction times? What design feature would be needed to support that conclusion?

20.7 A complete numerical example

Just to make the formula concrete — five students’ hours studied (x) and test scores (y):

Hours (x) Score (y) \(x_i - \bar{x}\) \(y_i - \bar{y}\) Product
2 50 -4 -20 80
4 60 -2 -10 20
6 70 0 0 0
8 80 +2 +10 20
10 90 +4 +20 80

Means: \(\bar{x} = 6\), \(\bar{y} = 70\).

  • \(\sum (x_i - \bar{x})(y_i - \bar{y}) = 200\)
  • \(\sum (x_i - \bar{x})^2 = 40\)
  • \(\sum (y_i - \bar{y})^2 = 1000\)

\[ r = \frac{200}{\sqrt{40 \times 1000}} = \frac{200}{\sqrt{40000}} = \frac{200}{200} = 1.00 \]

Here \(r = 1.00\) exactly — a perfect positive correlation. That happens because these data were constructed to fall precisely on a straight line (\(y = 10x + 30\)); every point sits exactly on the trend. Real data essentially never give \(r = 1.00\). (You’d never compute this by hand in practice; cor() in R gives you the same answer in one line.)

20.8 Reporting

A Pearson correlation indicated that hours studied was strongly and positively related to exam score, r(23) = .87, 95% CI [.72, .94], p < .001. Both variables were approximately normal (Shapiro-Wilk p = .698 and .536).

Conventions:

  • Report r to two decimal places, p to three.
  • Italicize r and p.
  • Report the degrees of freedom (sample size minus 2) in parentheses after r.
  • Confidence interval in square brackets is standard APA.

For non-parametric — the same data run through cor.test(data$hours, data$score, method = "spearman"):

Spearman’s rank correlation indicated a strong positive monotonic relationship between hours studied and exam score, \(\rho\) = .86, p < .001.

(R warns that it “cannot compute exact p-value with ties” when some scores repeat; it uses an approximation instead, and the warning is safe to note and move past.)

ImportantCommon Misconception: correlation implies causation

Two variables can move together perfectly (r = 1.00) for reasons that have nothing to do with either causing the other — both might be driven by a third variable, or the association might be coincidental. Correlation is evidence of association, never of mechanism. Establishing causation requires experimental manipulation or a strong causal-inference design, not a stronger correlation.

TipMake the correlation misbehave

Open Correlation Trainer: What r Can and Cannot Tell You. First calibrate your eye by guessing r, then move one high-leverage observation, restrict the predictor range, and reveal a third variable. The same coefficient can change dramatically even when the substantive story you are tempted to tell has not earned causal support.

NoteA real case: chocolate and Nobel prizes

In 2012, the New England Journal of Medicine published a note reporting that a country’s per-capita chocolate consumption correlates with its number of Nobel laureates per 10 million people: r = .79, p < .0001, across 23 countries (Messerli, 2012). Run that through this chapter’s tools and it looks impressive — a strong correlation, r² ≈ .63 of the variance “explained.”

So does eating chocolate make a nation smarter? No. Wealthier countries both consume more chocolate and invest more in research and education — a textbook third variable. The author wrote the piece as a deliberate demonstration of how easily a real, statistically significant correlation can be over-interpreted. The twist: much of the press missed the joke and reported that chocolate boosts brainpower.

Two lessons. First, no value of r, however large or significant, can tell you why two variables move together. Second, “it was published in a top journal” is not the same as “the causal claim is true” — a research-consumer skill we return to in Chapter 29.

20.9 Key considerations

  1. Correlation is not causation. A correlation tells you two variables move together; it does not tell you that one causes the other. The classic example: ice-cream sales and drowning incidents are correlated, but neither causes the other — both are driven by hot weather.

  2. Visualize before computing. A correlation coefficient summarizes a relationship in a single number; that can hide enormous patterns. Two datasets can have identical correlations and look completely different.

  3. Outliers can dominate Pearson’s r. A single extreme point can produce a huge correlation in otherwise-noisy data, or hide a real correlation. Always plot first.

  4. Pearson assumes linearity. Non-linear relationships (U-shaped, exponential) can produce \(r \approx 0\) even when the variables are strongly related. Spearman picks up monotonic non-linearity; nothing simple picks up U-shapes — for those, use regression with polynomial terms.

  5. The relationship must be bivariate. Correlation is a two-variable concept. If you want to control for additional variables, you need partial correlation or regression.

WarningAnscombe’s quartet

Statistician Francis Anscombe constructed four datasets that all have identical means, SDs, correlations, and regression lines — but look completely different when plotted. One is linear; one is curved; one has an outlier; one has nearly all the variance in a single point. The point: numerical summaries alone are not enough. Always plot.

20.10 Common mistakes

Wrong Right
Computing r without plotting first Always plot first to confirm linearity
Using Pearson on heavily skewed or outlier-heavy data Switch to Spearman, or address the outliers
Reporting “correlation” without saying Pearson or Spearman Specify in the write-up
Inferring causation from correlation “Correlation is not causation” — be careful with language
Forgetting the degrees of freedom in the report r(df) = .xx

20.11 Quick reference

Element R code
Pearson correlation cor.test(x, y)
Spearman correlation cor.test(x, y, method = "spearman")
Kendall’s tau cor.test(x, y, method = "kendall")
Just the coefficient (no test) cor(x, y)
Correlation matrix for multiple variables cor(data[, c("v1", "v2", "v3")])
Visualize plot(x, y) or ggplot(data, aes(x, y)) + geom_point()
TipReporting checklist for correlation

20.12 The same test, different disciplines

Correlation applies wherever you want to describe the linear relationship between two continuous variables.

Discipline Typical relationship Variables
Psychology Two continuous psychological or behavioral measures Stress and sleep quality; anxiety and cognitive performance
Biology Two continuous physiological or ecological measures Body size and metabolic rate; temperature and enzyme activity
Sociology Two continuous social or economic indicators Poverty rate and educational attainment; income and life satisfaction

Next: chi-square, the test for relationships between categorical variables.


TipChapter Summary

Core idea: Correlation measures the strength and direction of a linear relationship between two continuous variables. It does not imply causation, and it will mislead you if you skip the scatterplot.

You should understand:

  • What Pearson’s r measures, what its range is (−1 to +1), and what r = 0 means
  • Why you must plot before computing r (Anscombe’s Quartet)
  • When to use Spearman’s \(\rho\) instead (non-normal data, outliers, ordinal variables)
  • The difference between statistical significance and practical importance of a correlation

You should be able to do in R:

  • Pearson: cor.test(x, y)
  • Spearman: cor.test(x, y, method = "spearman")
  • Visualize: plot(x, y) or ggplot(data, aes(x, y)) + geom_point()

Plain-language check: A study with n = 800 finds r = .09, p = .01. Is this a meaningful relationship? What two separate questions are you answering when you look at r and p?

The one mistake to avoid: Reporting a significant correlation as evidence of a causal relationship. Correlation and causation are not the same thing — ever. Use “was associated with” or “was related to,” not “caused” or “led to.”

Practice: You find that number of hours studied correlates with exam score at r(48) = .62, p < .001. A classmate says “studying causes better grades.” What is right and wrong about that interpretation?

Key terms from this chapter are defined in the Glossary.

NoteBaby Dataset Assignment

Practice the skills from this chapter using real data: Assignment 2 — Correlation and Simple Regression