Learn R Programming

simsem (version 0.4-6)

generate: Generate data using SimSem template

Description

This function can be used to generate random data based on the SimSem template. Some notable features include fine control of misspecification and misspecification optimization, as well as the ability to generate non-normal data. When using simsem for simulations, this function is used internally to generate data in the function sim, and can be helpful for debugging, or in creating data for use with other analysis programs.

Usage

generate(model, n, maxDraw=50, misfitBounds=NULL, misfitType="f0",
	averageNumMisspec=FALSE, optMisfit=NULL, optDraws=50, 
	createOrder = c(1, 2, 3), indDist=NULL, sequential=FALSE,	
	facDist=NULL, errorDist=NULL, indLab=NULL, modelBoot=FALSE, 
	realData=NULL, params=FALSE)

Arguments

model
A SimSem object.
n
Integer of sample size.
maxDraw
Integer specifying the maximum number of attempts to draw a valid set of parameters (no negative error variance, standardized coefficients over 1).
misfitBounds
Vector that contains upper and lower bounds of the misfit measure. Sets of parameters drawn that are not within these bounds are rejected.
misfitType
Character vector indicating the fit measure used to assess the misfit of a set of parameters. Can be "f0", "rmsea", "srmr", or "all".
averageNumMisspec
If TRUE, the provided fit will be divided by the number of misspecified parameters.
optMisfit
Character vector of either "min" or "max" indicating either maximum or minimum optimized misfit. If not null, the set of parameters out of the number of draws in "optDraws" that has either the maximum or minimum misfit of the given misfit type will be ret
optDraws
Number of parameter sets to draw if optMisfit is not null. The set of parameters with the maximum or minimum misfit will be returned.
createOrder
The order of 1) applying equality/inequality constraints, 2) applying misspecification, and 3) fill unspecified parameters (e.g., residual variances when total variances are specified). The specification of this argument is a vector of different orders of
indDist
A SimDataDist object or list of objects for a distribution of indicators. If one object is passed, each indicator will have the same distribution. Use when sequential is FALSE.
sequential
If TRUE, use a sequential method to create data such that the data from factor are generated first and apply to a set of equations to obtain the data of indicators. If FALSE, create data directly from model-implied mean and covar
facDist
A SimDataDist object or list of objects for the distribution of factors. If one object is passed, all factors will have the same distribution. Use when sequential is TRUE.
errorDist
An object or list of objects of type SimDataDist indicating the distribution of errors. If a single SimDataDist is specified, each error will be genrated with that distribution.
indLab
A vector of indicator labels. When not specified, the variable names are x1, x2, ... xN.
modelBoot
When specified, a model-based bootstrap is used for data generation. See details for further information. This argument requires real data to be passed to realData.
realData
A data.frame containing real data. The data generated will follow the distribution of this data set.
params
If TRUE, return the parameters drawn along with the generated data set. Default is FALSE.

Value

  • A data.frame containing simulated data from the data generation template. A variable "group" is appended indicating group membership.

Details

This function will use mvrnorm function ito create data from model implied covariance matrix if the data distribution object (SimDataDist) is not specified. It the data distribution object is specified, the Gaussian copula model is used. See SimDataDist for further details. For the model-based bootstrap, the transformation proposed by Yung & Bentler (1996) is used. This procedure is the expansion from the Bollen and Stine (1992) bootstrap including a mean structure. The model-implied mean vector and covariance matrix with trivial misspecification will be used in the model-based bootstrap if misspec is specified. See page 133 of Bollen and Stine (1992) for a reference. Internally, parameters are first drawn, and data is then created from these parameters. Both of these steps are available via the draw and createData functions respectively.

References

Bollen, K. A., & Stine, R. A. (1992). Bootstrapping goodness-of-fit measures in structural equation models. Sociological Methods and Research, 21, 205-229. Yung, Y.-F., & Bentler, P. M. (1996). Bootstrapping techniques in analysis of mean and covariance structures. In G. A. Marcoulides & R. E. Schumacker (Eds.), Advanced structural equation modeling: Issues and techniques (pp. 195-226). Mahwah, NJ: Erlbaum.

See Also

  • drawTo draw parameters using theSimSemtemplate.
  • createDataTo generate random data using a set of parameters fromdraw

Examples

Run this code
loading <- matrix(0, 6, 2)
loading[1:3, 1] <- NA
loading[4:6, 2] <- NA
LY <- bind(loading, 0.7)

latent.cor <- matrix(NA, 2, 2)
diag(latent.cor) <- 1
RPS <- binds(latent.cor, 0.5)

RTE <- binds(diag(6))

VY <- bind(rep(NA,6),2)

CFA.Model <- model(LY = LY, RPS = RPS, RTE = RTE, modelType = "CFA")

dat <- generate(CFA.Model,200)

Run the code above in your browser using DataLab