sim_out | R Documentation |
Combine the outputs
of sim_data()
, fit_model()
,
and optionally gen_mc()
and/or
gen_boot()
to one
single object.
sim_out(data_all, ...)
## S3 method for class 'sim_out'
print(x, digits = 3, digits_descriptive = 2, fit_to_all_args = list(), ...)
data_all |
The output of
|
... |
Named arguments of
objects to be added to each
replication under the element
|
x |
The |
digits |
The numbers of digits displayed after the decimal. |
digits_descriptive |
The number of digits displayed after the decimal for the descriptive statistics table. |
fit_to_all_args |
A named list
of arguments to be passed to
|
It merges into one object the output
of sim_data()
, which is a list of
nrep
simulated datasets,
fit_model()
, which is a list of the
lavaan::sem()
output for the nrep
datasets, and optionally the output
of gen_mc()
or gen_boot()
, which is a list of the
R
sets of Monte Carlo or bootstrap estimates
based on the results of
fit_model()
. The list has nrep
elements, each element with the data,
the model fit
results, and optionally the Monte
Carlo estimates matched.
This object can then be used for testing effects of interests, which are further processed to estimate the power of this test.
The function sim_out()
is used by
the all-in-one function
power4test()
. Users usually do not
call this function directly, though
developers can use this function to
develop other functions for power
analysis, or to build their own
workflows to do the power analysis.
The function sim_out()
returns a sim_out
object, which
is a list of length equal to the
length of data_all
. Each element
of the list is a sim_data
object
with the element extra
added to
it. Other named elements will be
added under this name. For example.
the output of fit_model()
for this replication can be added
to fit
, under extra
. See
the description of the argument
...
for details.
The print
method of sim_out
returns x
invisibly. Called for
its side effect.
power4test()
# Specify the model
mod <-
"m ~ x
y ~ m + x"
# Specify the population values
es <-
"
y ~ m: m
m ~ x: m
y ~ x: n
"
# Generate the simulated datasets
dats <- sim_data(nrep = 5,
model = mod,
pop_es = es,
n = 100,
iseed = 1234)
# Fit the population model to each dataset
fits <- fit_model(dats)
# Combine the results to one object
sim_out_all <- sim_out(data_all = dats,
fit = fits)
sim_out_all
# Verify that the elements of fits are set to extra$fit
library(lavaan)
parameterEstimates(fits[[1]])
parameterEstimates(sim_out_all[[1]]$extra$fit)
parameterEstimates(fits[[2]])
parameterEstimates(sim_out_all[[2]]$extra$fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.