MyNixOS website logo
Description

Marginal Mediation.

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.

CRAN Downloads R buildstatus R-CMD-check

MarginalMediation: v 0.7.2

The MarginalMediation package provides the ability to perform marginal mediation analysis. It provides a useful statistical framework from which to interpret the coefficients in a mediation analysis, especially when the mediator(s) and/or outcome is binary or a count (other types of outcomes will be added).

You can install it via:

install.packages("MarginalMediation")

or

install.packages("remotes")
remotes::install_github("tysonstanley/MarginalMediation")

The main function is mma():

mma(...,
    ind_effects = c("apath-bpath"))

where ... consists of 2 or more model objects. The first is the b and c' path model, while the others are the a path models.

The ind_effects is a vector of requested mediated paths. These estimates are in terms of the average marginal effects using the a x b method of estimating indirect paths. Any number of these can be included, although it is limited to the number of variables available in the models.

A Quick Example

Below is an example, where the theoretical backing of such a model is not very stable, but it is useful to show how to use the function and the output.

## Data for the example
library(furniture)
data(nhanes_2010)
## The MarginalMediation package
library(MarginalMediation)
#> ℹ Loading MarginalMediation
#> ── MarginalMediation 0.7.2 ─────────────────── learn more at tysonbarrett.com ──
#> ✓ MarginalMediation attached
#> ✓ No potential conflicts found
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 
#> 
#> 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.00357 0.02435
#>         age => home_meals           0.00055  0.00000 0.00143
#>         asthmaNo => home_meals      0.00004 -0.00652 0.00596
#> 
#>    Direct Effects: 
#> 
#>      marijuana ~ 
#>                        Direct    Lower   Upper
#>         genderFemale  0.10430  0.04950 0.16045
#>         age           0.00066 -0.00652 0.00793
#>         asthmaNo     -0.00172 -0.07896 0.06809

The print method provides:

  1. the individual regression results,
  2. the a paths,
  3. the b paths,
  4. the indirect effect with the confidence interval, and
  5. the direct effect with the confidence interval.

The regressions are in their original (non-AME) units while the indirect and direct effects are in the AME units—the units of the outcome—in this case, risk of using marijuana.

Conclusions

Let me know if you find any bugs or want to discuss the method ([email protected]).

Metadata

Version

0.7.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows