Learn R Programming

lavaan (version 0.7-2)

lavaanList: Fit List of Latent Variable Models

Description

Fit the same latent variable model to a (potentially large) number of datasets.

Usage

lavaanList(model = NULL, data_list = NULL, data_function = NULL, 
    data_function_args = list(), ndat = length(data_list), cmd = "lavaan", 
    ..., store_slots = c("partable"), fun = NULL, show_progress = FALSE,
    store_failed = FALSE, parallel = c("no", "multicore", "snow"), 
    ncpus = min(2L, max(1L, parallel::detectCores() - 1L, na.rm = TRUE)),
    cl = NULL, iseed = NULL)

semList(model = NULL, data_list = NULL, data_function = NULL, data_function_args = list(), ndat = length(data_list), ..., store_slots = c("partable"), fun = NULL, show_progress = FALSE, store_failed = FALSE, parallel = c("no", "multicore", "snow"), ncpus = min(2L, max(1L, parallel::detectCores() - 1L, na.rm = TRUE)), cl = NULL, iseed = NULL)

cfaList(model = NULL, data_list = NULL, data_function = NULL, data_function_args = list(), ndat = length(data_list), ..., store_slots = c("partable"), fun = NULL, show_progress = FALSE, store_failed = FALSE, parallel = c("no", "multicore", "snow"), ncpus = min(2L, max(1L, parallel::detectCores() - 1L, na.rm = TRUE)), cl = NULL, iseed = NULL)

Value

An object of class lavaanList, for which several methods are available, including a summary method.

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 (e.g., the output of the lavParTable() function) is also accepted.

data_list

List. Each element contains a full data frame containing the observed variables used in the model.

data_function

Function. A function that generates a full data frame containing the observed variables used in the model. It can also be a matrix, if the columns are named.

data_function_args

List. Optional list of arguments that are passed to the data_function function.

ndat

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

cmd

Character. The command used to run the SEM models. The possible choices are "sem", "cfa" or "lavaan", which determine how the default options are handled.

...

Other named arguments for the 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 failed for some reason. This allows post hoc 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: By default, this is 2 (following CRAN policy). You may set this to a higher value (for example, the number of available CPUs) if you wish to use more processes.

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.

See Also

class lavaanList

Examples

Run this code
# 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, data_function = generateData, ndat = 5,
               store_slots = "partable")

# show parameter estimates, per dataset
coef(fit)

Run the code above in your browser using DataLab