Tidying methods for mediation analyses involving mixed effects models
Source:R/mediation_tidiers.R
mediation_tidiers.RdThese methods tidy the coefficients of mediation::mediate output
(i.e., mediate.mer objects) when lme4::lmer and
lme4::glmer models (i.e., merMod objects) provide the input.
Usage
# S3 method for class 'mediate.mer'
tidy(x, conf.int = FALSE, conf.level = 0.95, ...)Value
All tidying methods return a data.frame without rownames. The
structure depends on the method chosen.
tidy returns one row for each estimated effect:
first the mediated effect in the control and treatment groups, respectively,
then the direct effect in each group.
It contains the columns
- term
term being estimated
- estimate
estimated coefficient
- std.error
standard error
- p.value
P-value computed from t-statistic (may be missing/NA)
Examples
if (require("lme4") && require("mediation")) {
## Borrowed from \code{help(mediation::mediate)}:
if (FALSE) { # \dontrun{
## Varying intercept for mediator
mod_m <- glmer(job_dich ~ treat + econ_hard + (1 | educ),
family = binomial(link = "probit"), data = jobs)
## Varying intercept and slope for outcome
mod_y <- glmer(work1 ~ treat + job_dich + econ_hard + (1 + treat | occp),
family = binomial(link = "probit"), data = jobs)
## Output based on mediator group ("educ")
mod_med <- mediate(mod_m, mod_y, treat = "treat",
mediator = "job_dich", sims=50, group.out="educ")
} # }
## Load stored objects
load(system.file("extdata", "mediation_example.rda", package="broom.mixed"))
## Tidy outputs
tidy(mod_m)
tidy(mod_y)
tidy(mod_med)
}
#> Loading required package: mediation
#> Loading required package: mvtnorm
#> Loading required package: sandwich
#>
#> Attaching package: ‘sandwich’
#> The following objects are masked from ‘package:glmmTMB’:
#>
#> meatHC, sandwich
#> mediation: Causal Mediation Analysis
#> Version: 4.5.1
#> # A tibble: 4 × 4
#> term estimate std.error p.value
#> <chr> <dbl> <dbl> <dbl>
#> 1 acme_0 0.00403 0.00392 0.24
#> 2 acme_1 0.00436 0.00423 0.24
#> 3 ade_0 0.0554 0.0402 0.16
#> 4 ade_1 0.0557 0.0405 0.16