do_mc {manymome}R Documentation

Monte Carlo Estimates for 'indirect_effects' and 'cond_indirect_effects'

Description

Generate Monte Carlo estimates to be used by cond_indirect_effects(), indirect_effect(), and cond_indirect(),

Usage

do_mc(
  fit,
  R = 100,
  seed = NULL,
  parallel = TRUE,
  ncores = max(parallel::detectCores(logical = FALSE) - 1, 1),
  make_cluster_args = list(),
  progress = TRUE
)

gen_mc_est(fit, R = 100, seed = NULL)

Arguments

fit

The output of lavaan::sem(). It can also be a lavaan.mi object returned by semTools::runMI() or its wrapper, such as semTools::sem.mi(). The output of stats::lm() is not supported.

R

The number of replications. Default is 100.

seed

The seed for the generating Monte Carlo estimates. Default is NULL and seed is not set.

parallel

Not used. Kept for compatibility with do_boot().

ncores

Not used. Kept for compatibility with do_boot().

make_cluster_args

Not used. Kept for compatibility with do_boot().

progress

Logical. Display progress or not. Default is TRUE.

Details

It uses the parameter estimates and their variance-covariance matrix to generate Monte Carlo estimates of the parameter estimates in a model fitted by lavaan::sem(). The stored estimates can then be used by cond_indirect_effects(), indirect_effect(), and cond_indirect() to form Monte Carlo confidence intervals.

It also supports a model estimated by multiple imputation using semTools::runMI() or its wrapper, such as semTools::sem.mi(). The pooled estimates and their variance-covariance matrix will be used to generate the Monte Carlo estimates.

This approach removes the need to repeat Monte Carlo simulation in each call to cond_indirect_effects(), indirect_effect(), and cond_indirect(). It also ensures that the same set of Monte Carlo estimates is used in all subsequent analysis.

Multigroup Models

Since Version 0.1.14.2, support for multigroup models has been added for models fitted by lavaan.

Value

A mc_out-class object that can be used for the mc_out argument of cond_indirect_effects(), indirect_effect(), and cond_indirect() for forming Monte Carlo confidence intervals. The object is a list with the number of elements equal to the number of Monte Carlo replications. Each element is a list of the parameter estimates and sample variances and covariances of the variables in each Monte Carlo replication.

Functions

See Also

fit2mc_out(), which implements the Monte Carlo simulation.

Examples


library(lavaan)
data(data_med_mod_ab1)
dat <- data_med_mod_ab1
mod <-
"
m ~ x + w + x:w + c1 + c2
y ~ m + w + m:w + x + c1 + c2
"
fit <- sem(mod, dat)
# In real research, R should be 5000 or even 10000
mc_out <- do_mc(fit, R = 100, seed = 1234)
wlevels <- mod_levels(w = "w", fit = fit)
wlevels
out <- cond_indirect_effects(wlevels = wlevels,
                             x = "x",
                             y = "y",
                             m = "m",
                             fit = fit,
                             mc_ci = TRUE,
                             mc_out = mc_out)
out


[Package manymome version 0.2.1 Index]