Fit a list of models to a dataset.
Usage
fit_many(
model_list,
sem_out,
original = NULL,
parallel = FALSE,
ncores = max(parallel::detectCores(logical = FALSE) - 1, 1),
make_cluster_args = list(),
progress = TRUE,
verbose = TRUE
)
Arguments
- model_list
A list of parameter tables to be used by
lavaan::lavaan()
orupdate()
. Usually generated byget_add()
orget_drop()
.- sem_out
The output from an structural equation modeling function. It currently supports lavaan::lavaan objects only. Usually the one used in
model_set()
,get_add()
orget_drop()
to generate the list of models.- original
String. If provided, it should be a name of a model in
model_list
, with which differences in model degrees of freedom will be computed for other models. IfNULL
, the default, then the model insem_out
will be used to computed the differences in model degrees of freedom. IfNA
, then differences in model df will not be computed.- parallel
If
TRUE
, parallel processing will be used to fit the models. Default isFALSE
.- ncores
Numeric. The number of CPU cores to be used if
parallel
isTRUE
.- make_cluster_args
A list of named arguments to be passed to
parallel::makeCluster()
. Used by advanced users to configure the cluster ifparallel
isTRUE
. Default islist()
.- progress
Whether a progress bar will be displayed, implemented by the
pbapply
package. Default isTRUE
.- verbose
Whether additional messages will be displayed, such as the expected processing time. Default is
TRUE
.
Value
An object of the class
sem_outs
, a list with the
following major elements:
fit
: A named list oflavaan::lavaan()
output objects orupdate()
for fitting a model with the added parameters.change
: A numeric vector, of the same length asfit
. The change in model df for each fit compared to the original model. A positive number denotes one less free parameter. A negative number denotes one more free parameter or one less constraint.converged
: A named vector of boolean values, of the same length asfit
. Indicates whether each fit converged or not.post_check
: A named vector of boolean values, of the same length asfit
. Indicates whether the solution of each fit is admissible or not. Checked bylavaan::lavInspect()
with thewhat
argument set to"post.check"
.
Details
It receives a list of
models, defined by lavaan
parameter
tables (usually generated by
model_set()
, get_add()
or
get_drop()
),
and fit them to a dataset stored
in a lavaan
-class object.
This function is called by
model_set()
and usually users do
not need to call it. It is exported
for advanced users.
Author
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Examples
library(lavaan)
#> This is lavaan 0.6-18
#> lavaan is FREE software! Please report any bugs.
dat <- dat_path_model
mod <-
"
x3 ~ a*x1 + b*x2
x4 ~ a*x1
ab := a*b
"
fit <- sem(mod, dat_path_model, fixed.x = TRUE)
mod_to_add <- get_add(fit)
fit_many(mod_to_add, fit)
#>
#> Fit the 2 model(s) (duplicated models removed):
#>
#> Call:
#> fit_many(model_list = mod_to_add, sem_out = fit)
#>
#> Number of model(s) fitted: 2
#> Number of model(s) converged: 2
#> Number of model(s) passed post.check: 2
#>
#> The modification(s)/model(s):
#> add: x4~x2
#> add: (x3~x1),(x4~x1)