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,
  ...
)

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`

Value

tibble with standardized data

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 x 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.617   0.147  0.386    0.0607  0.568   0.104  0.361 
#>  2 -0.585  -0.455 -0.811   -0.941   0.168   0.204 -0.434 
#>  3  0.106   0.785 -0.721    0.214  -0.0657  0.635 -0.807 
#>  4  0.388  -1.03  -0.138   -0.222   0.566  -0.873 -0.0495
#>  5 -0.225  -0.110 -0.286   -0.474   0.155   0.222 -0.0967
#>  6 -0.329   0.668 -0.499   -0.0497 -0.289   0.703 -0.479 
#>  7 -0.0341  2.35   1.61     0.461  -0.403   2.03   1.42  
#>  8  0.220  -1.16  -0.0693  -0.353   0.502  -0.910  0.0718
#>  9  0.485   0.470  1.53     0.878  -0.217  -0.144  1.18  
#> 10 -0.249  -0.705 -1.41    -0.847   0.429  -0.113 -1.08