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
|
R |
The number of replications. Default is 100. |
seed |
The seed for the
generating Monte Carlo estimates.
Default is |
parallel |
Not used. Kept
for compatibility with |
ncores |
Not used. Kept
for compatibility with |
make_cluster_args |
Not used. Kept
for compatibility with |
progress |
Logical. Display
progress or not. Default is |
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
-
do_mc()
: A general purpose function for creating Monte Carlo estimates to be reused by other functions. It returns amc_out
-class object. -
gen_mc_est()
: Generate Monte Carlo estimates and store them in theexternal
slot:external$manymome$mc
. For advanced users.
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