View source: R/mc2est_lavaan.R
fit2mc_out | R Documentation |
lavaan
OutputGenerate Monte Carlo
estimates from the output of
lavaan::sem()
.
fit2mc_out(fit, progress = TRUE)
fit |
The fit object. This
function only supports a
lavaan::lavaan object.
It can also be
a |
progress |
Logical. Display
progress or not. Default is |
This function is for
advanced users. do_mc()
is a
function users should try first
because do_mc()
has a general
interface for input-specific
functions like this one.
fit2mc_out()
can be used
to extract the stored Monte Carlo
estimates so that they can be reused
by indirect_effect()
,
cond_indirect_effects()
and related
functions to form Monte Carlo
confidence intervals for effects such
as indirect effects and conditional
indirect effects.
This approach removes the need to
repeat Monte Carlo simulation in each
call to
indirect_effect()
,
cond_indirect_effects()
, and
related functions. It also ensures
that the same set of Monte Carlo
estimates is used in all subsequent
analyses.
A mc_out
-class object
that can be used for the mc_out
argument of indirect_effect()
,
cond_indirect_effects()
, and
related functions 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.
do_mc()
, the general
purpose function that users should
try first before using this function.
library(lavaan)
data(data_med_mod_ab1)
dat <- data_med_mod_ab1
dat$"x:w" <- dat$x * dat$w
dat$"m:w" <- dat$m * dat$w
mod <-
"
m ~ x + w + x:w + c1 + c2
y ~ m + w + m:w + x + c1 + c2
"
fit <- sem(model = mod, data = dat, fixed.x = FALSE,
baseline = FALSE)
# In real research, R should be 5000 or even 10000.
fit <- gen_mc_est(fit, R = 100, seed = 453253)
fit_mc_out <- fit2mc_out(fit)
out <- cond_indirect_effects(wlevels = "w",
x = "x",
y = "y",
m = "m",
fit = fit,
mc_ci = TRUE,
mc_out = fit_mc_out)
out
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.