bootstrap_modsem | R Documentation |
A generic interface for parametric and non-parametric bootstrap procedures
for structural equation models estimated with the modsem ecosystem.
The function dispatches on the class of model
; currently dedicated
methods exist for modsem_pi
(product‑indicator approach) and
modsem_da
(distributional‑analytic approach).
bootstrap_modsem(model = modsem, FUN, ...)
## S3 method for class 'modsem_pi'
bootstrap_modsem(model, FUN, ...)
## S3 method for class 'modsem_da'
bootstrap_modsem(
model,
FUN = "coef",
R = 1000L,
P.max = 1e+05,
type = c("nonparametric", "parameteric"),
verbose = interactive(),
calc.se = FALSE,
optimize = FALSE,
...
)
## S3 method for class ''function''
bootstrap_modsem(
model = modsem,
FUN = "coef",
data,
R = 1000L,
verbose = interactive(),
FUN.args = list(),
...
)
model |
A fitted |
FUN |
A function that returns the statistic of interest when applied to a fitted model. The function must accept a single argument, the model object, and should ideally return a numeric vector; see Value. |
... |
Additional arguments forwarded to |
R |
number of bootstrap replicates. |
P.max |
ceiling for the simulated population size. |
type |
Bootstrap flavour, see Details. |
verbose |
Should progress information be printed to the console? |
calc.se |
Should standard errors for each replicate. Defaults to |
optimize |
Should starting values be re-optimized for each replicate. Defaults to |
data |
Dataset to be resampled. |
FUN.args |
Arguments passed to |
A thin wrapper around lavaan::bootstrapLavaan()
that performs the
necessary book‑keeping so that FUN
receives a fully‑featured
modsem_pi
object—rather than a bare lavaan
fit—at every
iteration.
The function internally resamples the observed data (non-parametric
case) or simulates from the estimated parameter table (parametric case),
feeds the sample to modsem_da
, evaluates FUN
on the
refitted object and finally collates the results.
This is a more general version of boostrap_modsem
for
bootstrapping modsem
functions, not modsem objects.
model
is now a function to be boostrapped, and ...
are now passed to the function (model
), not FUN
. To
pass arguments to FUN
use FUN.args
.
Depending on the return type of FUN
either
A matrix with R
rows (bootstrap replicates) and as
many columns as length(FUN(model))
.
A list of length R
; each element is the raw output of
FUN
. NOTE: Only applies for modsem_da
objects
bootstrap_modsem(modsem_pi)
: Bootstrap a modsem_pi
model by delegating
to bootstrapLavaan
.
bootstrap_modsem(modsem_da)
: Parametric or non-parametric bootstrap for
modsem_da
models.
bootstrap_modsem(`function`)
: Non-parametric bootstrap of modsem
functions
bootstrapLavaan
, modsem_pi
,
modsem_da
m1 <- '
X =~ x1 + x2
Z =~ z1 + z2
Y =~ y1 + y2
Y ~ X + Z + X:Z
'
fit_pi <- modsem(m1, oneInt)
bootstrap_modsem(fit_pi, FUN = coef, R = 10L)
m1 <- '
X =~ x1 + x2
Z =~ z1 + z2
Y =~ y1 + y2
Y ~ X + Z + X:Z
'
## Not run:
fit_lms <- modsem(m1, oneInt, method = "lms")
bootstrap_modsem(fit_lms, FUN = coef, R = 10L)
## End(Not run)
tpb <- "
# Outer Model (Based on Hagger et al., 2007)
ATT =~ att1 + att2 + att3 + att4 + att5
SN =~ sn1 + sn2
PBC =~ pbc1 + pbc2 + pbc3
INT =~ int1 + int2 + int3
BEH =~ b1 + b2
# Inner Model (Based on Steinmetz et al., 2011)
INT ~ ATT + SN + PBC
BEH ~ INT + PBC + INT:PBC
"
## Not run:
boot <- bootstrap_modsem(model = modsem,
model.syntax = tpb, data = TPB,
method = "dblcent", rcs = TRUE,
rcs.scale.corrected = TRUE,
FUN = "coef", R = 50L)
coef <- apply(boot, MARGIN = 2, FUN = mean, na.rm = TRUE)
se <- apply(boot, MARGIN = 2, FUN = sd, na.rm = TRUE)
cat("Parameter Estimates:\n")
print(coef)
cat("Standard Errors: \n")
print(se)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.