lav_data.RdUtility functions related to the Data slot
# update data slot with new data (of the same size)
lav_data_update(lavdata = NULL, newX = NULL, BOOT.idx = NULL, lavoptions = NULL)A lavdata object.
A list of (new) data matrices (per group) of the same size. They will replace the data stored in the internal dataslot.
A list of integers. If bootstrapping was used to produce the data in newX, use these indices to adapt the remaining slots.
A named list. The Options lsot from a lavaan object.
# generate syntax for an independence model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- cfa(HS.model, data=HolzingerSwineford1939)
#> Warning: lavaan->lav_model_vcov():
#> The variance-covariance matrix of the estimated parameters (vcov) does not
#> appear to be positive definite! The smallest eigenvalue (= -1.747972e-02)
#> is smaller than zero. This may be a symptom that the model is not
#> identified.
# extract data slot and options
lavdata <- fit@Data
lavoptions <- lavInspect(fit, "options")
# create bootstrap sample
boot.idx <- sample(x = nobs(fit), size = nobs(fit), replace = TRUE)
newX <- list(lavdata@X[[1]][boot.idx,])
# generate update lavdata object
newdata <- lav_data_update(lavdata = lavdata, newX = newX,
lavoptions = lavoptions)