Learn R Programming

simsem (version 0.2-8)

runFit: Build a Monte Carlo simulation that the data-generation parameters are from the result of analyzing real data

Description

This function will analyze real data and use the result of the analysis to simulate data. Those simulated data will be analyzed by the same model. The result of the analyses will be saved in the result object, SimResult.

Usage

runFit(model, data, nRep=1000, misspec=new("NullSimMisspec"), 
	maxDraw=100, sequential=NA, facDist=new("NullSimDataDist"), 
	errorDist=new("NullSimDataDist"), indDist=new("NullSimDataDist"), 
	modelBoot=FALSE, seed=123321, silent=FALSE, multicore=FALSE, 
	cluster=FALSE, numProc=NULL, empiricalMissing=TRUE, 
	missModel=new("NullSimMissing"), usedStd=TRUE, analyzeModel=NULL)

Arguments

model
Model object used in analyzing the real data and simulated data (if the analyzeModel below is not specified).
data
Real data that will be used in the analysis
nRep
Number of replications.
misspec
Model misspecification matrices that are created by simMisspecCFA, simMisspecPath, or simMi
maxDraw
The maximum number of random drawn parameters and misspecification model until all parameters in the model are eligible (no negative error variance, standardized coefficients over 1).
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 for a distribution of factors. Use when sequential is TRUE.
errorDist
A SimDataDist for a distribution of measurement errors. Use when sequential is TRUE
indDist
A SimDataDist for a distribution of indicators. Use when sequential is FALSE.
modelBoot
Use a model-based bootstrap approach to create data. See simData for further details.
seed
Seed number
silent
TRUE if users do not wish to print number of replications during running the function.
multicore
Use multiple processors within a computer. Specify as TRUE to use it.
cluster
Not applicable now. Use for specify nodes in hpc in order to be parallelizable.
numProc
Number of processors for using multiple processors. If it is NULL, the package will find the maximum number of processors.
empiricalMissing
Use the missing pattern from the real data imposing on the simulated data if empiricalMissing=TRUE. If FALSE, the missing pattern will be generated from the missing object specified in the missModel argument. If we n
missModel
A missing object used for data simulation. Only numImps attribute within the missing object is used if empiricalMissing=TRUE. All attributes are used (for generating missing data) if empiricalMissing=FALSE.
usedStd
The standardized parameters are used for data generation if usedStd=TRUE. If usedStd=FALSE, unstandardized parameters are used.
analyzeModel
The SimModel that will be used to analyze the simulated data. If NULL, the model object from the model argument is used.

Value

  • SimResult that saves analysis results from simulated data.

Details

This function can be used to implement the Monte Carlo approach for evaluating model fit proposed by Millsap (in press). This function will use the obtained parameter estimates as the real population parameters in a simulation study, put a trivial model misspecification in the real parameters, generate multiple simulated data, analyze those simulated data, and put it in the result object, SimResult. The fit indices distribution in the result object can be used for the model fit evaluation. The useful functions for model fit evaluation are plotCutoff, getCutoff, and pValue. If modelBoot is TRUE, the function will use the Bollen-Stine bootstrap method for data generation. See simData for further details of the Bollen-Stine bootstrap approach.

References

  • Millsap, R.E. (in press). A simulation paradigm for evaluating model fit. In M. Edwards and R. MacCallum (Eds.)Current Issues in the Theory and Application of Latent Variable Models.New York: Routledge.

See Also

  • SimModelfor analysis model specification
  • SimResultfor the type of resulting object

Examples

Run this code
library(lavaan)
loading <- matrix(0, 9, 3)
loading[1:3, 1] <- NA
loading[4:6, 2] <- NA
loading[7:9, 3] <- NA
model <- simParamCFA(LY=loading)
SimModel <- simModel(model, indLab=paste("x", 1:9, sep=""))
u2 <- simUnif(-0.2, 0.2)
loading.trivial <- matrix(NA, 9, 3)
loading.trivial[is.na(loading)] <- 0
LY.trivial <- simMatrix(loading.trivial, "u2")
mis <- simMisspecCFA(LY = LY.trivial)
Output <- runFit(SimModel, HolzingerSwineford1939, 5, mis)
summary(Output)

out <- run(SimModel, HolzingerSwineford1939)
Output2 <- runFit(out, HolzingerSwineford1939, 5, mis)

# Bollen-Stine Bootstrap
Output3 <- runFit(out, HolzingerSwineford1939, 5, modelBoot=TRUE)

# Bollen-Stine Bootstrap with trivial misspecification
Output4 <- runFit(out, HolzingerSwineford1939, 5, mis, modelBoot=TRUE)

# Example with multiple imputation
library(lavaan)
loading <- matrix(0, 11, 3)
loading[1:3, 1] <- NA
loading[4:7, 2] <- NA
loading[8:11, 3] <- NA
path <- matrix(0, 3, 3)
path[2:3, 1] <- NA
path[3, 2] <- NA
errorCov <- diag(NA, 11)
facCov <- diag(3)
param <- simParamSEM(LY=loading, BE=path, TE=errorCov, PS=facCov)

miss <- simMissing(pmMCAR=0.03, numImps=5)
usedData <- run(miss, PoliticalDemocracy)

model <- simModel(param, indLab=c(paste("x", 1:3, sep=""), paste("y", 1:8, sep="")))
out <- run(model, usedData, miss)
output <- runFit(model, usedData, 5, missModel=miss)
pValue(out, output)

Run the code above in your browser using DataLab