项目作者: TysonStanley

项目描述 :
R package that provides functions to perform and interpret marginal mediation analysis.
高级语言: R
项目地址: git://github.com/TysonStanley/MarginalMediation.git
创建时间: 2017-03-03T07:06:48Z
项目社区:https://github.com/TysonStanley/MarginalMediation

开源协议:

下载


CRAN
Downloads
R build
status
R-CMD-check

" class="reference-link">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:

  1. install.packages("MarginalMediation")

or

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

The main function is mma():

  1. mma(...,
  2. 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.

  1. ## Data for the example
  2. library(furniture)
  3. data(nhanes_2010)
  1. ## The MarginalMediation package
  2. library(MarginalMediation)
  1. #> ℹ Loading MarginalMediation
  2. #> ── MarginalMediation 0.7.2 ─────────────────── learn more at tysonbarrett.com ──
  3. #> ✓ MarginalMediation attached
  4. #> ✓ No potential conflicts found
  1. pathbc <- glm(marijuana ~ home_meals + gender + age + asthma,
  2. data = nhanes_2010,
  3. family = "binomial")
  4. patha <- glm(home_meals ~ gender + age + asthma,
  5. data = nhanes_2010,
  6. family = "gaussian")
  7. mma(pathbc, patha,
  8. ind_effects = c("genderFemale-home_meals",
  9. "age-home_meals",
  10. "asthmaNo-home_meals"),
  11. boot = 500)
  12. #>
  13. #> calculating a paths... b and c paths... Done.
  14. #> ┌───────────────────────────────┐
  15. #> │ Marginal Mediation Analysis │
  16. #> └───────────────────────────────┘
  17. #> A marginal mediation model with:
  18. #> 1 mediators
  19. #> 3 indirect effects
  20. #> 3 direct effects
  21. #> 500 bootstrapped samples
  22. #> 95% confidence interval
  23. #> n = 1417
  24. #>
  25. #> Formulas:
  26. #> ◌ marijuana ~ home_meals + gender + age + asthma
  27. #> ◌ home_meals ~ gender + age + asthma
  28. #>
  29. #> Regression Models:
  30. #>
  31. #> marijuana ~
  32. #> Est SE Est/SE P-Value
  33. #> (Intercept) -0.39400 0.38028 -1.03608 0.30017
  34. #> home_meals -0.04062 0.01363 -2.98051 0.00288
  35. #> genderFemale 0.43161 0.11723 3.68169 0.00023
  36. #> age 0.00276 0.01470 0.18754 0.85123
  37. #> asthmaNo -0.00717 0.15004 -0.04778 0.96189
  38. #>
  39. #> home_meals ~
  40. #> Est SE Est/SE P-Value
  41. #> (Intercept) 6.56883 0.76462 8.59100 0.00000
  42. #> genderFemale -1.34831 0.23910 -5.63913 0.00000
  43. #> age -0.05689 0.03017 -1.88565 0.05955
  44. #> asthmaNo -0.00428 0.31293 -0.01368 0.98909
  45. #>
  46. #> Unstandardized Mediated Effects:
  47. #>
  48. #> Indirect Effects:
  49. #>
  50. #> marijuana ~
  51. #> Indirect Lower Upper
  52. #> genderFemale => home_meals 0.01312 0.00357 0.02435
  53. #> age => home_meals 0.00055 0.00000 0.00143
  54. #> asthmaNo => home_meals 0.00004 -0.00652 0.00596
  55. #>
  56. #> Direct Effects:
  57. #>
  58. #> marijuana ~
  59. #> Direct Lower Upper
  60. #> genderFemale 0.10430 0.04950 0.16045
  61. #> age 0.00066 -0.00652 0.00793
  62. #> 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
(t.barrett@aggiemail.usu.edu).