Skip to contents

Generate data for simulation studies.

Usage

gen_data_growth(
  n = 100,
  rel = 0.8,
  dist = "Normal",
  lavsim = FALSE,
  scale = 1,
  seed
)

gen_data_twofac(
  n = 100,
  rel = 0.8,
  dist = "Normal",
  lavsim = FALSE,
  meanstructure = FALSE,
  scale = 1,
  seed
)

Arguments

n

Sample size

rel

Reliability of the growth curve model. Either 0.8 or 0.5.

dist

Distribution of the manifest variables. Either "Normal", "Kurtosis" or "Non-normal".

lavsim

Logical. If TRUE, simulate data using lavaan's lavaan::simulateData function.

scale

Scaling factor for the data. Default is 1, but for the growth curve model data, it is found that having a smaller scale (1/10) can be beneficial for convergence.

seed

Seed for reproducibility.

meanstructure

Logical (this is almost always FALSE). If TRUE, include the mean structure in the estimation. Only for two-factor models (since growth models do not have a mean structure).

Value

A data frame with simulated data. For convenience, both the true values ("truth") and distribution ("dist") are attached as attributes.

Details

The function truth() is a simple extractor function to retrieve the true values of the data set generated by gen_data_growth() or gen_data_twofac().

References

Dhaene, S., & Rosseel, Y. (2022). Resampling Based Bias Correction for Small Sample SEM. Structural Equation Modeling: A Multidisciplinary Journal, 29(5), 755–771. https://doi.org/10.1080/10705511.2022.2057999

Author

Original code by Sara Dhaene and Yves Rosseel.

Examples

dat <- gen_data_growth(n = 100, rel = 0.8)
head(dat)
#>        Day0       Day1        Day2       Day3        Day4       Day5       Day6
#> 1  36.40856 -25.118196  -27.520137  -1.116821   -9.163532  -38.95116  -47.14138
#> 2 -58.74332 -47.643378 -107.799366 -94.357642 -106.091947 -116.45859 -156.21584
#> 3  -6.21620  18.441827    6.924438 -19.249225   12.677615  -39.48140  -28.20111
#> 4 -40.13273   2.767599  -51.366649 -61.071713  -61.725349  -78.29509  -75.41545
#> 5  28.39697  13.133848   -9.251629  11.505928  -17.268852  -11.58354  -20.68498
#> 6 -67.28882 -37.558663  -45.854703 -53.196658  -98.382638  -99.99884  -99.28088
#>         Day7       Day8       Day9
#> 1   -7.68428  -57.26876  -78.87382
#> 2 -132.82923 -159.82626 -191.52484
#> 3  -58.39856  -91.62914  -78.02064
#> 4 -103.11656 -144.45654 -135.48955
#> 5   10.97278  -20.25585  -44.31569
#> 6 -112.29904 -109.29257 -162.76015
truth(dat)
#> i~~i  i~1 s~~s  s~1 i~~s    v    v    v    v    v    v    v    v    v    v 
#>  550    0  100    0   40  500  500  500  500  500  500  500  500  500  500