Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

med_summary

Tidy report of mediation analysis.


Description

Tidy report of mediation analysis, which is performed using the mediation package.

Usage

med_summary(model, digits = nsmall, nsmall = 3, print.avg = TRUE)

Arguments

model

Mediation model built using mediation::mediate().

digits

Number of decimal places of output. Default is 3.

nsmall

The same as digits.

print.avg

Just set as TRUE for a concise output. For details, see the "Value" section in mediation::mediate().

Value

Invisibly return a data frame containing the results.

Examples

library(mediation)
?mediation::mediate

## Example 1: OLS Regression
## Bias-corrected and accelerated (BCa) bootstrap confidence intervals

## Hypothesis: Solar radiation -> Ozone -> Daily temperature
lm.m=lm(Ozone ~ Solar.R + Month + Wind, data=airquality)
lm.y=lm(Temp ~ Ozone + Solar.R + Month + Wind, data=airquality)
set.seed(123)  # set a random seed for reproduction
med=mediate(lm.m, lm.y,
            treat="Solar.R", mediator="Ozone",
            sims=1000, boot=TRUE, boot.ci.type="bca")
med_summary(med)

## Example 2: Multilevel Linear Model (Linear Mixed Model)
## (models must be fit using "lme4::lmer" rather than "lmerTest::lmer")
## Monte Carlo simulation (quasi-Bayesian approximation)
## (bootstrap method is not applicable to "lmer" models)

## Hypothesis: Crips -> Sweetness -> Preference (for carrots)
data=lmerTest::carrots  # long-format data
data=na.omit(data)  # omit missing values
lmm.m=lme4::lmer(Sweetness ~ Crisp + Gender + Age + (1 | Consumer), data=data)
lmm.y=lme4::lmer(Preference ~ Sweetness + Crisp + Gender + Age + (1 | Consumer), data=data)
set.seed(123)  # set a random seed for reproduction
med.lmm=mediate(lmm.m, lmm.y,
                treat="Crisp", mediator="Sweetness",
                sims=1000)
med_summary(med.lmm)

bruceR

Broadly Useful Convenient and Efficient R Functions

v0.6.2
GPL-3
Authors
Han-Wu-Shuang Bao [aut, cre]
Initial release
2021-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.