# ============================================================ # Correlation: Pearson & Spearman # Biostatistics in R — Rverse Analytics # https://rverseanalytics.com/learn-biostatistics/correlation # ============================================================ # 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")