SimSem objects created with the model function. In this function, parameters are drawn from the specified data-generation model and used to create data, specified missingness (if any) is imposed, and data are analyzed using the specified SimSem analysis model object. Provides a SimResult ) object as ouput, which summarizes analyses across replications. Data can be transformed using the datafun argument. Additional output can be extracted using the outfun argument. Paralleled processing can be enabled using the multicore argument. The sim function can also be used to obtain raw data using the dataOnly argument, to analyze pre-existing data using the rawData argument, and to simulate data that follows the distribution of a real data set using the rawData argument.sim(nRep, model, n, generate = NULL, rawData = NULL, miss = NULL, datafun=NULL, outfun=NULL,
pmMCAR = NULL, pmMAR = NULL, facDist = NULL, indDist = NULL, errorDist = NULL, sequential = FALSE,
modelBoot = FALSE, realData = NULL, maxDraw = 50, misfitType = "f0",
misfitBounds = NULL, averageNumMisspec = FALSE, optMisfit=NULL, optDraws = 50, createOrder = c(1, 2, 3),
aux = NULL, seed = 123321, silent = FALSE, multicore = FALSE, cluster = FALSE, numProc = NULL,
paramOnly = FALSE, dataOnly=FALSE, smartStart=FALSE, ...)n, pmMCAR, or pmMAR arguments are specified as lists, the number of replications will default to the length of the list(s), and nRep need not be specified.SimSem object created by model. If the generate argument is not specified, then the object in the model argument will be used for both data gen argument can also be specified as a random distribution object; if any resulting values are non-integers, the decimal will be rounded.SimSem object created using the model function. If included, this argument will be used to generate data instead of the code{SimSem template.miss function.lavaan output at each replication. Output from this function in each replication will be saved in the simulation output (SimResult ), and can beobjMissing argument is only r=>objMissing argument is only required when =>SimDataDist objects or a single SimDataDist object to give all factors the same distribution. Use when sequential is SimDataDist objects or a single SimDataDist object to give all indicators the same distribution. Use when sequential is SimDataDist indicating the distribution of errors. If a single SimDataDist is specified, each error will be genrated with that distribution.TRUE, a sequential method is used to generate data in which factor data is generated first, and is subsequently applied to a set of equations to obtain the indicator data. If FALSE, data is generated directly from model-implierealData argument). See draw for further information.TRUE, the provided fit will be divided by the number of misspecified parameters.TRUE, suppress warnings.TRUE, multiple processors within a computer will be utilized.NULL, the package will find the maximum number of processors.TRUE, only the parameters from each replication will be returned.TRUE, only the raw data generated from each replication will be returned.SimResult )SimResult for the resulting output descriptionloading <- 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")
# In reality, more than 5 replications are needed.
Output <- sim(5, CFA.Model,n=200)
summary(Output)
# Example of data transformation: Transforming to standard score
fun1 <- function(data) {
temp <- scale(data)
temp[,"group"] <- data[,"group"]
as.data.frame(temp)
}
# Example of additional output: Extract modification indices from lavaan
fun2 <- function(out) {
inspect(out, "mi")
}
# In reality, more than 5 replications are needed.
Output <- sim(5, CFA.Model,n=200,datafun=fun1, outfun=fun2)
summary(Output)
# Get modification indices
getExtraOutput(Output)Run the code above in your browser using DataLab