model_set {modelbpp} | R Documentation |
Identify neighboring models, fit them, and return the BIC posterior probabilities.
model_set(
sem_out,
partables = NULL,
model_set_out = NULL,
prior_sem_out = NULL,
must_add = NULL,
must_not_add = NULL,
must_drop = NULL,
must_not_drop = NULL,
remove_constraints = TRUE,
exclude_error_cov = TRUE,
exclude_feedback = TRUE,
exclude_xy_cov = TRUE,
df_change_add = 1,
df_change_drop = 1,
remove_duplicated = TRUE,
fit_models = ifelse(!is.null(model_set_out$fit), FALSE, TRUE),
compute_bpp = TRUE,
original = "original",
parallel = FALSE,
ncores = max(parallel::detectCores(logical = FALSE) - 1, 1),
make_cluster_args = list(),
progress = TRUE,
verbose = TRUE,
skip_check_sem_out = FALSE,
drop_equivalent_models = TRUE
)
gen_models(
sem_out,
must_add = NULL,
must_not_add = NULL,
must_drop = NULL,
must_not_drop = NULL,
remove_constraints = TRUE,
exclude_error_cov = TRUE,
df_change_add = 1,
df_change_drop = 1,
remove_duplicated = TRUE,
progress = TRUE,
output = c("partables", "model_set")
)
sem_out |
It can be the output from an SEM function. Currently it supports lavaan::lavaan objects only. If it is a named list of lavaan::lavaan objects, then all arguments for model generation will be ignored, and models will not be refitted. Users need to ensure that the models can be meaningfully compared because they will not be checked. |
partables |
A |
model_set_out |
If set to
the output of a previous call
to |
prior_sem_out |
The prior of the
model fitted in |
must_add |
A character vector
of parameters, named in
|
must_not_add |
A character
vector of parameters, named in
|
must_drop |
A character vector
of parameters, named in
|
must_not_drop |
A character
vector of parameters, named in
|
remove_constraints |
Whether equality constraints will be removed. Default is “TRUE'. |
exclude_error_cov |
Exclude
error covariances of indicators.
Default is |
exclude_feedback |
Exclude
paths that will result in a feedback
loop. For example, if there is
path from |
exclude_xy_cov |
Exclude
covariance between two variables,
in which one has a path to another.
For example, if there is
path from |
df_change_add |
How many degrees of freedom (df) away in the list. All models with df change less than or equal to this number will be included, taking into account requirements set by other arguments. Default is 1. |
df_change_drop |
How many degrees of freedom away in the list. All models with df change less than or equal to this number will be included, taking into account requirements set by other arguments. Default is 1. |
remove_duplicated |
If |
fit_models |
If |
compute_bpp |
If |
original |
String. The name of the
original (traget) model. Default is
|
parallel |
If |
ncores |
Numeric. The number of
CPU cores to be used if |
make_cluster_args |
A list of
named arguments to be passed to
|
progress |
Whether a progress
bar will be displayed, implemented
by the |
verbose |
Whether additional
messages will be displayed, such
as the expected processing time.
Default is |
skip_check_sem_out |
If |
drop_equivalent_models |
If
|
output |
If |
It computes the BIC posterior probabilities of a set of models by the method presented in Wu, Cheung, and Leung (2020).
First, a list of model is identified
based on user-specified criteria.
By default, models differ from a fitted
model by one degree of freedom,
the 1-df-away neighboring models,
will be found using get_add()
and get_drop.
Second, these models will be fitted to the sample dataset, and their BICs will be computed.
Third, their BIC posterior
probabilities will be computed
using their BICs. By default,
equal prior
probabilities for all the models
being fitted will be assumed in
the current version. This can be
changed by prior_sem_out
.
The results can then be printed,
with the models sorted by descending
order of BIC posterior
probabilities. The results can
also be visualized using
model_graph()
.
The function model_set()
returns an object of the class
model_set
, a list with the following
major elements:
models
: A named list of parameter
tables. Each represent the models
identified.
bic
: A numeric vector, of the
same length as model
. The BIC of
each model.
postprob
: A numeric vector, of
the same length as model
. The
BIC posterior probability of each
model.
fit
: A named list of
lavaan::lavaan()
output objects
or update()
for fitting a model
with the added parameters, of the
same length as model
.
change
: A numeric vector, of the
same length as model
. The change
in model df for each fit. 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
as model
. Indicates whether each
fit converged or not.
post_check
: A named vector of
boolean values, of the same length
as model
. Indicates whether the
solution of each fit is admissible
or not. Checked by
lavaan::lavInspect()
.
The object returned by gen_models()
depends on the argument output
.
See the argument output
for the
details
model_set()
: Compute the BPPs of a list of models.
Can generate the models and/or fit the models. Can also
accept pregenerated models, or just update BPPs.
gen_models()
: Generate a list of models (parameter tables).
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Wu, H., Cheung, S. F., & Leung, S. O. (2020). Simple use of BIC to assess model selection uncertainty: An illustration using mediation and moderation models. Multivariate Behavioral Research, 55(1), 1–16. doi:10.1080/00273171.2019.1574546
library(lavaan)
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)
out <- model_set(fit)
out