test_cond_indirect: Test a Conditional Indirect Effect

View source: R/test_conditional_indirect_effect.R

test_cond_indirectR Documentation

Test a Conditional Indirect Effect

Description

Test a conditional indirect effect for a power4test object.

Usage

test_cond_indirect(
  fit = fit,
  x = NULL,
  m = NULL,
  y = NULL,
  wvalues = 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().

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.

wvalues

A numeric vector of named elements. The names are the variable names of the moderators, and the values are the values to which the moderators will be set to. Default is NULL.

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().

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.

Details

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

It uses manymome::cond_indirect() 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 a conditional effect on a direct path with no mediator. Just omit m when calling the function.

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 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).

See Also

power4test()

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

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)

# Do the test in each replication

test_ind <- power4test(object = sim_only,
                       test_fun = test_cond_indirect,
                       test_args = list(x = "x",
                                        m = "m",
                                        y = "y",
                                        wvalues = c(w = 1),
                                        mc_ci = TRUE))
print(test_ind,
      test_long = TRUE)


power4mome documentation built on Sept. 9, 2025, 5:35 p.m.