Skip to content

Instantly share code, notes, and snippets.

@lundquist-ecology-lab
Created December 27, 2022 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lundquist-ecology-lab/e83d4deec4dfd90404cc409f83c14eba to your computer and use it in GitHub Desktop.
Save lundquist-ecology-lab/e83d4deec4dfd90404cc409f83c14eba to your computer and use it in GitHub Desktop.
Correlation and regression in R with examples
library(palmerpenguins)
data(penguins)
penguins <- na.omit(penguins)
# Correlation
cor.test(penguins$bill_length_mm, penguins$bill_depth_mm)
# Regression (linear model)
model_1 <- lm(bill_length_mm ~ bill_depth_mm, data = penguins)
summary(model_1)
plot(bill_length_mm ~ bill_depth_mm, data = penguins)
abline(model_1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment