
# Runs in R 3.6.2 but could not load lavaan into R 4.0.3
# Taken from https://www.lavaan.ugent.be/tutorial/growth.html

# a linear growth model with no time-varying covariates
model <- ' i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
           s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4 '

# can use the growth function only if the intercept and slope are the only latent variables
fit <- growth(model, data=Demo.growth)
summary(fit)

# a linear growth model with a time-varying covariate
model <- '
  # intercept and slope with fixed coefficients
    i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
    s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4
  # regressions
    i ~ x1 + x2
    s ~ x1 + x2
  # time-varying covariates
    t1 ~ c1
    t2 ~ c2
    t3 ~ c3
    t4 ~ c4
'
fit <- growth(model, data = Demo.growth)
summary(fit,fit.measures=T)

time <- data.frame(Demo.growth)
mean(time[,1])
mean(time[,2])
mean(time[,3])
mean(time[,4])

# Runs in R 3.6.2 but could not load lavaan into R 4.0.3
# Taken from https://www.lavaan.ugent.be/tutorial/growth.html

# a linear growth model with no time-varying covariates
model <- ' i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
           s =~ 0*t1 + 1*t2 + 4*t3 + 9*t4 '

# can use the growth function only if the intercept and slope are the only latent variables
fit <- growth(model, data=Demo.growth)
summary(fit)

