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 |
Internal function for mma()
. Based on the same strategy as
margins
by T. Leeper.
amed(model)
amed(model)
model |
the model object |
Tyson S. Barrett
Provides the average marginal effects of a GLM model with
bootstrapped confidence intervals. Similar results would be obtained from using
margins::margins()
.
frames(model, ci_type = "perc", boot = 100, ci = 0.95)
frames(model, ci_type = "perc", boot = 100, ci = 0.95)
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. |
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).
Tyson S. Barrett
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>
library(furniture) data(nhanes_2010) fit = glm(marijuana ~ home_meals + gender + age + asthma, data = nhanes_2010, family = "binomial") frames(fit)
library(furniture) data(nhanes_2010) fit = glm(marijuana ~ home_meals + gender + age + asthma, data = nhanes_2010, family = "binomial") frames(fit)
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.
mma(..., ind_effects, ci_type = "perc", boot = 500, ci = 0.95)
mma(..., ind_effects, ci_type = "perc", boot = 500, ci = 0.95)
... |
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 |
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. |
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).
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 |
Tyson S. Barrett
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.
## 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))
## 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))
Provides the correlations of the residual terms of the model
mma_check(model)
mma_check(model)
model |
The mma model object |
Extracts the formulas from a mma object
mma_dir_effects(model)
mma_dir_effects(model)
model |
mma fit object |
Extracts the formulas from a mma object
mma_formulas(model)
mma_formulas(model)
model |
mma fit object |
Extracts the formulas from a mma object
mma_ind_effects(model)
mma_ind_effects(model)
model |
mma fit object |
Extracts the formulas from a mma object
mma_std_dir_effects(model)
mma_std_dir_effects(model)
model |
mma fit object |
Extracts the formulas from a mma object
mma_std_ind_effects(model)
mma_std_ind_effects(model)
model |
mma fit object |
To obtain the percent of the total effect that is mediated through the specified indirect path: indirect / (total) * 100.
perc_med(model, effect)
perc_med(model, effect)
model |
mma fit object |
effect |
the indirect effect to be compared to its direct path |