-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path.Rhistory
44 lines (44 loc) · 1.01 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
knitr::opts_chunk$set(echo = TRUE)
library(broom)
library(tidyverse)
library(knitr)
# take a glimpse of the data
glimpse(mtcars)
model1 <- lm(mpg~wt, data = mtcars)
summary(model1)
# take a glance of the model fitting
glance(model1)
# take a glance of the model fitted values and stats
augment(model1) %>%
head()
# Print the coefficients
kable2 <- function(data){
knitr::kable(mutate_if(data, is_numeric, round, 2))
}
tidy(model1) %>%
kable2()
fits <- list(
fit1 <- lm(hp ~ cyl, data = mtcars),
fit2 <- lm(hp ~ cyl + mpg, data = mtcars),
fit3 <- lm(hp ~ ., data = mtcars)
)
gof <- purrr::map_df(fits, glance, .id = "model") %>%
arrange(AIC)
gof
fit <- lm(hp~., data = mtcars)
au <- broom::augment(fit)
au %>%
head()
fit <- lm(hp~., data = mtcars)
au <- broom::augment(fit)
au %>%
head()
p <- au %>%
gather(x, val, -contains(".")) %>%
ggplot(aes(x = val, y = .fitted)) +
geom_point() +
facet_wrap(~x, scales = "free") +
labs(x = "Predictpr values", y = "Residuals") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank())
p