Test several indirect effects
for a power4test
object.
Usage
test_k_indirect_effects(
fit = fit,
x = NULL,
m = NULL,
y = NULL,
mc_ci = TRUE,
mc_out = NULL,
boot_ci = FALSE,
boot_out = NULL,
check_post_check = TRUE,
...,
omnibus = c("no", "all_sig", "at_least_one_sig", "at_least_k_sig"),
at_least_k = 1,
fit_name = "fit",
get_map_names = FALSE,
get_test_name = FALSE
)
Arguments
- fit
The fit object, to be passed to
manymome::indirect_effect()
.- x
The name of the
x
-variable, the predictor.- m
Must be a list of character vectors. Each character vector stores the name(s) of mediator(s) along a path. The path moves from the first mediator in the vector to the last mediator in the vector. If
NULL
, the stored paths will be used, which are all the indirect paths in the model betweenx
andy
, by default.- y
The name of the
y
-variable, the outcome variable.- 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::many_indirect_effects()
.- omnibus
If
"no"
, the default, then the test results for all paths are stored. If"all_sig"
, then only one row of test is stored, and the test is declared significant if all paths are significant. If"at_least_one_sig"
, then only one row of test is stored, and the test is declared significant if at least one of the paths is significant. If"at_least_k_sig"
, then only one row of test is stored, and the test is declared significant if at leastk
of the paths is significant,k
determined by the argumentat_least_k
.- at_least_k
The minimum number of paths required to be significant for the omnibus test to be considered significant. Used when
omnibus
is"at_least_k_sig"
.- 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 data frame with the following columns:
est
: The estimated indirect effect for each path.cilo
andcihi
: The lower and upper limits of the confidence interval (95% by default), respectively, for each indirect effectsig
: Whether a test by confidence interval is significant (1
) or not significant (0
).test_label
: A column of labels generated to label the indirect effects.
If omnibus
is "all_sig"
or
"at_least_one"sig"
, then
the data frame has only one row,
and the columns "est"
, "cilo"
,
and "cihi"
are NA
. The column
sig
is determined by whether
all paths are significant ("all_sig"
)
or whether at least one path is
significant ("at_least_one_sig"
).
Details
This function is to be used in
power4test()
for testing an
indirect effect, by setting it
to the test_fun
argument.
It uses manymome::many_indirect_effects()
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
model_simple_med <-
"
m1 ~ x
m2 ~ x
y ~ m1 + m2 + x
"
# Specify the population values
model_simple_med_es <-
"
y ~ m1: s
m1 ~ x: m
y ~ m2: s
m2 ~ x: l
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)
#> Simulate the data:
#> Fit the model(s):
#> Generate Monte Carlo estimates:
# Do the test in each replication
test_ind <- power4test(object = sim_only,
test_fun = test_k_indirect_effects,
test_args = list(x = "x",
y = "y",
mc_ci = TRUE))
#> Do the test: test_indirects: x-...->y
print(test_ind,
test_long = TRUE)
#>
#> ====================== Model Information ======================
#>
#> == Model on Factors/Variables ==
#>
#> m1 ~ x
#> m2 ~ x
#> y ~ m1 + m2 + x
#>
#> == Model on Variables/Indicators ==
#>
#> m1 ~ x
#> m2 ~ x
#> y ~ m1 + m2 + x
#>
#> ====== Population Values ======
#>
#> Regressions:
#> Population
#> m1 ~
#> x 0.300
#> m2 ~
#> x 0.500
#> y ~
#> m1 0.100
#> m2 0.100
#> x 0.000
#>
#> Variances:
#> Population
#> .m1 0.910
#> .m2 0.750
#> .y 0.977
#> x 1.000
#>
#> (Computing indirect effects for 3 paths ...)
#>
#> == Population Conditional/Indirect Effect(s) ==
#>
#> == Indirect Effect(s) ==
#>
#> ind
#> x -> m1 -> y 0.030
#> x -> m2 -> y 0.050
#> x -> y 0.000
#>
#> - The 'ind' column shows the indirect effect(s).
#>
#> ======================= Data Information =======================
#>
#> Number of Replications: 5
#> 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 1 iteration
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 8
#>
#> Number of observations 100
#>
#> Model Test User Model:
#>
#> Test statistic 0.219
#> Degrees of freedom 1
#> P-value (Chi-square) 0.640
#>
#> =========== <mc_out> ===========
#>
#>
#> == A 'mc_out' class object ==
#>
#> Number of Monte Carlo replications: 100
#>
#>
#> ============== <test_indirects: x-...->y> ==============
#>
#> Mean(s) across replication:
#> test_label est cilo cihi sig
#> 1 x -> m1 -> y 0.026 -0.042 0.103 0.000
#> 2 x -> m2 -> y 0.034 -0.081 0.155 0.200
#>
#> - The column 'sig' shows the rejection rates.
#> - If the null hypothesis is false, the rate is the power.
#> - Number of valid replications for rejection rate(s): 5
#> - Proportion of valid replications for rejection rate(s): 1.000
# Set omnibus = "all_sig" to declare
# significant only if all paths are
# significant
test_ind_all_sig <- power4test(
object = sim_only,
test_fun = test_k_indirect_effects,
test_args = list(x = "x",
y = "y",
mc_ci = TRUE,
omnibus = "all_sig"))
#> Do the test: test_indirects: x-...->y
print(test_ind_all_sig,
test_long = TRUE)
#>
#> ====================== Model Information ======================
#>
#> == Model on Factors/Variables ==
#>
#> m1 ~ x
#> m2 ~ x
#> y ~ m1 + m2 + x
#>
#> == Model on Variables/Indicators ==
#>
#> m1 ~ x
#> m2 ~ x
#> y ~ m1 + m2 + x
#>
#> ====== Population Values ======
#>
#> Regressions:
#> Population
#> m1 ~
#> x 0.300
#> m2 ~
#> x 0.500
#> y ~
#> m1 0.100
#> m2 0.100
#> x 0.000
#>
#> Variances:
#> Population
#> .m1 0.910
#> .m2 0.750
#> .y 0.977
#> x 1.000
#>
#> (Computing indirect effects for 3 paths ...)
#>
#> == Population Conditional/Indirect Effect(s) ==
#>
#> == Indirect Effect(s) ==
#>
#> ind
#> x -> m1 -> y 0.030
#> x -> m2 -> y 0.050
#> x -> y 0.000
#>
#> - The 'ind' column shows the indirect effect(s).
#>
#> ======================= Data Information =======================
#>
#> Number of Replications: 5
#> 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 1 iteration
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 8
#>
#> Number of observations 100
#>
#> Model Test User Model:
#>
#> Test statistic 0.219
#> Degrees of freedom 1
#> P-value (Chi-square) 0.640
#>
#> =========== <mc_out> ===========
#>
#>
#> == A 'mc_out' class object ==
#>
#> Number of Monte Carlo replications: 100
#>
#>
#> ============== <test_indirects: x-...->y> ==============
#>
#> Mean(s) across replication:
#> test_label est cilo cihi sig
#> 1 x-...->y (All sig) NaN NaN NaN 0.000
#>
#> - The column 'sig' shows the rejection rates.
#> - If the null hypothesis is false, the rate is the power.
#> - Number of valid replications for rejection rate(s): 5
#> - Proportion of valid replications for rejection rate(s): 1.000