This function takes a lavaan model with standardized parameters and simulates latent scores, errors, disturbances, and observed scores.
sim_standardized(
m,
n = 1000,
observed = TRUE,
latent = TRUE,
errors = TRUE,
factor_scores = FALSE,
composites = FALSE,
matrices = FALSE,
...
)
Structural model represented by lavaan syntax
Number of simulated cases
Include observed variables
Include latent variables
Include observed error and latent disturbances variables
Include factor score variables
Include composite variables
Include matrices as attribute of tibble
Arguments passed to `simstandardized_matrices`
tibble with standardized data
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.
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.187 0.936 0.0448 0.0558 -0.231 0.896 0.0224
#> 2 2.30 2.62 0.780 2.35 0.422 0.974 -0.159
#> 3 0.663 -0.332 -0.210 0.467 0.289 -0.660 -0.397
#> 4 0.992 0.219 -0.138 1.02 0.176 -0.495 -0.546
#> 5 -0.225 0.0464 -0.286 -1.01 0.582 0.752 0.117
#> 6 -1.37 -0.205 -0.509 -1.02 -0.558 0.508 -0.102
#> 7 0.445 -0.654 -0.410 0.825 -0.215 -1.23 -0.740
#> 8 0.397 -1.24 0.0507 -0.202 0.559 -1.10 0.132
#> 9 0.833 0.0126 1.30 0.438 0.482 -0.294 1.13
#> 10 -0.388 0.296 -1.44 0.833 -1.05 -0.287 -1.78