Compute the standardized moderation effect in a structural equation model fitted by lavaan::lavaan() or its wrappers and form the nonparametric bootstrap confidence interval.

stdmod_lavaan(fit, x, y, w, x_w, boot_ci = FALSE, R = 100, conf = 0.95, ...)

## Arguments

fit

The SEM output by lavaan::lavaan() or its wrappers.

x

The name of the focal variable in the model, the variable with its effect on the outcome variable being moderated.

y

The name of the outcome variable (dependent variable) in the model.

w

The name of the moderator in the model.

x_w

The name of the product term (x * w) in the model. It can be the variable generated by the colon operator, e.g., "x:w", which is only in the model and not in the original data set.

boot_ci

Boolean. Whether nonparametric bootstrapping will be conducted. Default is FALSE.

R

The number of nonparametric bootstrapping samples. Default is 100. Set this to at least 2000 in actual use.

conf

The level of confidence. Default is .95, i.e., 95%.

...

Optional arguments to be passed to boot::boot(). Parallel processing can be used by adding the appropriate arguments in boot::boot().

## Value

A list of class stdmod_lavaan with these elements:

• stdmod: The standardized moderation effect.

• ci: The nonparametric bootstrap confidence interval. NA if confidence interval not requested.

• boot_out: The raw output from boot::boot(). NA if confidence interval not requested.

• fit: The original fit object.

## Details

stdmod_lavaan() accepts a lavaan::lavaan object, the structural equation model output returned by lavaan::lavaan() and its wrappers (e.g, lavaan::sem()) and computes the standardized moderation effect using the formula in the appendix of Cheung, Cheung, Lau, Hui, and Vong (2022).

The standard deviations of the focal variable (the variable with its effect on the outcome variable being moderated), moderator, and outcome variable (dependent variable) are computed from the implied covariance matrix returned by lavaan::lavInspect(). Therefore, models fitted to data sets with missing data (e.g., with missing = "fiml") are also supported.

If nonparametric bootstrap confidence interval is requested with R bootstrap samples, the model will be fitted R times to these samples, and the standardized moderation effect will be computed in each sample. This ensures that all components used in the computation, including the standard deviations, are also computed from the bootstrapping samples.

Note that the computation can be slow because lavaan::lavaan() or its wrappers will be called R times.

## References

Cheung, S. F., Cheung, S.-H., Lau, E. Y. Y., Hui, C. H., & Vong, W. N. (2022) Improving an old way to measure moderation effect in standardized units. Health Psychology, 41(7), 502-505. doi:10.1037/hea0001188

## Author

Shu Fai Cheung https://orcid.org/0000-0002-9871-9448

## Examples


#Load a test data of 500 cases

dat <- test_mod1
library(lavaan)
mod <-
"
med ~ iv + mod + iv:mod + cov1
dv ~ med + cov2
"
fit <- sem(mod, dat)

# Compute the standardized moderation effect
out_noboot <- stdmod_lavaan(fit = fit,
x = "iv",
y = "med",
w = "mod",
x_w = "iv:mod")
out_noboot
#>
#> Call:
#> stdmod_lavaan(fit = fit, x = "iv", y = "med", w = "mod", x_w = "iv:mod")
#>
#>                  Variable
#> Focal Variable         iv
#> Moderator             mod
#> Outcome Variable      med
#> Product Term       iv:mod
#>
#>              lhs op    rhs   est    se      z pvalue ci.lower ci.upper
#> Original     med  ~ iv:mod 0.257 0.025 10.169      0    0.208    0.307
#> Standardized med  ~ iv:mod 0.440    NA     NA     NA       NA       NA

# Compute the standardized moderation effect and
# its percentile confidence interval using
# nonparametric bootstrapping
set.seed(8479075)
system.time(out_boot <- stdmod_lavaan(fit = fit,
x = "iv",
y = "med",
w = "mod",
x_w = "iv:mod",
boot_ci = TRUE,
R = 50))
#>    user  system elapsed
#>   0.882   0.029   0.888
# In real analysis, R should be at least 2000.
out_boot
#>
#> Call:
#> stdmod_lavaan(fit = fit, x = "iv", y = "med", w = "mod", x_w = "iv:mod",
#>     boot_ci = TRUE, R = 50)
#>
#>                  Variable
#> Focal Variable         iv
#> Moderator             mod
#> Outcome Variable      med
#> Product Term       iv:mod
#>
#>              lhs op    rhs   est    se      z pvalue ci.lower ci.upper
#> Original     med  ~ iv:mod 0.257 0.025 10.169      0    0.208    0.307
#> Standardized med  ~ iv:mod 0.440    NA     NA     NA    0.296    0.523
#>
#> Confidence interval of standardized moderation effect:
#> - Level of confidence: 95%
#> - Bootstrapping Method: Nonparametric
#> - Type: Percentile
#> - Number of bootstrap samples requests: 50
#> - Number of bootstrap samples with valid results: 50