Skip to contents

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.

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.

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.

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)
#> Simulate the data:
#> Fit the model(s):

# Do the test in each replication

test_out <- power4test(object = sim_only,
                       test_fun = test_moderation)
#> Do the test: test_moderation: CIs  

print(test_out,
      test_long = TRUE)
#> 
#> ====================== Model Information ======================
#> 
#> == Model on Factors/Variables ==
#> 
#> m ~ x + w1 + x:w1
#> y ~ m + x
#> 
#> == Model on Variables/Indicators ==
#> 
#> m ~ x + w1 + x:w1
#> y ~ m + x
#> 
#> ====== Population Values ======
#> 
#> Regressions:
#>                    Population
#>   m ~                        
#>     x                 0.000  
#>     w1                0.000  
#>     x:w1              0.150  
#>   y ~                        
#>     m                 0.000  
#>     x                 0.300  
#> 
#> Covariances:
#>                    Population
#>   x ~~                       
#>     w1                0.000  
#>     x:w1              0.000  
#>   w1 ~~                      
#>     x:w1              0.000  
#> 
#> Variances:
#>                    Population
#>    .m                 0.977  
#>    .y                 0.910  
#>     x                 1.000  
#>     w1                1.000  
#>     x:w1              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.300
#> 
#>  - The 'ind' column shows the effect(s).
#>  
#> == Conditional indirect effects ==
#> 
#>  Path: x -> m -> y
#>  Conditional on moderator(s): w1
#>  Moderator(s) represented by: w1
#> 
#>      [w1] (w1) ind    m~x y~m
#> 1 M+1.0SD    1   0  0.150   0
#> 2 Mean       0   0  0.000   0
#> 3 M-1.0SD   -1   0 -0.150   0
#> 
#>  - 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: w1 -> m -> y
#>  Conditional on moderator(s): x
#>  Moderator(s) represented by: x
#> 
#>       [x] (x) ind   m~w1 y~m
#> 1 M+1.0SD   1   0  0.150   0
#> 2 Mean      0   0  0.000   0
#> 3 M-1.0SD  -1   0 -0.150   0
#> 
#>  - The 'ind' column shows the conditional indirect effects.
#>  - ‘m~w1’,‘y~m’ is/are the path coefficient(s) along the path
#>    conditional on the moderator(s).
#> 
#> 
#> ======================= Data Information =======================
#> 
#> Number of Replications:  4 
#> Sample Sizes:  100 
#> 
#> Call print with 'data_long = TRUE' for further information.
#> 
#> ==================== Extra Element(s) Found ====================
#> 
#> - fit
#> 
#> === 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.537
#>   Degrees of freedom                                 2
#>   P-value (Chi-square)                           0.103
#> 
#> =============== <test_moderation: CIs > ===============
#> 
#> Mean(s) across replication:
#>   test_label lhs op  rhs   est    se     z pvalue   cilo  cihi   sig
#> 1     m~x:w1   m  ~ x:w1 0.150 0.101 1.557  0.160 -0.047 0.348 0.250
#> 
#> - 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): 4 
#> - Proportion of valid replications for rejection rate(s): 1.000