Example 6 - Linear Latent Growth Curve Model with 4 Timepoints

Load the lavaan package.

library(lavaan)
## Warning: package 'lavaan' was built under R version 3.1.3
## This is lavaan 0.5-18
## lavaan is BETA software! Please report any bugs.

Load the data, give the columns names.

dat <- read.table("../../data/anxiety.dat", header = F)
names(dat) <- c("a1", "a2", "a3", "a4")

Build the LGC model with lavaan syntax. Here we are specifying a linear slope. Notice how the manifest variable intercepts are fixed to 0, and the last two lines request the means for the intercept and slope latent variables.

model <- "intercept =~ 1*a1 + 1*a2 + 1*a3 + 1*a4
slope =~ 0*a1 + 1*a2 + 2*a3 + 3*a4
a1 ~ 0*1
a2 ~ 0*1
a3 ~ 0*1
a4 ~ 0*1
intercept ~ 1
slope ~ 1
"

Run the model using the sem function, request a summary of the output.

output <- sem(model, data = dat)
summary(output)
## lavaan (0.5-18) converged normally after  45 iterations
## 
##   Number of observations                           485
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic               27.288
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.000
## 
## Parameter estimates:
## 
##   Information                                 Expected
##   Standard Errors                             Standard
## 
##                    Estimate  Std.err  Z-value  P(>|z|)
## Latent variables:
##   intercept =~
##     a1                1.000
##     a2                1.000
##     a3                1.000
##     a4                1.000
##   slope =~
##     a1                0.000
##     a2                1.000
##     a3                2.000
##     a4                3.000
## 
## Covariances:
##   intercept ~~
##     slope            -0.011    0.003   -3.472    0.001
## 
## Intercepts:
##     a1                0.000
##     a2                0.000
##     a3                0.000
##     a4                0.000
##     intercept         0.698    0.020   35.050    0.000
##     slope            -0.062    0.006  -10.513    0.000
## 
## Variances:
##     a1                0.067    0.007
##     a2                0.048    0.004
##     a3                0.048    0.004
##     a4                0.040    0.006
##     intercept         0.151    0.013
##     slope             0.007    0.001