Test a moderated
mediation effect for a power4test
object.
Usage
test_index_of_mome(
fit = fit,
x = NULL,
m = NULL,
y = NULL,
w = NULL,
mc_ci = TRUE,
mc_out = NULL,
boot_ci = FALSE,
boot_out = NULL,
check_post_check = TRUE,
...,
fit_name = "fit",
get_map_names = FALSE,
get_test_name = FALSE
)
Arguments
- fit
The fit object, to be passed to
manymome::index_of_mome()
.- x
The name of the
x
-variable, the predictor.- m
A character vector of the name(s) of mediator(s). The path moves from the first mediator in the vector to the last mediator in the vector. Can be
NULL
and the path is a direct path without mediator.- y
The name of the
y
-variable, the outcome variable.- w
The name of the moderator.
- mc_ci
Logical. If
TRUE
, the default, Monte Carlo confidence intervals will be formed. This argument andboot_ci
cannot be bothTRUE
.- mc_out
The pre-generated Monte Carlo estimates generated by manymome::do_mc, stored in a
power4test
object. Users should not set this argument and should letpower4test()
to set it automatically.- boot_ci
Logical. If
TRUE
, the default, nonparametric bootstrap confidence intervals will be formed. This argument andmc_ci
cannot be bothTRUE
.- boot_out
The pre-generated bootstrap estimates generated by manymome::do_boot, stored in a
power4test
object. Users should not set this argument and should letpower4test()
to set it automatically.- check_post_check
Logical. If
TRUE
, the default, and the model is fitted bylavaan
, the test will be conducted only if the model passes thepost.check
conducted bylavaan::lavInspect()
(withwhat = "post.check"
).- ...
Additional arguments to be passed to
manymome::index_of_mome()
.- fit_name
The name of the model fit object to be extracted. Default is
"fit"
. Used only when more than one model is fitted in each replication. This should be the name of the model on which the test is to be conducted.- get_map_names
Logical. Used by
power4test()
to determine how to extract stored information and assign them to this function. Users should not use this argument.- get_test_name
Logical. Used by
power4test()
to get the default name of this test. Users should not use this argument.
Value
In its normal usage, it returns a named numeric vector with the following elements:
est
: The mean of the estimated indirect effect across datasets.cilo
andcihi
: The means of the lower and upper limits of the confidence interval (95% by default), respectively.sig
: Whether a test by confidence interval is significant (1
) or not significant (0
).
Details
This function is to be used in
power4test()
for testing a
moderated mediation effect, by
setting it to the test_fun
argument.
It uses manymome::index_of_mome()
to do the test. It can be used on
models fitted by lavaan::sem()
or fitted by a sequence of calls
to stats::lm()
, although only
nonparametric bootstrap confidence
interval is supported for models
fitted by regression using
stats::lm()
.
Examples
# Specify the model
mod <-
"
m ~ x + w + x:w
y ~ m
"
# Specify the population values
mod_es <-
"
m ~ x: n
y ~ x: m
m ~ w: l
m ~ x:w: l
"
# Simulate the data
sim_only <- power4test(nrep = 2,
model = mod,
pop_es = mod_es,
n = 100,
R = 100,
do_the_test = FALSE,
iseed = 1234)
#> Simulate the data:
#> Fit the model(s):
#> Generate Monte Carlo estimates:
# Do the test in each replication
test_out <- power4test(object = sim_only,
test_fun = test_index_of_mome,
test_args = list(x = "x",
m = "m",
y = "y",
w = "w",
mc_ci = TRUE))
#> Do the test: test_index_of_mome: x->m->y, moderated by w
print(test_out,
test_long = TRUE)
#>
#> ====================== Model Information ======================
#>
#> == Model on Factors/Variables ==
#>
#> m ~ x + w + x:w
#> y ~ m
#>
#> == Model on Variables/Indicators ==
#>
#> m ~ x + w + x:w
#> y ~ m
#>
#> ====== Population Values ======
#>
#> Regressions:
#> Population
#> m ~
#> x 0.000
#> w 0.500
#> x:w 0.150
#> y ~
#> m 0.000
#>
#> Covariances:
#> Population
#> x ~~
#> w 0.000
#> x:w 0.000
#> w ~~
#> x:w 0.000
#>
#> Variances:
#> Population
#> .m 0.731
#> .y 1.000
#> x 1.000
#> w 1.000
#> x:w 1.000
#>
#> (Computing conditional effects for 2 paths ...)
#>
#> == Population Conditional/Indirect Effect(s) ==
#>
#> == Conditional indirect effects ==
#>
#> Path: x -> m -> y
#> Conditional on moderator(s): w
#> Moderator(s) represented by: w
#>
#> [w] (w) ind m~x y~m
#> 1 M+1.0SD 1 0 0.150 0
#> 2 Mean 0 0 -0.000 0
#> 3 M-1.0SD -1 0 -0.150 0
#>
#> - The 'ind' column shows the conditional indirect effects.
#> - ‘m~x’,‘y~m’ is/are the path coefficient(s) along the path conditional
#> on the moderator(s).
#>
#>
#> == Conditional indirect effects ==
#>
#> Path: w -> m -> y
#> Conditional on moderator(s): x
#> Moderator(s) represented by: x
#>
#> [x] (x) ind m~w y~m
#> 1 M+1.0SD 1 0 0.650 0
#> 2 Mean 0 0 0.500 0
#> 3 M-1.0SD -1 0 0.350 0
#>
#> - The 'ind' column shows the conditional indirect effects.
#> - ‘m~w’,‘y~m’ is/are the path coefficient(s) along the path conditional
#> on the moderator(s).
#>
#>
#> ======================= Data Information =======================
#>
#> Number of Replications: 2
#> Sample Sizes: 100
#>
#> Call print with 'data_long = TRUE' for further information.
#>
#> ==================== Extra Element(s) Found ====================
#>
#> - fit
#> - mc_out
#>
#> === Element(s) of the First Dataset ===
#>
#> ============ <fit> ============
#>
#> lavaan 0.6-19 ended normally after 2 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 6
#>
#> Number of observations 100
#>
#> Model Test User Model:
#>
#> Test statistic 5.502
#> Degrees of freedom 3
#> P-value (Chi-square) 0.139
#>
#> =========== <mc_out> ===========
#>
#>
#> == A 'mc_out' class object ==
#>
#> Number of Monte Carlo replications: 100
#>
#>
#> ==== <test_index_of_mome: x->m->y, moderated by w> ====
#>
#> Mean(s) across replication:
#> est cilo cihi sig
#> -0.006 -0.040 0.029 0.000
#>
#> - The value 'sig' is the rejection rate.
#> - If the null hypothesis is false, this is the power.
#> - Number of valid replications for rejection rate: 2
#> - Proportion of valid replications for rejection rate: 1.000