The package requires the development version of cSEM (version 0.1.0:9000 as Feb. 2020). To install the development version use:
# install.packages("devtools") devtools::install_github("M-E-Rademaker/cSEM")
To install the development version of cSEM.DGP
use:
# install.packages("devtools") devtools::install_github("M-E-Rademaker/cSEM.DGP")
The best place to get started is the cSEM.DGP website.
Generate data for structural equation models including up to eight constructs. Data generation is based on parameter values given in lavaan model syntax.
In addition to supplying numeric values, variable values (symbolic names) for parameters are allowed. To achieve this, the package makes use of lavaan's labeling capabilities. Users may replace a given parameter in, i.e. the structural model by a symbolic name and assign a vector of values to that name. These values will be used to generate data for all possible combinations of these values with the remaining fixed parameters.
The package works nicely in combination with the cSEM package.
Simply write your model in lavaan model syntax.
Add a fixed numeric value for each parameter. Note, currently you must either set all parameters or none. The type
of output can be chosen: a data.frame (return_type = "data.frame"
, the default),
a numeric matrix (return.type = "matrix"
), or a correlation matrix (return.type = "cor"
).
require(cSEM.DGP) model <- " # Structural model eta3 ~ 0.6*eta1 + 0.4*eta2 eta4 ~ 0.4*eta1 + 0.35*eta3 # Measurement model eta1 =~ 0.8*y11 + 0.9*y12 + 0.8*y13 eta2 =~ 0.7*y21 + 0.7*y22 eta3 =~ 0.9*y31 + 0.8*y32 eta4 =~ 0.9*y41 + 0.8*y42 # Measurment error correlation y11 ~~ 0.2*y12 # Correlation between exogenous constructs eta1 ~~ 0.5*eta2 " dat <- generateData(model, .return_type = "cor") dat
To include variable parameters:
generateData()
where the name corresponds to
the chosen character string.Now, data for all possible combinations of these values with the remaining fixed parameters will be generated.
# We want to vary the path coefficient between eta2 and eta1 and # the first loading of eta1. model <- " # Structural model eta2 ~ gamma1*eta1 eta3 ~ gamma2*eta1 + 0.35*eta2 # Measurement model eta1 =~ lambda*y11 + 0.9*y12 + 0.8*y13 eta2 =~ 0.7*y21 + 0.7*y22 + 0.9*y23 eta3 =~ 0.9*y31 + 0.8*y32 + 0.7*y33 " dat <- generateData(model, .return_type = "cor", lambda = c(0.8, 0.9), gamma1 = c(0.2, 0.3), gamma2 = c(0, 0.2, 0.3), .handle_negative_definite = "drop" ) dat
The return type in this case is a nested tibble. To access e.g. the first data set type:
dat$dgp[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.