This function takes a lavaan model with standardized parameters and simulates latent scores, errors, disturbances, and observed scores.
Usage
sim_standardized(
m,
n = 1000,
observed = TRUE,
latent = TRUE,
errors = TRUE,
factor_scores = FALSE,
composites = FALSE,
matrices = FALSE,
...
)
Arguments
- m
Structural model represented by lavaan syntax
- n
Number of simulated cases
- observed
Include observed variables
- latent
Include latent variables
- errors
Include observed error and latent disturbances variables
- factor_scores
Include factor score variables
- composites
Include composite variables
- matrices
Include matrices as attribute of tibble
- ...
Arguments passed to `simstandardized_matrices`
Details
This function supports the `~` operator for regressions, the `~~` for covariances (but not variances), and the `=~` latent variable loadings. It does not support intercepts (e.g,. `y ~ 1`), thresholds, scaling factors, formative factors, or equality constraints.
Examples
library(simstandard)
# Lavaan model
m = "Latent_1 =~ 0.8 * Ob_1 + 0.7 * Ob_2 + 0.4 * Ob_3"
# simulate 10 cases
sim_standardized(m, n = 10)
#> # A tibble: 10 × 7
#> Ob_1 Ob_2 Ob_3 Latent_1 e_Ob_1 e_Ob_2 e_Ob_3
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 -0.844 0.178 -2.24 -0.00557 -0.840 0.182 -2.23
#> 2 0.175 0.647 -1.77 -0.247 0.373 0.820 -1.67
#> 3 0.357 0.238 -0.256 0.629 -0.147 -0.202 -0.507
#> 4 -0.251 -2.47 -0.276 -1.86 1.24 -1.16 0.470
#> 5 -1.04 -0.677 0.132 -0.914 -0.313 -0.0376 0.498
#> 6 0.871 0.776 -0.901 0.738 0.281 0.259 -1.20
#> 7 1.12 -0.0808 -0.864 -0.0160 1.13 -0.0696 -0.858
#> 8 -0.355 -0.957 0.928 0.176 -0.496 -1.08 0.857
#> 9 0.0390 1.07 0.0491 -0.134 0.146 1.16 0.103
#> 10 -0.292 0.548 0.140 1.07 -1.15 -0.199 -0.287