fit_model | R Documentation |
Get the output of
sim_data()
and fit a model to each
of the stored datasets.
fit_model(
data_all = NULL,
model = NULL,
fit_function = "lavaan",
arg_data_name = "data",
arg_model_name = "model",
arg_group_name = "group",
...,
fit_out = NULL,
parallel = FALSE,
progress = FALSE,
ncores = max(1, parallel::detectCores(logical = FALSE) - 1)
)
data_all |
The output
of |
model |
The model to be fitted.
If |
fit_function |
The function to
be used to fit the model. Can also
be a string: |
arg_data_name |
The name of the
argument of |
arg_model_name |
The name of
the argument of |
arg_group_name |
The name of
the argument of |
... |
Optional arguments to be
passed to |
fit_out |
If set to a |
parallel |
If |
progress |
If |
ncores |
The number of CPU cores to use if parallel processing is used. |
By default, the function fit_model()
extracts the model
stored in the output of sim_data()
,
fits the model to each dataset
simulated using fit_function
,
default to "lavaan"
and
lavaan::sem()
will be called,
and returns the results.
If the datasets
were generated from a multigroup
model when calling sim_data()
,
a multigroup model is fitted.
An object of the class fit_out
,
which is a list of the output of
fit_function
(lavaan::sem()
by default). If an error occurred
when fitting the model to a dataset,
then this element will be the error
message from the fit function.
fit_model()
This function is used by the
all-in-one function power4test()
.
Users usually do not call this
function directly, though
developers can use this function to
customize the model fitting step in
power analysis.
See power4test()
for
the all-in-one function that uses
this function, and sim_data()
for the function generating datasets
for this function.
# Specify the population model
mod <-
"m ~ x
y ~ m + x"
# Specify the effect sizes (population parameter values)
es <-
"
y ~ m: m
m ~ x: m
y ~ x: n
"
# Generate several simulated datasets
data_all <- sim_data(nrep = 5,
model = mod,
pop_es = es,
n = 100,
iseed = 1234)
# Fit the population model to each datasets
fit_all <- fit_model(data_all)
fit_all[[1]]
# Fit the population model using the MLR estimator
fit_all_mlr <- fit_model(data_all,
estimator = "MLR")
fit_all_mlr[[1]]
# Fit a model different from the population model,
# with the MLR estimator
mod2 <-
"m ~ x
y ~ m"
fit_all_mlr2 <- fit_model(data_all,
mod2,
estimator = "MLR")
fit_all_mlr2[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.