library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.8
## ✓ tidyr 1.0.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 3.6.2
## Warning: package 'tibble' was built under R version 3.6.2
## Warning: package 'purrr' was built under R version 3.6.2
## Warning: package 'dplyr' was built under R version 3.6.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
mtcars %>% skimr::skim() %>%
data.frame() %>%
filter(stat == "sd") ->
skimmed
# mtcars %>%
# lm(mpg ~ cyl + disp + hp, data = .) %>%
# broom::tidy() %>%
# rename(variable = term) %>%
# left_join(skimmed) %>%
# mutate(estimate_sd = estimate * value) %>%
# ggplot() +
# aes(y = term, x = estimate_sd) +
# geom_point() +
# geom_vline(xintercept = 0, linetype = "dashed")
mtcars %>%
select(mpg, cyl, hp, disp) %>%
remove_missing() %>%
mutate(mpg_sd = mpg/sd(mpg)) %>%
mutate(cyl_sd = cyl/sd(cyl)) %>%
mutate(disp_sd = disp/sd(disp)) %>%
mutate(hp_sd = hp/sd(hp)) %>%
lm(mpg_sd ~ cyl_sd + disp_sd + hp_sd, data = .) ->
m1
confint(m1) %>%
as_tibble() ->
confint
m1 %>%
broom::tidy() %>%
bind_cols(confint(m1) %>% as_tibble()) %>%
slice(-1) %>%
ggplot() +
aes(y = term, x = estimate) +
geom_point() +
geom_segment(aes(x = `2.5 %`, xend = `97.5 %`, yend = term)) +
geom_vline(xintercept = 0, linetype = "dashed")