vignettes/fixed_effects.Rmd
fixed_effects.Rmd
This creates a standard regression table for the fixed effects,
mostly in keeping with the broom::tidy
approach.
library(lme4)
library(glmmTMB)
library(nlme)
library(brms)
library(mgcv)
lmer_model <-
lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
lme_model <-
lme(Reaction ~ Days, random = ~ 1 + Days | Subject, data = sleepstudy)
tmb_model <-
glmmTMB(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
# brms_model <-
# brm(Reaction ~ Days + (1 + Days | Subject),
# data = sleepstudy,
# cores = 4,
# refresh = -1,
# verbose = FALSE
# )
# this is akin to (1 | Subject) + (0 + Days | Subject) in lme4
mgcv_model <-
gam(
Reaction ~ Days +
s(Subject, bs = 're') +
s(Days, Subject, bs = 're'),
data = lme4::sleepstudy,
method = 'REML'
)
library(mixedup)
extract_fixed_effects(lmer_model)
38;5;246m# A tibble: 2 × 7
[39m
[.5 upper_97.5
term value se t p_value lower_238;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 251. 6.82 36.8 0 238. 265.
[38;5;250m2
[39m Days 10.5 1.55 6.77 0 7.44 13.5
[
extract_fixed_effects(lme_model)
38;5;246m# A tibble: 2 × 7
[39m
[.5 upper_97.5
term value se z p_value lower_238;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 251. 6.82 36.8 0 238. 265.
[38;5;250m2
[39m Days 10.5 1.55 6.77 0 7.42 13.5
[
extract_fixed_effects(tmb_model)
38;5;246m# A tibble: 2 × 7
[39m
[.5 upper_97.5
term value se z p_value lower_238;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 251. 6.63 37.9 0 238. 264.
[38;5;250m2
[39m Days 10.5 1.50 6.97 0 7.52 13.4
[
extract_fixed_effects(brms_model)
38;5;246m# A tibble: 2 × 5
[39m
[.5 upper_97.5
term value se lower_238;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 250. 7.73 235. 265.
[38;5;250m2
[39m Days 10.5 1.7 6.96 13.5
[
extract_fixed_effects(mgcv_model)
38;5;246m# A tibble: 2 × 7
[39m
[.5 upper_97.5
term value se t p_value lower_238;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 251. 6.88 36.5 0 238. 265.
[38;5;250m2
[39m Days 10.5 1.56 6.71 0 7.39 13.5
[
extract_fixed_effects(
lmer_model,ci_level = .9,
ci_args = list(method = 'boot', nsim = 50),
digits = 2
)38;5;246m# A tibble: 2 × 7
[39m
[
term value se t p_value lower_5 upper_9538;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 251. 6.82 36.8 0 237. 265.
[38;5;250m2
[39m Days 10.5 1.55 6.77 0 8.57 13.1
[
<- glmmTMB(
tmb_zip ~ spp + mined + (1 | site),
count zi = ~ spp + mined + (1 | site),
family = truncated_poisson,
data = Salamanders
)
extract_fixed_effects(
tmb_zip,cond = 'zi',
exponentiate = TRUE
)38;5;246m# A tibble: 8 × 7
[39m
[.5 upper_97.5
term value se z p_value lower_238;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;250m1
[39m Intercept 0.935 0.193 -
[31m0
[39m
[31m.
[39m
[31m325
[39m 0.745 0.624 1.4
[38;5;250m2
[39m sppPR 0.594 0.166 -
[31m1
[39m
[31m.
[39m
[31m87
[39m 0.062 0.344 1.03
[38;5;250m3
[39m sppDM 1.25 0.181 1.55 0.121 0.942 1.66
[38;5;250m4
[39m sppEC-A 0.822 0.165 -
[31m0
[39m
[31m.
[39m
[31m972
[39m 0.331 0.554 1.22
[38;5;250m5
[39m sppEC-L 1.91 0.253 4.89 0 1.47 2.47
[38;5;250m6
[39m sppDES-L 1.83 0.239 4.64 0 1.42 2.36
[38;5;250m7
[39m sppDF 1.05 0.161 0.299 0.765 0.774 1.42
[38;5;250m8
[39m minedno 2.76 0.516 5.42 0 1.91 3.98
[