7.1 Linear Regression Model

Model: yt=β0+β1xt+ϵt

β0 is the intercept β1 is the slope

library(tidyverse)
library(fpp3)
set.seed(123)

# Generate x values
x <- seq(0, 5, length.out = 100)
# Generate y values with a positive linear slope
# y <- 2*x + rnorm(100, mean = 5, sd = 8)
y <-  2*x + 3*x^2 + rnorm(100, mean = 0, sd = 20)

df <- tibble(x,y)


df %>%
  ggplot(aes(x,y))+
  geom_point()+
  geom_smooth(method="lm")
## `geom_smooth()` using formula = 'y ~ x'