I got the information on slide 3 and the equations from this article: https://www.datacamp.com/tutorial/simple-linear-regression. The R code and plots are my own work.
2025-03-16
I got the information on slide 3 and the equations from this article: https://www.datacamp.com/tutorial/simple-linear-regression. The R code and plots are my own work.
\(y = b_0 + b_1 * x_1\)
\(a = r * \frac{sy}{sx}\)
\(i = \bar y - r * \frac{sy}{sx} * \bar x\)
Uses the Iris dataset:
mod = lm(iris$Petal.Length~iris$Petal.Width)
fig = plot_ly(x = iris$Petal.Width, y = iris$Petal.Length,
type = "scatter",
mode = "markers", name = "data") %>%
add_lines(x = iris$Petal.Width, y = fitted(mod),
name = "fitted") %>%
layout(xaxis = list(title = "Petal Width"),
yaxis = list(title = "Petal Length"))
config(fig, displaylogo = F)
Uses the Trees dataset:
mod = lm(trees$Volume~trees$Girth)
fig = plot_ly(x = trees$Girth, y = trees$Volume,
type = "scatter",
mode = "markers", name = "data") %>%
add_lines(x = trees$Girth, y = fitted(mod),
name = "fitted") %>%
layout(xaxis = list(title = "Girth"),
yaxis = list(title = "Volume"))
config(fig, displaylogo = F)
Uses the Iris dataset:
g = ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + geom_point()
g + geom_smooth(method = 'lm', se = F)
`geom_smooth()` using formula = 'y ~ x'