Correlation measures how strongly two continuous variables move together in a straight line. Neither variable is the “response”; both are just measured. The correlation coefficient r runs from −1 (perfect negative) through 0 (none) to +1 (perfect positive).
\(H_0: \rho = 0\) (no linear association) vs. \(H_A: \rho \neq 0\)
Version
Use when
R call
Pearson’s r
Both variables roughly normal, relationship linear
cor.test(x, y)
Spearman’s rho
Non-normal, outliers, or monotonic but curved
cor.test(x, y, method = "spearman")
Correlation is not causation, and r only detects linear patterns. Always plot first.
Booby data: how often a Nazca booby was visited by unrelated adults as a nestling, and how aggressive it was as an adult.
Step 2: Plot the relationship
booby_df %>%ggplot(aes(visits_as_nestling, future_aggression)) +geom_point(size =2) +labs(x ="Visits as a nestling", y ="Adult aggression score") +theme_bw()
Look for: a roughly straight trend, no strong curve, no single point driving the pattern.
Step 3: Check normality
Pearson’s test assumes both variables are (bivariate) normal.
shapiro.test(booby_df$visits_as_nestling)
Shapiro-Wilk normality test
data: booby_df$visits_as_nestling
W = 0.95783, p-value = 0.3965
shapiro.test(booby_df$future_aggression)
Shapiro-Wilk normality test
data: booby_df$future_aggression
W = 0.91575, p-value = 0.04709
Spearman's rank correlation rho
data: rope_df$years_since_seen and rope_df$impressiveness
S = 332.12, p-value = 2.571e-05
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.7843363
The warning about ties is expected with a 1–5 score; R uses an approximate p-value.
Step 6: Write it up
Adult aggression increased with the number of visits a booby received as a nestling (Pearson’s r = 0.53, t(22) = 2.96, p = 0.0072, n = 24).
Remembered impressiveness of the rope trick increased with years since it was seen (Spearman’s ρ = 0.78, p < 0.001, n = 21).
Report r (or ρ), the test statistic and df for Pearson, p, and n. Show the scatterplot.