test_moderation: Test All Moderation Effects

View source: R/test_moderation.R

test_moderationR Documentation

Test All Moderation Effects

Description

Test all moderation effects by testing all product terms for a power4test object.

Usage

test_moderation(
  fit = fit,
  standardized = FALSE,
  check_post_check = TRUE,
  ...,
  fit_name = "fit",
  get_map_names = FALSE,
  get_test_name = FALSE
)

Arguments

fit

The fit object, to be passed to lavaan::parameterEstimates(), lavaan::standardizedSolution(), or lmhelprs::lm_list_to_partable().

standardized

Logical. If TRUE, lavaan::standardizedSolution() will be used. Can be used only with models fitted by lavaan.

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 lavaan::parameterEstimates(), lavaan::standardizedSolution(), or lmhelprs::lm_list_to_partable().

fit_name

The name of the fit results for which the parameter names will be displayed. Default is "fit".

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 all product terms, by setting it to the test_fun argument.

It is just a wrapper to test_parameters(). It will first identifies all product terms (terms with : in the names), and then call test_parameters(), with pars set to select the regression coefficients of these terms.

Value

In its normal usage, it returns the output returned by lavaan::parameterEstimates() or lmhelprs::lm_list_to_partable(), with the following modifications:

  • est: The parameter estimates, even if standardized estimates are requested (not est.std).

  • cilo and cihi: The lower and upper limits of the confidence interval (95% by default), respectively (not ci.lower and ci.upper).

  • sig: Whether a test by confidence interval is significant (1) or not significant (0).

  • test_label: A column of labels generated by lavaan::lav_partable_labels(), which are usually the labels used by coef() to label the parameters.

See Also

power4test(), test_parameters()

Examples


# Specify the model

mod <-
"
m ~ x + w1 + x:w1
y ~ m + x
"

# Specify the population values

mod_es <-
"
m ~ x: n
y ~ x: m
m ~ w1: n
m ~ x:w1: l
"

# Simulate the data

sim_only <- power4test(nrep = 4,
                       model = mod,
                       pop_es = mod_es,
                       n = 100,
                       do_the_test = FALSE,
                       iseed = 1234)

# Do the test in each replication

test_out <- power4test(object = sim_only,
                       test_fun = test_moderation)

print(test_out,
      test_long = TRUE)


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