Title: | Marginal Mediation |
Version: | 0.7.2 |
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. |
Imports: | stats, magrittr, boot, cli, crayon, rstudioapi, purrr, tibble, furniture, stringr |
Suggests: | testthat, knitr, rmarkdown, margins, betareg |
VignetteBuilder: | knitr |
Encoding: | UTF-8 |
License: | GPL-2 |
RoxygenNote: | 7.1.1 |
NeedsCompilation: | no |
Packaged: | 2022-04-15 01:14:46 UTC; tysonbarrett |
Author: | Tyson S Barrett |
Maintainer: | Tyson S Barrett <t.barrett88@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2022-04-15 08:42:36 UTC |
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 |
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 |