library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6 ✔ purrr 0.3.4
✔ tibble 3.1.8 ✔ dplyr 1.0.10
✔ tidyr 1.2.1 ✔ stringr 1.4.1
✔ readr 2.1.2 ✔ forcats 0.5.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
library(broom)
= lm(mpg ~ wt, data = mtcars)
model |> tidy() model
# A tibble: 2 × 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 37.3 1.88 19.9 8.24e-19
2 wt -5.34 0.559 -9.56 1.29e-10
|> glance() model
# A tibble: 1 × 12
r.squared adj.r.squa…¹ sigma stati…² p.value df logLik AIC BIC devia…³
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0.753 0.745 3.05 91.4 1.29e-10 1 -80.0 166. 170. 278.
# … with 2 more variables: df.residual <int>, nobs <int>, and abbreviated
# variable names ¹adj.r.squared, ²statistic, ³deviance
|> augment() model
# A tibble: 32 × 9
.rownames mpg wt .fitted .resid .hat .sigma .cooksd .std.r…¹
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Mazda RX4 21 2.62 23.3 -2.28 0.0433 3.07 0.0133 -0.766
2 Mazda RX4 Wag 21 2.88 21.9 -0.920 0.0352 3.09 0.00172 -0.307
3 Datsun 710 22.8 2.32 24.9 -2.09 0.0584 3.07 0.0154 -0.706
4 Hornet 4 Drive 21.4 3.22 20.1 1.30 0.0313 3.09 0.00302 0.433
5 Hornet Sportabout 18.7 3.44 18.9 -0.200 0.0329 3.10 0.0000760 -0.0668
6 Valiant 18.1 3.46 18.8 -0.693 0.0332 3.10 0.000921 -0.231
7 Duster 360 14.3 3.57 18.2 -3.91 0.0354 3.01 0.0313 -1.31
8 Merc 240D 24.4 3.19 20.2 4.16 0.0313 3.00 0.0311 1.39
9 Merc 230 22.8 3.15 20.5 2.35 0.0314 3.07 0.00996 0.784
10 Merc 280 19.2 3.44 18.9 0.300 0.0329 3.10 0.000171 0.100
# … with 22 more rows, and abbreviated variable name ¹.std.resid