Package 'MarginalMediation'

Title: Marginal Mediation
Description: Provides the ability to perform "Marginal Mediation"--mediation wherein the indirect and direct effects are in terms of the average marginal effects (Bartus, 2005, <https://EconPapers.repec.org/RePEc:tsj:stataj:v:5:y:2005:i:3:p:309-329>). The style of the average marginal effects stems from Thomas Leeper's work on the "margins" package. This framework allows the use of categorical mediators and outcomes with little change in interpretation from the continuous mediators/outcomes. See <doi:10.13140/RG.2.2.18465.92001> for more details on the method.
Authors: Tyson S Barrett [aut, cre] , Angelo Canty [ctb] (S original bootstrap method, http://statwww.epfl.ch/davison/BMA/library.html), Brian D. Ripley [ctb] (R port, bootstrap method), Thomas Leeper [ctb] (Vectorized marginal effects, https://thomasleeper.com/software.html)
Maintainer: Tyson S Barrett <[email protected]>
License: GPL-2
Version: 0.7.2
Built: 2025-01-04 03:40:38 UTC
Source: https://github.com/tysonstanley/marginalmediation

Help Index


re-export magrittr pipe operator

Description

re-export magrittr pipe operator


Average Marginal Effects

Description

Internal function for mma(). Based on the same strategy as margins by T. Leeper.

Usage

amed(model)

Arguments

model

the model object

Author(s)

Tyson S. Barrett


Average Marginal Effects

Description

Provides the average marginal effects of a GLM model with bootstrapped confidence intervals. Similar results would be obtained from using margins::margins().

Usage

frames(model, ci_type = "perc", boot = 100, ci = 0.95)

Arguments

model

the model object

ci_type

the type of boostrapped confidence interval; options are "perc", "basic", "bca"

boot

the number of bootstrapped samples; default is 100

ci

the confidence interval; the default is .975 which is the 95% confidence interval.

Details

Using the average marginal effects as discussed by Tamas Bartus (2005), the coefficients are transformed into probabilities (for binary outcomes) or remain in their original units (continuous outcomes).

Author(s)

Tyson S. Barrett

References

Bartus, T. (2005). Estimation of marginal effects using margeff. The Stata Journal, 5(3), 309–329. <https://EconPapers.repec.org/RePEc:tsj:stataj:v:5:y:2005:i:3:p:309-329>

Examples

library(furniture)
data(nhanes_2010)
fit = glm(marijuana ~ home_meals + gender + age + asthma, 
           data = nhanes_2010, 
           family = "binomial")
frames(fit)

Marginal Mediation

Description

Provides the ability to perform marginal mediation. Marginal mediation is particularly useful for situations where the mediator or outcome is categorical, a count, or some other non-normally distributed variable. The results provide the average marginal effects of the models, providing simple interpretation of the indirect effects.

Usage

mma(..., ind_effects, ci_type = "perc", boot = 500, ci = 0.95)

Arguments

...

the glm model objects; the first is the model with the outcome while the others are the mediated effects ("a" paths)

ind_effects

a vector of the desired indirect effects. Has the form "var1-var2".

ci_type

a string indicating the type of bootstrap method to use (currently "perc" and "basic" are available; "perc" is recommended). Further development will allow the Bias-Corrected bootstrap soon.

boot

the number of bootstrapped samples; default is 500.

ci

the confidence interval; the default is .95 which is the 95% confidence interval.

Details

Using the average marginal effects as discussed by Tamas Bartus (2005), the coefficients are transformed into probabilities (for binary outcomes) or remain in their original units (continuous outcomes).

Value

A list of class mma containing:

ind_effects

the indirect effects reported in the average marginal effect

dir_effects

the direct effects reported in the average marginal effect

ci_level

the confidence level

data

the original data frame

reported_ind

the indirect effects the user requested (in the ...)

boot

the number of bootstrap samples

model

the formulas of the individual sub-models

call

the original function call

Author(s)

Tyson S. Barrett

References

Bartus, T. (2005). Estimation of marginal effects using margeff. The Stata Journal, 5(3), 309–329.

MacKinnon, D. (2008). Introduction to Statistical Mediation Analysis. Taylor \& Francis, LLC.

Examples

## A minimal example:

library(furniture)
data(nhanes_2010)
bcpath = glm(marijuana ~ home_meals + gender + age + asthma, 
           data = nhanes_2010, 
           family = "binomial")
apath = glm(home_meals ~ gender + age + asthma,
           data = nhanes_2010, 
           family = "gaussian")
(fit = mma(bcpath, apath, 
           ind_effects = c("genderFemale-home_meals",
                           "age-home_meals",
                           "asthmaNo-home_meals"),
           boot = 10))

Uncorrelated Residual Assumption Check

Description

Provides the correlations of the residual terms of the model

Usage

mma_check(model)

Arguments

model

The mma model object


Direct Effects Extraction for MMA

Description

Extracts the formulas from a mma object

Usage

mma_dir_effects(model)

Arguments

model

mma fit object


Formula Extraction for MMA

Description

Extracts the formulas from a mma object

Usage

mma_formulas(model)

Arguments

model

mma fit object


Indirect Effects Extraction for MMA

Description

Extracts the formulas from a mma object

Usage

mma_ind_effects(model)

Arguments

model

mma fit object


Standardized Direct Effects Extraction for MMA

Description

Extracts the formulas from a mma object

Usage

mma_std_dir_effects(model)

Arguments

model

mma fit object


Standardized Indirect Effects Extraction for MMA

Description

Extracts the formulas from a mma object

Usage

mma_std_ind_effects(model)

Arguments

model

mma fit object


Percent Mediation

Description

To obtain the percent of the total effect that is mediated through the specified indirect path: indirect / (total) * 100.

Usage

perc_med(model, effect)

Arguments

model

mma fit object

effect

the indirect effect to be compared to its direct path