Browse Source

Cours regression + code

master
Maxime Wack 6 years ago
parent
commit
ce41603844
2 changed files with 29 additions and 0 deletions
  1. BIN
      02_Regression/cours.odp
  2. +29
    -0
      02_Regression/lm.R

BIN
02_Regression/cours.odp View File


+ 29
- 0
02_Regression/lm.R View File

@@ -0,0 +1,29 @@
library(tidyverse)
library(broom)

data(iris)

fit <- lm(Sepal.Length ~ Petal.Length, data = iris)

fit

fit %>% summary

fit %>% glance

fit %>% tidy

fit %>% augment

fit %>% plot

tibble(Petal.Length = 1:7,
Sepal.Length = predict(fit, tibble(Petal.Length = Petal.Length))) -> pred

iris %>%
ggplot() +
aes(x = Petal.Length, y = Sepal.Length) +
geom_point() +
# geom_abline(intercept = fit %>% tidy %>% filter(term == "(Intercept)") %>% pull(estimate),
# slope = fit %>% tidy %>% filter(term == "Petal.Length") %>% pull(estimate)) +
geom_point(data = pred, aes(x = Petal.Length, y = Sepal.Length), color = "red")

Loading…
Cancel
Save