Build models, then do tbl_regression and examine results. Do quick visual check against broom::tidy()
.
#
mod_lm <- lm(hp ~ am, data = mtcars)
tbl_regression(mod_lm)
Characteristic | Beta | 95% CI1 | p-value |
---|---|---|---|
am | -33 | -83, 16 | 0.2 |
1
CI = Confidence Interval
|
broom::tidy(mod_lm, conf.int = TRUE)
## # A tibble: 2 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 160. 15.5 10.3 2.12e-11 129. 192.
## 2 am -33.4 24.3 -1.37 1.80e- 1 -83.1 16.3
mod_survreg <- survreg(Surv(time, status) ~ age + ph.ecog, data = lung)
tbl_regression(mod_survreg)
Characteristic | Beta | 95% CI1 | p-value |
---|---|---|---|
age | -0.01 | -0.02, 0.01 | 0.3 |
ph.ecog | -0.33 | -0.49, -0.16 | <0.001 |
1
CI = Confidence Interval
|
broom::tidy(mod_survreg, conf.int = TRUE)
## # A tibble: 4 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 6.83 0.429 15.9 3.74e-57 5.99 7.67
## 2 age -0.00772 0.00688 -1.12 2.62e- 1 -0.0212 0.00576
## 3 ph.ecog -0.326 0.0858 -3.80 1.42e- 4 -0.495 -0.158
## 4 Log(scale) -0.304 0.0619 -4.90 9.48e- 7 NA NA
mod_logistic <- glm(response ~ age + stage, trial, family = binomial)
tbl_regression(mod_logistic, exponentiate = TRUE)
Characteristic | OR1 | 95% CI1 | p-value |
---|---|---|---|
Age, yrs | 1.02 | 1.00, 1.04 | 0.091 |
T Stage | |||
T1 | — | — | |
T2 | 0.58 | 0.24, 1.37 | 0.2 |
T3 | 0.94 | 0.39, 2.28 | 0.9 |
T4 | 0.79 | 0.33, 1.90 | 0.6 |
1
OR = Odds Ratio, CI = Confidence Interval
|
broom::tidy(mod_logistic, exponentiate = TRUE, conf.int = TRUE)
## # A tibble: 5 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 0.226 0.620 -2.40 0.0166 0.0645 0.742
## 2 age 1.02 0.0115 1.69 0.0909 0.997 1.04
## 3 stageT2 0.582 0.440 -1.23 0.219 0.242 1.37
## 4 stageT3 0.942 0.450 -0.132 0.895 0.386 2.28
## 5 stageT4 0.794 0.448 -0.516 0.606 0.325 1.90
mod_poisson <- glm(count ~ age + trt,
trial %>% dplyr::mutate(count = sample.int(20, size = nrow(trial), replace = TRUE)),
family = poisson
)
tbl_regression(mod_poisson, exponentiate = TRUE)
Characteristic | IRR1 | 95% CI1 | p-value |
---|---|---|---|
Age, yrs | 1.00 | 1.00, 1.00 | 0.5 |
Chemotherapy Treatment | |||
Drug A | — | — | |
Drug B | 0.91 | 0.83, 0.99 | 0.025 |
1
IRR = Incidence Rate Ratio, CI = Confidence Interval
|
broom::tidy(mod_poisson, exponentiate = TRUE, conf.int = TRUE)
## # A tibble: 3 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 12.1 0.0782 31.9 1.71e-223 10.4 14.1
## 2 age 0.999 0.00154 -0.730 4.66e- 1 0.996 1.00
## 3 trtDrug B 0.906 0.0440 -2.25 2.47e- 2 0.831 0.988
mod_lmer <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
tbl_regression(mod_lmer)
## Registered S3 methods overwritten by 'broom.mixed':
## method from
## augment.lme broom
## augment.merMod broom
## glance.lme broom
## glance.merMod broom
## glance.stanreg broom
## tidy.brmsfit broom
## tidy.gamlss broom
## tidy.lme broom
## tidy.merMod broom
## tidy.rjags broom
## tidy.stanfit broom
## tidy.stanreg broom
Characteristic | Beta | 95% CI1 | p-value |
---|---|---|---|
Days | 10 | 7.4, 13 | |
1
CI = Confidence Interval
|
broom.mixed::tidy(mod_lmer)
## # A tibble: 6 x 6
## effect group term estimate std.error statistic
## <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 fixed <NA> (Intercept) 251. 6.82 36.8
## 2 fixed <NA> Days 10.5 1.55 6.77
## 3 ran_pars Subject sd__(Intercept) 24.7 NA NA
## 4 ran_pars Subject sd__Days 5.92 NA NA
## 5 ran_pars Subject cor__(Intercept).Days 0.0656 NA NA
## 6 ran_pars Residual sd__Observation 25.6 NA NA
mod_glmer <- glmer(am ~ hp + factor(cyl) + (1 | gear), mtcars, family = binomial)
tbl_regression(mod_glmer, exponentiate = TRUE)
Characteristic | OR1 | 95% CI1 | p-value |
---|---|---|---|
hp | 1.00 | 0.94, 1.08 | >0.9 |
factor(cyl) | |||
4 | — | — | |
6 | 0.27 | 0.01, 12.1 | 0.5 |
8 | 0.12 | 0.00, 15727 | 0.7 |
1
OR = Odds Ratio, CI = Confidence Interval
|
broom.mixed::tidy(mod_glmer, exponentiate = TRUE, conf.int = TRUE)
## # A tibble: 5 x 9
## effect group term estimate std.error statistic p.value conf.low conf.high
## <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 fixed <NA> (Inter~ 1.85 8.27 0.138 0.890 2.93e-4 11704.
## 2 fixed <NA> hp 1.00 0.0357 0.0855 0.932 9.36e-1 1.08
## 3 fixed <NA> factor~ 0.273 0.528 -0.671 0.502 6.13e-3 12.1
## 4 fixed <NA> factor~ 0.119 0.714 -0.354 0.723 8.95e-7 15727.
## 5 ran_pa~ gear sd__(I~ 4.32 NA NA NA NA NA
tbl_lme4 <- tbl_regression(mod_glmer, exponentiate = TRUE,
conf.level = 0.90)
a <- coef(mod_glmer)[[1]] %>% {.[1, 2:ncol(.)]} %>% purrr::map_dbl(exp)
b <- tbl_lme4$table_body %>%
dplyr::pull(estimate) %>%
na.omit()
all.equal(unname(a), as.vector(b))
## [1] TRUE
mod_lm_interaction <- lm(age ~ trt * grade * response, data = trial)
tbl_regression(mod_lm_interaction)
Characteristic | Beta | 95% CI1 | p-value |
---|---|---|---|
Chemotherapy Treatment | |||
Drug A | — | — | |
Drug B | -0.61 | -9.4, 8.2 | 0.9 |
Grade | |||
I | — | — | |
II | 0.14 | -8.3, 8.6 | >0.9 |
III | 4.5 | -4.9, 14 | 0.3 |
Tumor Response | 4.8 | -6.9, 16 | 0.4 |
Chemotherapy Treatment * Grade | |||
Drug B * II | 4.2 | -8.4, 17 | 0.5 |
Drug B * III | -2.9 | -16, 9.9 | 0.7 |
Chemotherapy Treatment * Tumor Response | |||
Drug B * Tumor Response | 1.3 | -14, 17 | 0.9 |
Grade * Tumor Response | |||
II * Tumor Response | -4.4 | -21, 13 | 0.6 |
III * Tumor Response | -0.56 | -17, 16 | >0.9 |
Chemotherapy Treatment * Grade * Tumor Response | |||
Drug B * II * Tumor Response | 1.3 | -22, 24 | >0.9 |
Drug B * III * Tumor Response | -5.3 | -28, 17 | 0.6 |
1
CI = Confidence Interval
|
broom::tidy(mod_lm_interaction, conf.int = TRUE)
## # A tibble: 12 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 44.7 2.92 15.3 6.52e-34 39.0 50.5
## 2 trtDrug B -0.615 4.44 -0.138 8.90e- 1 -9.38 8.15
## 3 gradeII 0.144 4.27 0.0337 9.73e- 1 -8.28 8.56
## 4 gradeIII 4.48 4.77 0.940 3.49e- 1 -4.93 13.9
## 5 response 4.78 5.93 0.806 4.21e- 1 -6.92 16.5
## 6 trtDrug B:gradeII 4.17 6.37 0.655 5.14e- 1 -8.41 16.8
## 7 trtDrug B:gradeIII -2.95 6.51 -0.452 6.52e- 1 -15.8 9.91
## 8 trtDrug B:response 1.27 7.92 0.160 8.73e- 1 -14.4 16.9
## 9 gradeII:response -4.36 8.67 -0.502 6.16e- 1 -21.5 12.8
## 10 gradeIII:response -0.563 8.19 -0.0688 9.45e- 1 -16.7 15.6
## 11 trtDrug B:gradeII:r~ 1.29 11.6 0.111 9.12e- 1 -21.7 24.3
## 12 trtDrug B:gradeIII:~ -5.25 11.4 -0.461 6.46e- 1 -27.7 17.2
lung2 <- lung
Hmisc::label(lung2$sex) <- "Gender"
Hmisc::label(lung2$age) <- "AGE"
cox_hmisclbl <- coxph(Surv(time, status) ~ age + sex, data = lung2)
tbl_regression(cox_hmisclbl, exponentiate = TRUE)
Characteristic | HR1 | 95% CI1 | p-value |
---|---|---|---|
AGE | 1.02 | 1.00, 1.04 | 0.065 |
Gender | 0.60 | 0.43, 0.83 | 0.002 |
1
HR = Hazard Ratio, CI = Confidence Interval
|
broom::tidy(cox_hmisclbl, exponentiate = TRUE, conf.int = TRUE)
## # A tibble: 2 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 age 1.02 0.00922 1.85 0.0646 0.999 1.04
## 2 sex 0.599 0.167 -3.06 0.00218 0.431 0.831