Fit List of Latent Variable Models
lavaanList.RdFit the same latent variable model, for a (potentially large) number of datasets.
Usage
lavaanList(model = NULL, dataList = NULL, dataFunction = NULL,
dataFunction.args = list(), ndat = length(dataList), cmd = "lavaan",
..., store.slots = c("partable"), FUN = NULL, show.progress = FALSE,
store.failed = FALSE, parallel = c("no", "multicore", "snow"),
ncpus = max(1L, parallel::detectCores() - 1L), cl = NULL, iseed = NULL)
semList(model = NULL, dataList = NULL, dataFunction = NULL,
dataFunction.args = list(), ndat = length(dataList),
..., store.slots = c("partable"), FUN = NULL, show.progress = FALSE,
store.failed = FALSE, parallel = c("no", "multicore", "snow"),
ncpus = max(1L, parallel::detectCores() - 1L), cl = NULL, iseed = NULL)
cfaList(model = NULL, dataList = NULL, dataFunction = NULL,
dataFunction.args = list(), ndat = length(dataList),
..., store.slots = c("partable"), FUN = NULL, show.progress = FALSE,
store.failed = FALSE, parallel = c("no", "multicore", "snow"),
ncpus = max(1L, parallel::detectCores() - 1L), cl = NULL, iseed = NULL)Arguments
- model
A description of the user-specified model. Typically, the model is described using the lavaan model syntax. See
model.syntaxfor more information. Alternatively, a parameter table (eg. the output of thelavParTable()function) is also accepted.- dataList
List. Each element contains a full data frame containing the observed variables used in the model.
- dataFunction
Function. A function that generated a full data frame containing the observed variables used in the model. It can also be a matrix, if the columns are named.
- dataFunction.args
List. Optional list of arguments that are passed to the
dataFunctionfunction.- ndat
Integer. The number of datasets that should be generated using the
dataFunctionfunction.- cmd
Character. Which command is used to run the sem models. The possible choices are
"sem","cfa"or"lavaan", determining how we deal with default options.- ...
Other named arguments for
lavaanfunction.- store.slots
Character vector. Which slots (from a lavaan object) should be stored for each dataset? The possible choices are
"timing","partable","data","samplestats","vcov","test","optim","h1","loglik", or"implied". Finally,"all"selects all slots.- FUN
Function. A function which when applied to the
lavaanobject returns the information of interest.- store.failed
Logical. If
TRUE, write (to tempdir()) the dataset and (if available) the fitted object when the estimation for a particular dataset somehow failed. This will allow posthoc inspection of the problem.- parallel
The type of parallel operation to be used (if any). If missing, the default is
"no".- ncpus
Integer. The number of processes to be used in parallel operation: typically one would chose this to the number of available CPUs.
- cl
An optional parallel or snow cluster for use if
parallel = "snow". If not supplied, a cluster on the local machine is created for the duration of thelavaanListcall.- iseed
An integer to set the seed. Or NULL if no reproducible seeds are needed. To make this work, make sure the first RNGkind() element is
"L'Ecuyer-CMRG". You can check this by typingRNGkind()in the console. You can set it by typingRNGkind("L'Ecuyer-CMRG"), before the lavaanList functions are called.- show.progress
If
TRUE, show information for each dataset.
Value
An object of class lavaanList, for which several methods
are available, including a summary method.
See also
class lavaanList
Examples
# The Holzinger and Swineford (1939) example
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
# a data generating function
generateData <- function() lavSimulateData(HS.model, sample.nobs = 100)
set.seed(1234)
fit <- semList(HS.model, dataFunction = generateData, ndat = 5,
store.slots = "partable")
# show parameter estimates, per dataset
coef(fit)
#> [,1] [,2] [,3] [,4] [,5]
#> visual=~x2 0.91791609 0.92199215 0.92779203 0.99754819 0.99931892
#> visual=~x3 0.72505352 0.91797204 1.03929219 0.87855241 1.23528238
#> textual=~x5 0.91799277 1.09583845 0.95492722 0.83559376 0.74619256
#> textual=~x6 0.93577780 1.52055851 2.18398470 0.62835639 0.91749152
#> speed=~x8 1.32561097 0.89057977 1.52617465 0.76516216 0.93819692
#> speed=~x9 0.88858749 0.93360004 0.90851427 0.73308589 0.81127187
#> x1~~x1 0.72211092 0.60247837 0.91198778 0.85708214 1.22479435
#> x2~~x2 0.75299324 1.28994192 1.16727712 1.14479769 1.26660493
#> x3~~x3 1.15434338 1.03954685 0.94474628 0.71863907 0.80241954
#> x4~~x4 0.82758068 1.48125061 1.22981959 0.31992506 0.62025576
#> x5~~x5 0.74164972 1.05062993 1.05305411 0.98847761 1.13842967
#> x6~~x6 0.96232185 0.98753272 0.21967451 1.42791143 1.08105890
#> x7~~x7 1.34412447 0.82389693 1.38099916 0.77236139 0.99883918
#> x8~~x8 0.75586122 0.94070899 0.66176461 1.08818301 0.54392141
#> x9~~x9 1.25410648 1.10666300 0.98451747 0.66116027 0.92452652
#> visual~~visual 1.33868030 0.86134536 0.53604774 1.16373925 0.74400241
#> textual~~textual 1.03360092 0.52264499 0.37673118 1.58292303 1.27528568
#> speed~~speed 0.89982900 1.04999825 0.63539384 1.88852048 1.08798753
#> visual~~textual 0.13953853 -0.08091131 0.01454512 -0.17113781 0.16805796
#> visual~~speed 0.01923061 0.11188598 0.07747246 -0.07639808 -0.05479958
#> textual~~speed 0.12411009 -0.06291862 0.10011408 0.23035747 -0.13796677