Skip to contents

simulate data for a latent growth curve model with five measurement occasions. The time-distance between these occasions differs between subjects.

Usage

simulate_latent_growth_curve(N = 100)

Arguments

N

sample size

Value

data set with columns y1-y5 (observations) and t_1-t_5 (time of observation)

Examples

set.seed(123)
dataset <- simulate_latent_growth_curve(N = 100)

model <- "
  I =~ 1*y1 + 1*y2 + 1*y3 + 1*y4 + 1*y5
  S =~ data.t_1 * y1 + data.t_2 * y2 + data.t_3 * y3 + data.t_4 * y4 + data.t_5 * y5

  I ~ int*1
  S ~ slp*1

  # set intercepts of manifest variables to zero
  y1 ~ 0*1; y2 ~ 0*1; y3 ~ 0*1; y4 ~ 0*1; y5 ~ 0*1;
  "

mod <- mxsem(model = model,
             data = dataset) |>
  mxTryHard()
#> Skipping the automatic scaling of I. The variable was already scaled manually (e.g., eta =~ 1*y1 + ...).
#> Warning: Automatically scaling latent variable S failed. Could not find an unlabeled free loading on observed items. Did you give labels to all loadings? If so, remove the label for one of the items or manually set one of the loadings to a fixed value (e.g., eta =~ 1*y1 + ...).
#> Running untitled31 with 10 parameters
#> 
#> Beginning initial fit attempt
#> Running untitled31 with 10 parameters
#> 
#>  Lowest minimum so far:  860.891632385377
#> 
#> Solution found
#> 


#> 
#>  Solution found!  Final fit=860.89163 (started at 2725.1683)  (1 attempt(s): 1 valid, 0 errors)
#>  Start values from best fit:
#> 0.024864350436888,0.0537583562803673,0.0362117929126171,0.0523549171097821,0.0292053383787375,0.85025530119423,-0.0297817514055883,0.928423391801049,1.09511498540101,0.290548817833504