exportData {simsem}R Documentation

Export data sets for analysis with outside SEM program.

Description

This function can be used to export data created from a set of parameters created from draw, called a codeparamSet. This function can export data to be analyzed with either Mplus or LISREL.

Usage

exportData(nRep, model, n, program = "Mplus", fileStem = "sim", miss = NULL, 
	missCode = -999, datafun=NULL, pmMCAR = NULL, pmMAR = NULL, facDist = NULL, 
	indDist = NULL, errorDist = NULL, sequential = FALSE, modelBoot = FALSE, 
	realData = NULL, maxDraw = 50, misfitType = "f0", misfitBounds = NULL, 
	averageNumMisspec = NULL, optMisfit=NULL, optDraws = 50, seed = 123321, 
	silent = FALSE, multicore = FALSE, numProc = NULL,  params = FALSE)

Arguments

nRep

Number of replications. Users can specify as NULL and specify n, pmMCAR, and pmMAR

model

SimSem object created by model. Will be used to generate data and analyze it.

n

Sample size. This argument is not necessary except the user wish to vary sample size across replications. The sample size here is a vector of sample size in integers. For the random distribution object, if the resulting value has decimal, the value will be rounded.

program

Statistical program that will be used to analyze data. Currently only Mplys and LISREL are supported.

fileStem

The stem of the filename(s) for file(s) output. For example, a fileStem of "sim" will result in files named sim1.dat, sim2.dat, etc.

miss

Missing data handling template, created by the function miss.

missCode

Missing data code, NA will be replaced by this value for all missing values in exported data.

datafun

Function to be applied to generated data set at each replication.

pmMCAR

The percent completely missing at random. This argument is not necessary except the user wish to vary percent missing completely at random across replications. The pmMCAR here is a vector of percent missing, which the values can be in between 0 and 1 only. The specification of objMissing is not needed (but is needed if users wish to specify complex missing value data generation or wish to use multiple imputation).

pmMAR

The percent missing at random. This argument is not necessary except the user wish to vary percent missing at random across replications. The pmMAR here is a vector of percent missing, which the values can be in between 0 and 1 only. The specification of objMissing is not needed (but is needed if users wish to specify complex missing value data generation or wish to use multiple imputation).

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.

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.

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.

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 covariance of indicators.

modelBoot

When specified, a model-based bootstrap is used for data generation. See draw 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.

maxDraw

Integer specifying the maximum number of attempts to draw a valid set of parameters (no negative error variance, standardized coefficients over 1).

misfitType

Character vector indicating the fit measure used to assess the misfit of a set of parameters. Can be "f0", "rmsea", "srmr", or "all".

misfitBounds

Vector that contains upper and lower bounds of the misfit measure. Sets of parameters drawn that are not within these bounds are rejected.

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 returned.

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.

seed

Random number seed. Reproducibility across multiple cores or clusters is ensured using R'Lecuyer package.

silent

If TRUE, suppress warnings.

multicore

Use multiple processors within a computer. Specify as TRUE to use it.

numProc

Number of processors for using multiple processors. If it is NULL, the package will find the maximum number of processors.

params

If TRUE, the parameters from each replication will be returned.

Value

Text files saved to the current working directory. If program = "Mplus" one file is output for each replication, and an extra file is output with the names of all saved data sets (this file can be used with the MONTECARLO command in Mplus). If program = "LISREL" one file is output with each replication stacked on top of the next (this file can be used with the RP command in LISREL). If program = TRUE, a list of parameter values for each replication is returned.

Author(s)

Alexander M. Schoemann (East Carolina University; schoemanna@ecu.edu)

Examples

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")

## Export 20 replications to an external data file (not run).
#exportData(20, CFA.Model, 200)

[Package simsem version 0.5-16 Index]