How strongly do two numeric variables move together — from −1 to +1?
Your browser does not support embedded video. Download the video (MP4).
:::
Everything in the video, ready to copy:
# Correlation - Pearson vs Spearman # Built-in mtcars: weight vs fuel efficiency cor(mtcars$wt, mtcars$mpg) # Pearson correlation with a test and 95% CI cor.test(mtcars$wt, mtcars$mpg) # Spearman - rank based, for non-linear or non-normal data cor.test(mtcars$wt, mtcars$mpg, method = "spearman") # See the relationship plot(mtcars$wt, mtcars$mpg, pch = 19, col = "#17a2b8", xlab = "Weight", ylab = "MPG")
Download this R script · ▶ Practice in the playground
When to use it. Use Pearson for a linear relationship between roughly normal variables; switch to Spearman (ranks) for non-linear or non-normal data, or when outliers are present. Always plot the scatter first.
Try the correlation calculator · read Pearson vs Spearman.
Next: Chi-square & Fisher’s Test →