- This presentation will explain:
- What simple linear regression is
- Methods of finding the function for a given dataset
- How to plot these functions to a dataset in R
- This presentation will utilize the publicly available trees dataset for all examples.
2023-10-15
1
cor(trees$Girth, trees$Volume)
girth.volume.lm <- lm(Volume ~ Girth, data = trees) summary(girth.volume.lm)
## `geom_smooth()` using formula = 'y ~ x'
ggplot(trees, aes(Girth,Volume), main = "Volume vs Girth in Trees") + geom_point() + stat_smooth(method = lm, col = "blue") + geom_abline(intercept = -38.92958, slope = 5.215771, col = "red")
#slope m = (nrow(trees) - sum(trees$Volume)*sum(trees$Volume))/((nrow(trees))^2 - (sum(trees$Girth))^2) #intercept b = (sum(trees$Volume) - (m*sum(trees$Girth)))/nrow(trees)