| boot.bs | R Documentation |
This function performs the model-based Bollen-Stine Bootstrapping with incomplete data of the chi-square statistic. By default, the function performs model-based bootstrapping based on transformation method 2 in Savalei and Yuan (2009).
boot.bs(object = NULL, data = NULL, model = NULL, sigma = NULL, mu = NULL,
group = NULL, chisq = NULL, em.cov = NULL, trans = c(1, 2), nrep = 500,
return = c("transdat", "bootsamp", "output"), seed = NULL,
progress = TRUE, digits = 2, p.digits = 3, plot = FALSE, filename = NULL,
width = NA, height = NA, dpi = 600, write = NULL, append = TRUE,
check = TRUE, output = TRUE, ...)
object |
an object of class lavaan, i.e., a fitted latent variable model
including mean structures, i.e., |
data |
a data frame representing the target raw data set, optional
argument if the argument |
model |
a character string. Optional argument representing the target
model if the argument |
sigma |
a matrix. Optional argument representing the model-implied
covariance matrix if the argument |
mu |
a numeric vector. Optional argument representing the model-implied
mean vector if the argument |
group |
a character vector. Optional argument representing the name of
the grouping variable in |
chisq |
a numeric value. Optional argument representing the model's
|
em.cov |
a matrix. Optional argument representing the EM or Two-Stage ML estimated covariance matrix used to speed up the Transformation 2 algorithm. |
trans |
a character string representing the transformation method in
Savalei and Yuan (2009). There are three methods presented in
the article, but only the first two are currently implemented
in the function, i.e., |
nrep |
a numeric value indicating the number of bootstrap replicates (default is 500). |
return |
a character string indicating which results to return, i.e.,
|
seed |
a numeric value specifying the seed of the pseudo-random numbers used when drawing bootstrap samples. |
progress |
logical: if |
digits |
an integer value indicating the number of decimal places
to be used for displaying the |
p.digits |
an integer value indicating the number of decimal places to be used for displaying the p-values. |
plot |
logical: if |
filename |
a character string indicating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
dpi |
a numeric value indicating the |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
... |
additional arguments in the lavaan::lavaan() function, see lavaan::lavOptions(). |
Returns an object of class misty.object when specifying return = "output":
call |
function call |
type |
type of analysis |
object |
object of class lavaan specified in the argument |
args |
specification of function arguments |
plot |
ggplot2 object when specifying |
result |
result table |
When specifying return = "transdat", the transformed data and when
specifying return = "bootsamp", the bootstrap samples are returned.
This function is based on modified copies of the functions bsBootMiss
from the semTools package by Terrence D. Jorgensen et al. (2026).
Takuya Yanagida
Bollen, K. A., & Stine, R. A. (1992). Bootstrapping goodness-of-fit measures in structural equation models. Sociological Methods & Research, 21(2), 205-229. https://doi.org/10.1177/0049124192021002004
Jorgensen, T. D., Pornprasertmanit, S., Schoemann, A. M., & Rosseel, Y. (2026). semTools: Useful tools for structural equation modeling. R package version 0.5-8. Retrieved from https://CRAN.R-project.org/package=semTools
Savalei, V., & Yuan, K.-H. (2009). On the model-based bootstrap with missing data: Obtaining a p-value for a test of exact fit. Multivariate Behavioral Research, 44(6), 741-763. https://doi.org/10.1080/00273170903333590
## Not run:
# Load lavaan package
library(lavaan)
# Holzinger and Swineford data set
dat <- HolzingerSwineford1939
# Introduce missing data
dat$x5 <- ifelse(dat$x1 <= quantile(dat$x1, 0.3), NA, dat$x5)
dat$x9 <- ifelse(is.na(dat$x5), NA, dat$x9)
# Model specification
model <- 'visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9'
# Model estimation
fit <- sem(model, data = dat, meanstructure = TRUE, std.lv = TRUE,
missing = "fiml", group = "school")
#————————————————————————————————————————————————————————————————————————————
# Bollen-Stine Bootstrapping with Incomplete Data
# Example 1: Default setting, transformation method 2, 500 replicates
# Plot bootstrap sampling distribution of the test statistic
boot.bs(fit, seed = 42, plot = TRUE)
#————————————————————————————————————————————————————————————————————————————
# Transformed Data and Bootstrap Samples
# Example 2: Return transformed data only
transdat <- boot.bs(fit, return = "transdat")
# Example 3: Return bootstrap samples only
bootsamp <- boot.bs(fit, return = "bootsamp")
#————————————————————————————————————————————————————————————————————————————
# Plot Bootstrap Sampling Distribution of Chi-Square Test Statistic
# Bollen-Stine Bootstrapping
object <- boot.bs(fit, seed = 42)
# Load ggplot2 package
library(ggplot2)
# Plot data
plotdat <- data.frame(chisq = object$boot.chisq)
# Example 3: Plot bootstrap sampling distribution, create plot manually
ggplot(plotdat, aes(chisq)) +
geom_histogram(aes(y = after_stat(density)), color = "black", alpha = 0.4, fill = "gray85") +
geom_density(color = "#0072B2") +
geom_vline(aes(xintercept = object$result$chisq, color = "Observed Test Statistic")) +
scale_x_continuous(name = expression(paste(chi^2, " Test Statistic")),
limits = c(0, max(c(plotdat$chisq, object$result$chisq), na.rm = TRUE))) +
scale_y_continuous(name = "Probability Density, f(x)", expand = expansion(mult = c(0, 0.05))) +
scale_color_manual(values = c("Observed Test Statistic" = "#CC79A7")) +
theme_bw() +
theme(legend.position = "bottom", legend.box.margin = margin(-12, 0, 0, 0),
legend.title = element_blank())
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.