Learn R Programming

(Version 0.2.7, updated on 2025-01-25, release history)

manymome

Functions for estimating indirect effects, conditional indirect effects, and conditional effects in a model with moderation, mediation, and/or moderated mediation fitted by structural equation modelling (SEM) or estimated by multiple regression. The package was introduced in:

  • Cheung, S. F., & Cheung, S.-H. (2024). manymome: An R package for computing the indirect effects, conditional effects, and conditional indirect effects, standardized or unstandardized, and their bootstrap confidence intervals, in many (though not all) models. Behavior Research Methods, 56(5), 4862--4882. https://doi.org/10.3758/s13428-023-02224-z

What Can It Do?

  • Compute an unstandardized or standardized indirect effect or conditional indirect effect in a path model.

  • Form the confidence interval for this effect. Nonparametric bootstrapping is fully supported, while Monte Carlo is supported for models fitted by lavaan::sem().

  • Multigroup models fitted by lavaan::sem() are also supported in 0.1.14.2 and later versions. Details can be found in this article.

Advantages

  • A Simpler Workflow

    No need to define any parameters or similar code when fitting a model in lavaan::sem(). Just focus on fitting the model first. After a model has been selected, users can compute the effect for nearly any path, from nearly any variable, to nearly any other variables, conditional on nearly any moderators, and at any levels of the moderators. (See vignette("manymome") for details.) This is particularly convenient for multigroup models fitted by lavaan::sem(), which are supported in 0.1.14.2 and later versions (see this guide, for an illustration).

  • Supports Both SEM-Based and Regression-Based Analysis

    Supports structural equation models fitted by lavaan::sem() or by path models fitted by regression using lm(), although the focus of this package is on structural equation models. The interface of the main functions are nearly the same for both approaches.

  • Flexible in the Form of Models

    No limit on the number of predictors, mediators, and outcome variables, other than those by lavaan::sem() and lm(). For multigroup models fitted by lavaan::sem(), there is no inherent limit on the number of groups, other than the limit due to lavaan::sem(), if any (supported in 0.1.14.2 and later versions).

  • Supports Standardized Effects

    Can estimate standardized indirect effects and standardized conditional indirect effects without the need to standardize the variables. The bootstrap and Monte Carlo confidence intervals for standardized effects correctly take into account the sampling variation of the standardizers (the standard deviations of the predictor and the outcome variable) by recomputing them in each bootstrap sample or replication.

  • Supports Missing Data

    Supports datasets with missing data through lavaan::sem() with full information maximum likelihood (fiml).

    In version 0.1.9.8 or later, it also supports missing data handled by multiple imputation if the models are fitted by semTools::sem.mi() or semTools::runMI() (see vignette("do_mc_lavaan_mi")).

  • Supports Numeric and Categorical Moderators

    Supports numeric and categorical moderators. It has a function (factor2var()) for the easy creation of dummy variables in lavaan::sem(), and can also capitalize on the native support of categorical moderators in lm().

  • Less Time for Bootstrapping

    Bootstrapping, which can be time consuming, can be conducted just once. The main functions for computing indirect effects and conditional indirect effects can be called as many times as needed without redoing bootstrapping because they can reuse pregenerated bootstrap estimates (see vignette("manymome") and vignette("do_boot")).

  • Supports Latent Variables Mediation

    Supports indirect effects among latent variables for models fitted by lavaan::sem() (see vignette("med_lav")).

  • Support Treating Group As a Moderator

    For multigroup models fitted by lavaan::sem(), it supports comparing the direct or indirect effects along any path between any two groups. That is, it uses the grouping variable as a moderator (illustrated here; supported in 0.1.14.2 and later versions).

Limitations

Despite the aforementioned advantages, the current version of manymome has the following limitations:

  • Does not (officially) support categorical x-variables with more than two categories. Note that most functions will work with dichotomous x-variables, and the effect of x is simply the difference in predicted y between the two levels if coded as 0 and 1 (or any coding with a difference of 1, e.g., 1 and 2).

  • Does not support multilevel models (although lavaan does).

  • For bootstrapping, only supports nonparametric bootstrapping,

and supports only percentile and bias-corrected confidence interval. Does not support other bootstrapping methods such parametric bootstrapping.

  • Only supports OLS estimation when lm() is used.

We would add more to this list (suggestions are welcomed by adding GitHub issues) so that users (and we) know when other tools should be used instead of manymome, or whether we can address these limitations in manymome in the future.

How To Use It?

A good starting point is the Get-Started article (vignette("manymome")).

There are also articles (vignettes) on special topics, such as how to use mod_levels() to set the levels of the moderators. More will be added.

Homepage

For more information on this package, please visit its GitHub page:

https://sfcheung.github.io/manymome/

Installation

The stable version at CRAN can be installed by install.packages():

install.packages("manymome")

The latest developmental-but-stable version at GitHub can be installed by remotes::install_github():

remotes::install_github("sfcheung/manymome")

Background

We developed the package stdmod in 2021 for moderated regression. We included a function (stdmod::stdmod_lavaan()) for standardized moderation effect in path models fitted by lavaan::sem(). However, in practice, path models nearly always included indirect effects and so moderated mediation is common in path models. Moreover, stdmod is intended for moderated regression, not for structural equation modeling. We thought perhaps we could develop a more general tool for models fitted by structural equation modelling based on the interface we used in stdmod::stdmod_lavaan(). In our own projects, we also need to estimate indirect effects in models frequently. Large sample sizes with missing data are also common to us, for which bootstrapping is slow even with parallel processing. Therefore, we developed manymome to address these needs.

Issues

If you have any suggestions and found any bugs or limitations, please feel feel to open a GitHub issue. Thanks.

https://github.com/sfcheung/manymome/issues

Copy Link

Version

Install

install.packages('manymome')

Monthly Downloads

610

Version

0.2.7

License

GPL (>= 3)

Maintainer

Shu Fai Cheung

Last Published

January 25th, 2025

Functions in manymome (0.2.7)

data_med_complicated_mg

Sample Dataset: A Complicated Mediation Model With Two Groups
confint.indirect

Confidence Interval of Indirect Effect or Conditional Indirect Effect
confint.cond_indirect_diff

Confidence Interval of the Output of 'cond_indirect_diff()'
confint.indirect_list

Confidence Intervals of Indirect Effects in an 'indirect_list' Object
data_med_mod_b_mod

Sample Dataset: A Simple Mediation Model with b-Path Moderated-Moderation
data_med_mod_parallel

Sample Dataset: Parallel Mediation with Two Moderators
data_serial

Sample Dataset: Serial Mediation
data_med_mod_parallel_cat

Sample Dataset: Parallel Moderated Mediation with Two Categorical Moderators
data_mome_demo_missing

Sample Dataset: A Complicated Moderated-Mediation Model With Missing Data
data_med_mod_serial

Sample Dataset: Serial Mediation with Two Moderators
data_serial_parallel

Sample Dataset: Serial-Parallel Mediation
data_mome_demo

Sample Dataset: A Complicated Moderated-Mediation Model
data_med_mod_ab

Sample Dataset: Simple Mediation with Both Paths Moderated (Two Moderators)
data_mod

Sample Dataset: One Moderator
data_med_mod_serial_parallel

Sample Dataset: Serial-Parallel Mediation with Two Moderators
data_sem

Sample Dataset: A Latent Variable Mediation Model With 4 Factors
data_med_mod_a

Sample Dataset: Simple Mediation with a-Path Moderated
data_parallel

Sample Dataset: Parallel Mediation
data_med_mod_serial_parallel_cat

Sample Dataset: Serial-Parallel Moderated Mediation with Two Categorical Moderators
data_med_mod_serial_cat

Sample Dataset: Serial Moderated Mediation with Two Categorical Moderators
factor2var

Create Dummy Variables
fit2boot_out

Bootstrap Estimates for a lavaan Output
data_med_mod_b

Sample Dataset: Simple Mediation with b-Path Moderated
data_med_mod_ab1

Sample Dataset: Simple Mediation with Both Paths Moderated By a Moderator
data_mod2

Sample Dataset: Two Moderators
data_med_mg

Sample Dataset: Simple Mediation With Two Groups
do_boot

Bootstrap Estimates for 'indirect_effects' and 'cond_indirect_effects'
get_prod

Product Terms (if Any) Along a Path
do_mc

Monte Carlo Estimates for 'indirect_effects' and 'cond_indirect_effects'
data_mod_cat

Sample Dataset: Moderation with One Categorical Moderator
math_indirect

Math Operators for 'indirect'-Class Objects
fit2mc_out

Monte Carlo Estimates for a lavaan Output
manymome-package

manymome: Mediation, Moderation and Moderated-Mediation After Model Fitting
data_serial_parallel_latent

Sample Dataset: A Latent Mediation Model With Three Mediators
indirect_proportion

Proportion of Effect Mediated
delta_med

Delta_Med by Liu, Yuan, and Li (2023)
lm2boot_out

Bootstrap Estimates for lm Outputs
indirect_effects_from_list

Coefficient Table of an 'indirect_list' Class Object
indirect_i

Indirect Effect (No Bootstrapping)
index_of_mome

Index of Moderated Mediation and Index of Moderated Moderated Mediation
plot.cond_indirect_effects

Plot Conditional Effects
modmed_x1m3w4y1

Sample Dataset: Moderated Serial Mediation
merge_mod_levels

Merge the Generated Levels of Moderators
print.cond_indirect_diff

Print the Output of 'cond_indirect_diff'
lm2list

Join 'lm()' Output to Form an 'lm_list`-Class Object
get_one_cond_indirect_effect

Get The Conditional Indirect Effect for One Row of 'cond_indirect_effects' Output
lm_from_lavaan_list

'lavaan'-class to 'lm_from_lavaan_list'-Class
mod_levels

Create Levels of Moderators
print.cond_indirect_effects

Print a 'cond_indirect_effects' Class Object
print.all_paths

Print 'all_paths' Class Object
predict.lm_from_lavaan

Predicted Values of a 'lm_from_lavaan'-Class Object
plot_effect_vs_w

Plot an Effect Against a Moderator
predict.lm_from_lavaan_list

Predicted Values of an 'lm_from_lavaan_list'-Class Object
print.indirect_proportion

Print an 'indirect_proportion'-Class Object
print.indirect_list

Print an 'indirect_list' Class Object
print.boot_out

Print a boot_out-Class Object
print.lm_list

Print an lm_list-Class Object
print.mc_out

Print a mc_out-Class Object
simple_mediation_latent

Sample Dataset: A Simple Latent Mediation Model
subsetting_cond_indirect_effects

Extraction Methods for 'cond_indirect_effects' Outputs
predict.lm_list

Predicted Values of an 'lm_list'-Class Object
pseudo_johnson_neyman

Pseudo Johnson-Neyman Probing
subsetting_wlevels

Extraction Methods for a 'wlevels'-class Object
q_mediation

Mediation Models By Regression
terms.lm_from_lavaan

Model Terms of an 'lm_from_lavaan'-Class Object
summary.lm_list

Summary of an lm_list-Class Object
print.delta_med

Print a 'delta_med' Class Object
print.indirect

Print an 'indirect' Class Object
total_indirect_effect

Total Indirect Effect Between Two Variables
coef.delta_med

Delta_Med in a 'delta_med'-Class Object
all_indirect_paths

Enumerate All Indirect Effects in a Model
coef.indirect_list

Extract the Indirect Effects from a 'indirect_list' Object
coef.lm_from_lavaan

Coefficients of an 'lm_from_lavaan'-Class Object
coef.cond_indirect_diff

Print the Output of 'cond_indirect_diff()'
check_path

Check a Path Exists in a Model
coef.indirect_proportion

Extract the Proportion of Effect Mediated
cond_indirect

Conditional, Indirect, and Conditional Indirect Effects
coef.cond_indirect_effects

Estimates of Conditional Indirect Effects or Conditional Effects
data_med_complicated

Sample Dataset: A Complicated Mediation Model
cond_indirect_diff

Differences In Conditional Indirect Effects
confint.cond_indirect_effects

Confidence Intervals of Indirect Effects or Conditional Indirect Effects
confint.delta_med

Confidence Interval for Delta_Med in a 'delta_med'-Class Object
coef.indirect

Extract the Indirect Effect or Conditional Indirect Effect
data_med

Sample Dataset: Simple Mediation