knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This vignette demonstrates how to form bootstrapping confidence intervals and examining bootstrap estimates in SEM using semboottools.
library(semboottools) library(lavaan)
We use a simple mediation model with a large sample (N = 1000).
This model includes: A predictor x, A mediator m, An outcome y.
Indirect effect (ab) and total effect (total) defined.
# Set seed for reproducibility set.seed(1234) # Generate data n <- 1000 x <- runif(n) - 0.5 m <- 0.20 * x + rnorm(n) y <- 0.17 * m + rnorm(n) dat <- data.frame(x, y, m) # Specify mediation model in lavaan syntax mod <- ' m ~ a * x y ~ b * m + cp * x ab := a * b total := a * b + cp '
fit <- sem(mod, data = dat, fixed.x = FALSE) summary(fit, ci = TRUE) # Ensure bootstrap estimates are stored fit <- store_boot(fit)
# Basic usage: default settings # Compute standardized solution with percentile bootstrap CIs std_boot <- standardizedSolution_boot(fit) print(std_boot)
'parameterEstimates_boot()' computes bootstrap CIs, standard errors, and optional asymmetric p-values for unstandardized parameter estimates, including both free and user-defined parameters.
It requires bootstrap estimates stored via store_boot(), supports percentile and bias-corrected CIs, and outputs bootstrap SEs as the standard deviation of estimates.
# Basic usage: default settings # Compute unstandardized solution with percentile bootstrap CIs est_boot <- parameterEstimates_boot(fit) # Print results print(est_boot)
To examine the distribution of bootstrap estimates, two functions are available:
hist_qq_boot()
\
For histogram + normal QQ-plot of one parameter.
scatter_boot()
\
For scatterplot matrix of two or more parameters.
hist_qq_boot()
# For estimates of user-defined parameters, hist_qq_boot(fit, "ab", standardized = FALSE) # For estimates in standardized solution, hist_qq_boot(fit, "ab", standardized = TRUE)
scatter_boot()
# standardized solution scatter_boot(fit, c("a", "b", "ab"), standardized = TRUE) # unstandardized solution scatter_boot(fit, c("a", "b", "ab"), standardized = FALSE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.