A latent growth curve model is a special case of a ctsem model. Its process changes at a constant rate, with no random fluctuation, and people differ in where they start and how fast they grow. This article fits a linear growth curve, then two growth processes with several indicators, then lets the measurement error depend on the level of the process.
Data
Thirty people, each observed eight times at irregular times. Each person has their own intercept and slope, and people who start higher grow more slowly:
set.seed(3)
nsubjects <- 30
nobs <- 8
intercept <- rnorm(nsubjects, 3, 2)
slope <- rnorm(nsubjects, 0.45, 0.15) - intercept * 0.05
dat <- expand.grid(obs = 1:nobs, id = 1:nsubjects)
dat$time <- dat$obs + runif(nrow(dat), -0.5, 0.5)
dat$eta1 <- intercept[dat$id] + slope[dat$id] * dat$time
dat$y1 <- dat$eta1 + rnorm(nrow(dat), 0, 0.2)
dat <- dat[, c('id', 'time', 'y1', 'eta1')]
head(dat)
#> id time y1 eta1
#> 1 1 1.216853 1.787250 1.722631
#> 2 1 2.322188 2.132112 2.309882
#> 3 1 3.320742 2.919136 2.840400
#> 4 1 3.699945 3.089174 3.041866
#> 5 1 5.101135 3.700201 3.786300
#> 6 1 5.929836 4.116992 4.226578eta1 is the true value, which a real data set would not
have. It is kept here to compare with the estimates.
ggplot(dat, aes(time, y1, colour = factor(id))) +
geom_point() + geom_line(aes(y = eta1)) +
theme_bw() + guides(colour = 'none')
Linear growth
The default ctsem model is more flexible than linear growth, so a few matrices change:
-
DRIFT = 0: the rate of change does not depend on the current level; -
DIFFUSION = 0: the process does not fluctuate, so change is deterministic; -
CINT = 'slope': the continuous time intercept is the constant rate of change, the slope; -
MANIFESTMEANS = 0: the starting levelT0MEANStakes the place of the intercept.
By default the free intercepts, here the starting level and the slope, vary over people and are correlated. Since the observation times differ within and between people, the model is in continuous time. In discrete time with an interval of one unit, a linear growth curve is the same model.
model <- ctModel(type = 'ct',
manifestNames = 'y1', latentNames = 'eta1',
LAMBDA = 1,
DRIFT = 0,
DIFFUSION = 0,
CINT = 'slope',
MANIFESTMEANS = 0)
T0m_eta1 is the average level at each person’s first
observation, and slope the average slope.
popsd gives their standard deviations over people, and
rawpopcorr their correlation:
s$popsd
#> mean sd 2.5% 50% 97.5% mode
#> T0m_eta1 1.521 0.199 1.178 1.509 1.940 1.516
#> slope 0.147 0.020 0.112 0.147 0.193 0.147
s$rawpopcorr
#> mean sd 2.5% 50% 97.5% mode z
#> slope__T0m_eta1 -0.236 0.171 -0.548 -0.24 0.12 -0.243 -1.381The true values for these thirty people, which the estimates should be close to:
ctPredict() shows the predictions for a few people. The
predicted values (yprior) use each person’s earlier
observations only. Before the first observation the prediction is the
population average, and with each observation the person’s own starting
level and slope are learned:
The smoothed values (ysmooth) use all of each person’s
observations:
Two processes and several indicators
A second process, eta2, has its own starting levels,
related to those of eta1, and declines by 0.2 per unit of
time on average. It is measured by two variables: y2, and
y3 with a loading of 0.8 and an intercept of 3.
In the model each process has a starting level and a slope.
y2 has a loading of 1 and an intercept of 0, which set the
scale of eta2, and y3 gets a free loading and
a free intercept. The intercept is the same for everyone, which
indvarying = FALSE in its string says.
ctModelLatex() shows the structure:
fit2 <- ctFit(dat, model2, cores = 2)
summary(fit2)$popmeans
#> mean sd 2.5% 50% 97.5% mode
#> int1 2.927 0.277 2.391 2.921 3.464 2.928
#> int2 1.977 0.261 1.493 1.967 2.483 1.969
#> lambda3 0.801 0.020 0.760 0.801 0.841 0.802
#> mvary1 0.207 0.011 0.187 0.206 0.230 0.207
#> mvary2 0.504 0.024 0.457 0.504 0.552 0.504
#> mvary3 0.305 0.016 0.275 0.305 0.337 0.304
#> manintercept3 2.943 0.040 2.864 2.942 3.022 2.941
#> slope1 0.321 0.027 0.268 0.321 0.374 0.322
#> slope2 -0.205 0.021 -0.248 -0.205 -0.165 -0.206The slopes come out close to the generating 0.27 and -0.2, and the
loading and intercept of y3 close to 0.8 and 3.
Measurement error that depends on the level
A measurement instrument may work better for some values of the
process than for others. Here the measurement error of y1
grows with the level of eta1:
dat$y1 <- dat$eta1 + rnorm(nrow(dat), 0, log1p_exp(0.8 * dat$eta1 - 3))
ggplot(dat, aes(eta1, log1p_exp(0.8 * eta1 - 3))) + geom_line() +
labs(y = 'measurement error sd of y1') + theme_bw()
The measurement error cell of the model becomes an expression in the
latent process. log1p_exp() keeps the standard deviation
positive. Free parameters inside an expression are declared in
PARS:
model3 <- ctModel(type = 'ct',
manifestNames = 'y1', latentNames = 'eta1',
LAMBDA = 1,
DRIFT = 0,
DIFFUSION = 0,
CINT = 'slope',
MANIFESTMEANS = 0,
MANIFESTVAR = 'log1p_exp(errorsd_intercept + errorsd_byeta1 * eta1)',
PARS = c('errorsd_intercept', 'errorsd_byeta1'))
fit3 <- ctFit(dat, model3, cores = 2)
summary(fit3)$popmeans
#> mean sd 2.5% 50% 97.5% mode
#> T0m_eta1 2.874 0.270 2.332 2.875 3.397 2.867
#> slope 0.347 0.043 0.262 0.349 0.428 0.347
#> errorsd_intercept -2.909 0.188 -3.247 -2.907 -2.563 -2.904
#> errorsd_byeta1 0.780 0.054 0.678 0.781 0.886 0.779The generating values were -3 for the intercept and 0.8 for the
effect of eta1. The band around each smoothed trajectory
includes the measurement error, which is much smaller for person 4,
whose level is lower:
vignette('measurement-models') has more on measurement
that depends on the state, including loadings.