Creates a data generation and analysis template (lavaan parameter table) for simulations with the lavaan
result. Model misspecification may be added into the template by a vector, a matrix, or a list of vectors or matrices (for multiple groups).
1 2 3 4 
object 
A 
std 
If TRUE, use the resulting standardized parameters for data generation. If FALSE, use the unstandardized parameters for data generation. 
LY 
Model misspecification in factor loading matrix from endogenous factors to Y indicators (need to be a matrix or a list of matrices). 
PS 
Model misspecification in residual covariance matrix among endogenous factors (need to be a symmetric matrix or a list of symmetric matrices). 
RPS 
Model misspecification in residual correlation matrix among endogenous factors (need to be a symmetric matrix or a list of symmetric matrices). 
TE 
Model misspecification in measurement error covariance matrix among Y indicators (need to be a symmetric matrix or a list of symmetric matrices). 
RTE 
Model misspecification in measurement error correlation matrix among Y indicators (need to be a symmetric matrix or a list of symmetric matrices). 
BE 
Model misspecification in regression coefficient matrix among endogenous factors (need to be a symmetric matrix or a list of symmetric matrices). 
VTE 
Model misspecification in measurement error variance of indicators (need to be a vector or a list of vectors). 
VY 
Model misspecification in total variance of indicators (need to be a vector or a list of vectors). NOTE: Either measurement error variance or indicator variance is specified. Both cannot be simultaneously specified. 
VPS 
Model misspecification in residual variance of factors (need to be a vector or a list of vectors). 
VE 
Model misspecification in total variance of of factors (need to be a vector or a list of vectors). NOTE: Either residual variance of factors or total variance of factors is specified. Both cannot be simulatneously specified. 
TY 
Model misspecification in measurement intercepts of Y indicators. (need to be a vector or a list of vectors). 
AL 
Model misspecification in endogenous factor intercept (need to be a vector or a list of vectors). 
MY 
Model misspecification in overall Y indicator means. (need to be a vector or a list of vectors). NOTE: Either measurement intercept of indicator mean can be specified. Both cannot be specified simultaneously. 
ME 
Model misspecification in total mean of endogenous factors (need to be a vector or a list of vectors). NOTE: Either endogenous factor intercept or total mean of endogenous factor is specified. Both cannot be simultaneously specified. 
KA 
Model misspecification in regression coefficient matrix from covariates to indicators (need to be a matrix or a list of matrices). KA is applicable when exogenous covariates are specified only. 
GA 
Model misspecification in regression coefficient matrix from covariates to factors (need to be a matrix or a list of matrices). KA is applicable when exogenous covariates are specified only. 
SimSem
object that contains the data generation template (@dgen
) and analysis template (@pt
).
Sunthud Pornprasertmanit (psunthud@gmail.com)
model
To build data generation and data analysis template for simulation.
sim
for simulations using the SimSem
template.
generate
To generate data using the SimSem
template.
analyze
To analyze real or generated data using the SimSem
template.
draw
To draw parameters using the SimSem
template.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  library(lavaan)
HS.model < ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit < cfa(HS.model, data=HolzingerSwineford1939)
# Create data generation and data analysis model from lavaan
# Data generation is based on standardized parameters
datamodel1 < model.lavaan(fit, std=TRUE)
# Data generation is based on unstandardized parameters
datamodel2 < model.lavaan(fit, std=FALSE)
# Data generation model with misspecification on crossloadings
crossload < matrix("runif(1, 0.1, 0.1)", 9, 3)
crossload[1:3, 1] < 0
crossload[4:6, 2] < 0
crossload[7:9, 3] < 0
datamodel3 < model.lavaan(fit, std=TRUE, LY=crossload)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.