Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tysonstanley/marginalmediation
R package that provides functions to perform and interpret marginal mediation analysis.
https://github.com/tysonstanley/marginalmediation
average-marginal-effects margins mediation mediation-analysis mediator partial-effects r rstudio
Last synced: about 1 month ago
JSON representation
R package that provides functions to perform and interpret marginal mediation analysis.
- Host: GitHub
- URL: https://github.com/tysonstanley/marginalmediation
- Owner: TysonStanley
- Created: 2017-03-03T07:06:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-15T00:29:03.000Z (over 2 years ago)
- Last Synced: 2023-03-01T17:16:58.656Z (over 1 year ago)
- Topics: average-marginal-effects, margins, mediation, mediation-analysis, mediator, partial-effects, r, rstudio
- Language: R
- Homepage:
- Size: 1.88 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
set.seed(84322)
```
[![CRAN](https://www.r-pkg.org/badges/version/MarginalMediation)](https://www.r-pkg.org/badges/version/MarginalMediation)
[![Downloads](http://cranlogs.r-pkg.org/badges/grand-total/MarginalMediation)](https://cranlogs.r-pkg.org/badges/grand-total/MarginalMediation)
[![R build status](https://github.com/TysonStanley/MarginalMediation/workflows/R-CMD-check/badge.svg)](https://github.com/TysonStanley/MarginalMediation/actions)
[![R-CMD-check](https://github.com/TysonStanley/MarginalMediation/workflows/R-CMD-check/badge.svg)](https://github.com/TysonStanley/MarginalMediation/actions)# 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:
```{r, eval=FALSE}
install.packages("MarginalMediation")
```
or
```{r, eval=FALSE}
install.packages("remotes")
remotes::install_github("tysonstanley/MarginalMediation")
```The main function is `mma()`:
```{r, eval=FALSE}
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.
```{r}
## Data for the example
library(furniture)
data(nhanes_2010)
``````{r, eval = FALSE}
## The MarginalMediation package
library(MarginalMediation)
```
```{r, echo = FALSE}
devtools::load_all()
``````{r}
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)
```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 ().