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 `nhanes_2010`

.

```
library(furniture)
data("nhanes_2010")
names(nhanes_2010)
```

```
## [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.

```
<- glm(marijuana ~ home_meals + gender + age + asthma,
pathbc data = nhanes_2010,
family = "binomial")
<- glm(home_meals ~ gender + age + asthma,
patha 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
##
## Regression Models:
##
## marijuana ~
## Est SE Est/SE P-Value
## (Intercept) -0.39400 0.38028 -1.03608 0.30017
## home_meals -0.04062 0.01363 -2.98051 0.00288
## genderFemale 0.43161 0.11723 3.68169 0.00023
## age 0.00276 0.01470 0.18754 0.85123
## asthmaNo -0.00717 0.15004 -0.04778 0.96189
##
## home_meals ~
## Est SE Est/SE P-Value
## (Intercept) 6.56883 0.76462 8.59100 0.00000
## genderFemale -1.34831 0.23910 -5.63913 0.00000
## age -0.05689 0.03017 -1.88565 0.05955
## asthmaNo -0.00428 0.31293 -0.01368 0.98909
##
## Unstandardized Mediated Effects:
##
## Indirect Effects:
##
## marijuana ~
## Indirect Lower Upper
## genderFemale => home_meals 0.01312 0.00393 0.02473
## age => home_meals 0.00055 0.00002 0.00142
## asthmaNo => home_meals 0.00004 -0.00583 0.00719
##
## Direct Effects:
##
## marijuana ~
## Direct Lower Upper
## genderFemale 0.10430 0.04975 0.15803
## age 0.00066 -0.00660 0.00897
## asthmaNo -0.00172 -0.06253 0.07419
```

The print method of MMA shows:

- information about the overall model,
- the individual regression models,
- the indirect effect (
`a x b`

) with its confidence interval, and - the direct effect with its confidence interval.

These 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()`

.

```
frames(pathbc,
boot = 100)
```

```
##
## Bootstrapping...Done.
```

```
## ┌────────────────────────────┐
## │ Average Marginal Effects │
## └────────────────────────────┘
##
## Estimate Lower Upper
## home_meals -0.0097 -0.0158 -0.0034
## genderFemale 0.1043 0.0434 0.1567
## age 0.0007 -0.0068 0.0074
## asthmaNo -0.0017 -0.0607 0.0818
## ────
```

We can compare these results to those from the remarkable
`margins`

package 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.

```
::install_github("leeper/margins")
remoteslibrary(margins)
summary(margins(pathbc))
```

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).