View source: R/test_indirect_effect.R
test_indirect_effect | R Documentation |
Test an indirect effect
for a power4test
object.
test_indirect_effect(
fit = fit,
x = NULL,
m = NULL,
y = 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
)
fit |
The fit object, to be
passed to |
x |
The name of the |
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 |
y |
The name of the |
mc_ci |
Logical. If |
mc_out |
The pre-generated
Monte Carlo estimates generated by
manymome::do_mc, stored in
a |
boot_ci |
Logical. If |
boot_out |
The pre-generated
bootstrap estimates generated by
manymome::do_boot, stored in
a |
check_post_check |
Logical. If
|
... |
Additional arguments to
be passed to |
fit_name |
The name of the
model fit object to be extracted.
Default is |
get_map_names |
Logical. Used
by |
get_test_name |
Logical. Used
by |
This function is to be used in
power4test()
for testing an
indirect effect, by setting it
to the test_fun
argument.
It uses manymome::indirect_effect()
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()
.
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
and cihi
: 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
).
power4test()
# Specify the model
model_simple_med <-
"
m ~ x
y ~ m + x
"
# Specify the population values
model_simple_med_es <-
"
y ~ m: l
m ~ x: m
y ~ x: n
"
# Simulate the data
sim_only <- power4test(nrep = 5,
model = model_simple_med,
pop_es = model_simple_med_es,
n = 100,
R = 100,
do_the_test = FALSE,
iseed = 1234)
# Do the test in each replication
test_ind <- power4test(object = sim_only,
test_fun = test_indirect_effect,
test_args = list(x = "x",
m = "m",
y = "y",
mc_ci = TRUE))
print(test_ind,
test_long = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.