10.7 Impact of a predictor

insurance %>%
  rename(lag0=TVadverts)%>%
  mutate(lag1=lag(lag0),
         lag2=lag(lag0,2))%>%
  pivot_longer(cols = c("lag0","lag1","lag2"),
               names_to = "lags",values_to="TVadverts")%>%
  ggplot(aes(x=TVadverts,y=Quotes,group=lags)) +
  geom_point()+
  geom_smooth()+
  facet_wrap(vars(lags))