Learn R Programming

lavaan (version 0.6-11)

lavaanList: Fit List of Latent Variable Models

Description

Fit 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.syntax for more information. Alternatively, a parameter table (eg. the output of the lavaanify() 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 dataFunction function.

ndat

Integer. The number of datasets that should be generated using the dataFunction function.

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 lavaan function.

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 '>lavaan object 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 the lavaanList call.

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 typing RNGkind() in the console. You can set it by typing RNGkind("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

Run this code
# NOT RUN {
# 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() simulateData(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)
# }

Run the code above in your browser using DataLab