Marginal Mediation is the general method of interpreting indirect and direct effects in terms of the average marginal effects. When the mediator(s) and outcome are continuous, this is the same as the normal a x b
method. When either the mediator(s) or outcome is dichotomous, then it allows a simple transformation from the log-odds scale to probability.
For example, when the mediator is dichotomous and the outcome is continuous, we have a probability times a value in the unit of the outcome. Simply, the resulting indirect or total effect is in the units of the outcome.
MarginalMediation
To demonstrate the main functions in MarginalMediation
, we are going to use a data set from the furniture
package called nhanes10
.
## [1] "id" "gen_health" "mod_active" "vig_active" "home_meals"
## [6] "gender" "age" "marijuana" "illicit" "rehab"
## [11] "asthma" "overweight" "cancer" "low_int" "down"
## [16] "sleeping" "low_energy" "appetite" "feel_bad" "no_con"
## [21] "speak_move" "dead" "difficulty" "active"
mma()
This is the main function of the package. It takes data, two (or more in the future) formulas relating to the outcome and mediators, the family of the generalized linear model (GLM) regression functions, the indirect effects to compute, and the number of bootstrapped samples.
pathbc = glm(marijuana ~ home_meals + gender + age + asthma,
data = nhanes_2010,
family = "binomial")
patha = glm(home_meals ~ gender + age + asthma,
data = nhanes_2010,
family = "gaussian")
mma(pathbc, patha,
ind_effects = c("genderFemale-home_meals",
"age-home_meals",
"asthmaNo-home_meals"),
boot = 500)
##
## calculating a paths... b and c paths... Done.
## ┌───────────────────────────────┐
## │ Marginal Mediation Analysis │
## └───────────────────────────────┘
## A marginal mediation model with:
## 1 mediators
## 3 indirect effects
## 3 direct effects
## 500 bootstrapped samples
## 95% confidence interval
## n = 1417
##
## Formulas:
## ◌ marijuana ~ home_meals + gender + age + asthma
## ◌ home_meals ~ gender + age + asthma
##
## Unstandardized Effects
## ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
## ── Indirect Effects ──
## A-path B-path Indirect Lower Upper
## genderFemale-home_meals -1.34831 -0.00973 0.01312 0.00437 0.02318
## age-home_meals -0.05689 -0.00973 0.00055 0.00000 0.00143
## asthmaNo-home_meals -0.00428 -0.00973 0.00004 -0.00623 0.00675
##
## ── Direct Effects ──
## Direct Lower Upper
## genderFemale 0.10430 0.05290 0.16338
## age 0.00066 -0.00603 0.00804
## asthmaNo -0.00172 -0.06534 0.07127
## -----
The output is simple, with:
a
path,b
path,a x b
) with its confidence interval, andThese estimates are all average marginal effects, meaning each are interpreted in terms of the corresponding endogenous variable’s original units. In this example, since marijuana is binary, its original units are probabilities. That means that the indirect and direct effects are risks (or probabilities) of using marijuana.
frames()
This function provides the average marginal effects of a GLM model’s parameters. Its syntax is similar to that of mma()
.
##
## Bootstrapping...Done.
## ┌────────────────────────────┐
## │ Average Marginal Effects │
## └────────────────────────────┘
##
## Estimate Lower Upper
## home_meals -0.0097 -0.0180 -0.0029
## genderFemale 0.1043 0.0459 0.1597
## age 0.0007 -0.0051 0.0089
## asthmaNo -0.0017 -0.0667 0.0731
## ────
We can compare these results to those from margins
found at https://github.com/leeper/margins from Thomas Leeper. We won’t show them here, but the estimates are the same as those from the frames()
function.
The differences are mainly in the confidence intervals since they are based on two different methods. I highly recommend looking into both the delta method (as used in margins
and Stata) as well as the bootstrapping method as used in MarginalMediation
.
This is currently beta but I am excited to provide an initial working release. Let me know if you find any bugs or want to discuss the method (t.barrett@aggiemail.usu.edu).