store_boot {semboottools} | R Documentation |
Compute and Store Bootstrap Estimates
Description
This function computes bootstrap estimates of a fitted structural equation model and stores the estimates for further processing.
Usage
store_boot(
object,
type = "std.all",
do_bootstrapping = TRUE,
R = 1000,
boot_type = "ordinary",
parallel = c("no", "multicore", "snow"),
ncpus = parallel::detectCores(logical = FALSE) - 1,
iseed = NULL,
keep.idx = FALSE,
bootstrapLavaan_args = list()
)
Arguments
object |
A 'lavaan'-class object, fitted with 'se = "boot"'. |
type |
The type of standard
estimates. The same argument of
|
do_bootstrapping |
If |
R |
If |
boot_type |
If |
parallel |
If |
ncpus |
If |
iseed |
If |
keep.idx |
Whether the indices
of cases selected in each bootstrap
sample is to be stored. To be passed
to the argument of the same name
in |
bootstrapLavaan_args |
A named
list of additional arguments to be
passed to |
Details
The function store_boot()
receives a
lavaan::lavaan object, optionally
fitted with bootstrapping standard errors
requested, and compute and store
the bootstrap estimates of user-defined
parameters and estimates in the
standardized solution.
If bootstrapping was not requested
when fitting the model (i.e., se
not set to "boot"
or "bootstrap"
),
then bootstrapping will be conducted
using lavaan::bootstrapLavaan()
to
compute bootstrap estimates of free
parameters. Otherwise, the stored
bootstrap estimates will be used in
subsequent steps.
For standardized solution bootstrap
estimates, it works by calling
lavaan::standardizedSolution()
with the bootstrap estimates
of free parameters in each bootstrap sample
to compute the standardized estimates
in each sample.
For user-defined parameters, it works by calling the function used to compute user-defined parameters with the bootstrap estimates of free parameters in each bootstrap samples to compute the user-defined parameters.
The bootstrap estimates are then
stored in the external
slot
of the fit object for further
processing.
Value
The original lavaan
object is
returned with the following objects
stored in the external
slot:
-
sbt_boot_std
: The matrix of bootstrap estimates in the standardized solution. -
sbt_boot_def
: The matrix of bootstrap estimates of user-defined parameters, if any. -
sbt_boot_ustd
: The matrix of bootstrap estimates of free parameters, if bootstrapping is not requested when fitting the model (i.e.,se
is not set to"boot"
or"bootstrap"
when fitting the model inlavaan
).
Author(s)
Shu Fai Cheung
https://orcid.org/0000-0002-9871-9448.
Based on semhelpinghands::standardizedSolution_boot_ci()
,
which was originally proposed in an issue at GitHub
https://github.com/simsem/semTools/issues/101#issue-1021974657,
inspired by a discussion at
the Google group for lavaan
https://groups.google.com/g/lavaan/c/qQBXSz5cd0o/m/R8YT5HxNAgAJ.
Unlike semhelpinghands::standardizedSolution_boot_ci()
,
this function only computes and stores
the bootstrap estimates.
Examples
library(lavaan)
set.seed(5478374)
n <- 50
x <- runif(n) - .5
m <- .40 * x + rnorm(n, 0, sqrt(1 - .40))
y <- .30 * m + rnorm(n, 0, sqrt(1 - .30))
dat <- data.frame(x = x, y = y, m = m)
model <-
'
m ~ a*x
y ~ b*m
ab := a*b
'
# Should set bootstrap to at least 2000 in real studies
fit <- sem(model, data = dat, fixed.x = FALSE,
se = "boot",
bootstrap = 100)
summary(fit)
fit <- store_boot(fit)