Skip to contents

Test several conditional indirect effects for a power4test object.

Usage

test_cond_indirect_effects(
  fit = fit,
  x = NULL,
  m = NULL,
  y = NULL,
  wlevels = 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::cond_indirect_effects().

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.

wlevels

The output of manymome::merge_mod_levels(), or the moderator(s) to be passed to manymome::mod_levels_list(). If all the moderators can be represented by one variable, that is, each moderator is (a) a numeric variable, (b) a dichotomous categorical variable, or (c) a factor or string variable used in stats::lm() in fit, then it is a vector of the names of the moderators as appeared in the data frame. If at least one of the moderators is a categorical variable represented by more than one variable, such as user-created dummy variables used in lavaan::sem(), then it must be a list of the names of the moderators, with such moderators represented by a vector of names. For example: list("w1", c("gpgp2", "gpgp3"), the first moderator w1 and the second moderator a three-category variable represented by gpgp2 and gpgp3. See the help page of manymome::cond_indirect_effects() for further details.

mc_ci

Logical. If TRUE, the default, Monte Carlo confidence intervals will be formed. This argument and boot_ci cannot be both TRUE.

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 let power4test() to set it automatically.

boot_ci

Logical. If TRUE, the default, nonparametric bootstrap confidence intervals will be formed. This argument and mc_ci cannot be both TRUE.

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 let power4test() to set it automatically.

check_post_check

Logical. If TRUE, the default, and the model is fitted by lavaan, the test will be conducted only if the model passes the post.check conducted by lavaan::lavInspect() (with what = "post.check").

...

Additional arguments to be passed to manymome::cond_indirect_effects().

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 the output returned by manymome::cond_indirect_effects(), with the following modifications:

  • est: The estimated conditional indirect effects.

  • cilo and cihi: 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).

  • test_label: A column of labels generated to label the conditional effects.

Details

This function is to be used in power4test() for testing several conditional indirect effects, by setting it to the test_fun argument.

It uses manymome::cond_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().

It can also be used to test conditional effects on a direct path with no mediator. Just omit m when calling the function.

See also

Examples


# Specify the model

model_simple_mod <-
"
m ~ x + w + x:w
y ~ m + x
"

# Specify the population values

model_simple_mod_es <-
"
y ~ m: l
y ~ x: n
m ~ x: m
m ~ w: n
m ~ x:w: l
"

# Simulate the data

# Set nrep to a larger value in real analysis, such as 400
sim_only <- power4test(nrep = 5,
                       model = model_simple_mod,
                       pop_es = model_simple_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 tests in each replication

test_out <- power4test(object = sim_only,
                       test_fun = test_cond_indirect_effects,
                       test_args = list(x = "x",
                                        m = "m",
                                        y = "y",
                                        wlevels = c("w"),
                                        mc_ci = TRUE))
#> Do the test: test_cond_indirect_effects: x->m->y 
print(test_out,
      test_long = TRUE)
#> 
#> ====================== Model Information ======================
#> 
#> == Model on Factors/Variables ==
#> 
#> m ~ x + w + x:w
#> y ~ m + x
#> 
#> == Model on Variables/Indicators ==
#> 
#> m ~ x + w + x:w
#> y ~ m + x
#> 
#> ====== Population Values ======
#> 
#> Regressions:
#>                    Population
#>   m ~                        
#>     x                 0.300  
#>     w                 0.000  
#>     x:w               0.150  
#>   y ~                        
#>     m                 0.500  
#>     x                 0.000  
#> 
#> Covariances:
#>                    Population
#>   x ~~                       
#>     w                 0.000  
#>     x:w               0.000  
#>   w ~~                       
#>     x:w               0.000  
#> 
#> Variances:
#>                    Population
#>    .m                 0.887  
#>    .y                 0.751  
#>     x                 1.000  
#>     w                 1.000  
#>     x:w               1.000  
#> 
#> (Computing indirect effects for 1 paths ...)
#> 
#> (Computing conditional effects for 2 paths ...)
#> 
#> == Population Conditional/Indirect Effect(s) ==
#> 
#> == Effect(s) ==
#> 
#>        ind
#> x -> y   0
#> 
#>  - The 'ind' column shows the 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.225 0.450 0.500
#> 2 Mean      0 0.150 0.300 0.500
#> 3 M-1.0SD  -1 0.075 0.150 0.500
#> 
#>  - 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.075  0.150 0.500
#> 2 Mean      0 -0.000 -0.000 0.500
#> 3 M-1.0SD  -1 -0.075 -0.150 0.500
#> 
#>  - 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:  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                         7
#> 
#>   Number of observations                           100
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                 4.530
#>   Degrees of freedom                                 2
#>   P-value (Chi-square)                           0.104
#> 
#> =========== <mc_out> ===========
#> 
#> 
#> == A 'mc_out' class object ==
#> 
#> Number of Monte Carlo replications: 100 
#> 
#> 
#> ======== <test_cond_indirect_effects: x->m->y> ========
#> 
#> Mean(s) across replication:
#>             test_label     [w]    (w)   est   cilo  cihi   sig   m~x   y~m
#> 1 x->m->y | w: M+1.0SD M+1.0SD  1.060 0.212  0.078 0.405 0.800 0.438 0.474
#> 2    x->m->y | w: Mean    Mean  0.061 0.132  0.030 0.254 0.800 0.275 0.474
#> 3 x->m->y | w: M-1.0SD M-1.0SD -0.939 0.053 -0.092 0.189 0.000 0.112 0.474
#> 
#> - 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