fit2boot_out function

Bootstrap Estimates for a lavaan Output

Bootstrap Estimates for a lavaan Output

Generate bootstrap estimates from the output of lavaan::sem().

fit2boot_out(fit) fit2boot_out_do_boot( fit, R = 100, seed = NULL, parallel = FALSE, ncores = max(parallel::detectCores(logical = FALSE) - 1, 1), make_cluster_args = list(), progress = TRUE, internal = list() )

Arguments

  • fit: The fit object. This function only supports a lavaan::lavaan object.
  • R: The number of bootstrap samples. Default is 100.
  • seed: The seed for the random resampling. Default is NULL.
  • parallel: Logical. Whether parallel processing will be used. Default is NULL.
  • ncores: Integer. The number of CPU cores to use when parallel is TRUE. Default is the number of non-logical cores minus one (one minimum). Will raise an error if greater than the number of cores detected by parallel::detectCores(). If ncores is set, it will override make_cluster_args.
  • make_cluster_args: A named list of additional arguments to be passed to parallel::makeCluster(). For advanced users. See parallel::makeCluster() for details. Default is list().
  • progress: Logical. Display progress or not. Default is TRUE.
  • internal: A list of arguments to be used internally for debugging. Default is list().

Returns

A boot_out-class object that can be used for the boot_out

argument of indirect_effect(), cond_indirect_effects(), and related functions for forming bootstrapping confidence intervals.

The object is a list with the number of elements equal to the number of bootstrap samples. Each element is a list of the parameter estimates and sample variances and covariances of the variables in each bootstrap sample.

Details

This function is for advanced users. do_boot() is a function users should try first because do_boot() has a general interface for input-specific functions like this one.

If bootstrapping confidence intervals was requested when calling lavaan::sem() by setting se = "boot", fit2boot_out() can be used to extract the stored bootstrap estimates so that they can be reused by indirect_effect(), cond_indirect_effects() and related functions to form bootstrapping confidence intervals for effects such as indirect effects and conditional indirect effects.

If bootstrapping confidence was not requested when fitting the model by lavaan::sem(), fit2boot_out_do_boot() can be used to generate nonparametric bootstrap estimates from the output of lavaan::sem() and store them for use by indirect_effect(), cond_indirect_effects(), and related functions.

This approach removes the need to repeat bootstrapping in each call to indirect_effect(), cond_indirect_effects(), and related functions. It also ensures that the same set of bootstrap samples is used in all subsequent analyses.

Functions

  • fit2boot_out(): Process stored bootstrap estimates for functions such as cond_indirect_effects().
  • fit2boot_out_do_boot(): Do bootstrapping and store information to be used by cond_indirect_effects() and related functions. Support parallel processing.

Examples

library(lavaan) data(data_med_mod_ab1) dat <- data_med_mod_ab1 dat$"x:w" <- dat$x * dat$w dat$"m:w" <- dat$m * dat$w mod <- " m ~ x + w + x:w + c1 + c2 y ~ m + w + m:w + x + c1 + c2 " # Bootstrapping not requested in calling lavaan::sem() fit <- sem(model = mod, data = dat, fixed.x = FALSE, se = "none", baseline = FALSE) fit_boot_out <- fit2boot_out_do_boot(fit = fit, R = 40, seed = 1234, progress = FALSE) out <- cond_indirect_effects(wlevels = "w", x = "x", y = "y", m = "m", fit = fit, boot_ci = TRUE, boot_out = fit_boot_out) out

See Also

do_boot(), the general purpose function that users should try first before using this function.

  • Maintainer: Shu Fai Cheung
  • License: GPL (>= 3)
  • Last published: 2025-01-25