Accelerated longitudinal and multiple group designs
Source:vignettes/articles/accelerated-designs.qmd
accelerated-designs.RmdAn accelerated longitudinal design follows several cohorts, each over a short span of age, to learn about development over a longer span. The cohorts may differ, for instance because they grew up at different times or were measured with different instruments. In ctsem the cohorts are time independent predictors, which can affect any parameter, so no separate multiple group model is needed. This article fits such a design, finds which parameters differ between cohorts, and shows how to make the starting values refer to a common age.
Data
Four cohorts of 50 children are each followed for two years, from
ages 0, 1, 2 and 3, so that neighbouring cohorts overlap by a year. In
every cohort a single process grows towards an equilibrium that differs
between children. The cohorts differ in how strongly the process is
pulled towards that equilibrium (the auto effect in DRIFT),
and the older cohorts were measured with a more precise instrument. The
code simulates each cohort from age 0 and keeps its two years:
set.seed(1)
drift <- c(-0.3, -0.4, -0.5, -0.6)
errorsd <- c(0.6, 0.6, 0.3, 0.3)
dat <- NULL
for (cohort in 1:4) {
gm <- ctModel(type = 'ct', silent = TRUE,
manifestNames = 'Y', latentNames = 'eta',
LAMBDA = 1, DRIFT = drift[cohort], DIFFUSION = 0.5,
CINT = 'cint', T0MEANS = 0, T0VAR = 0.1,
MANIFESTMEANS = 0, MANIFESTVAR = 0)
d <- data.frame(ctGenerate(gm, n = 50, Tpoints = 26, dtmean = 0.2,
backend = 'julia',
values = list(popmeans = c(cint = 5), popsd = c(cint = 1))))
d <- d[d$time >= cohort - 1 & d$time < cohort + 1, ]
d$id <- paste0('cohort', cohort, '_', d$id)
d$cohort <- cohort
d$Yobs <- d$Y + rnorm(nrow(d), 0, errorsd[cohort])
dat <- rbind(dat, d)
}
dat$cohort2 <- as.numeric(dat$cohort == 2)
dat$cohort3 <- as.numeric(dat$cohort == 3)
dat$cohort4 <- as.numeric(dat$cohort == 4)
head(dat)
#> id time Y cohort Yobs cohort2 cohort3 cohort4
#> 1 cohort1_1 0.0 0.03981059 1 0.01814951 0 0 0
#> 2 cohort1_1 0.2 0.75362873 1 0.79632969 0 0 0
#> 3 cohort1_1 0.4 1.63277039 1 2.37289812 0 0 0
#> 4 cohort1_1 0.6 2.14152695 1 2.31299696 0 0 0
#> 5 cohort1_1 0.8 3.17685601 1 3.30633698 0 0 0
#> 6 cohort1_1 1.0 4.27070751 1 5.09589977 0 0 0The true scores Y are kept to plot. The analysis uses
Yobs, which has measurement error, shown faintly:
ggplot(dat, aes(time, Y, colour = factor(cohort), group = id)) +
geom_line() + geom_line(aes(y = Yobs), alpha = .2) +
labs(x = 'age', colour = 'cohort') + theme_bw()
A common starting age
The initial values of the processes, T0MEANS, apply at
each subject’s first observation. In an accelerated design the first
observation is at a different age in each cohort, so
T0MEANS would mean a different thing for each. Giving every
child a row at the earliest age in the data, with the observed variables
missing but the covariates kept, makes T0MEANS the value at
that age for everyone:
start <- dat[!duplicated(dat$id), ]
start$time <- min(dat$time)
start$Y <- start$Yobs <- NA
dat <- rbind(start, dat)
dat <- dat[order(dat$id, dat$time), ]Ignoring the cohorts
The first model ignores the cohorts. The continuous time intercept
CINT drives the growth, and by default it varies over
children, as does the starting value. The measurement intercept is fixed
to 0, since T0MEANS and CINT set the
level.
m1 <- ctModel(type = 'ct',
manifestNames = 'Yobs', latentNames = 'eta',
LAMBDA = 1, CINT = 'cint', MANIFESTMEANS = 0)
f1 <- ctFit(dat, m1, cores = 2)
summary(f1)$popmeans
#> mean sd 2.5% 50% 97.5% mode
#> T0m_eta 0.018 0.071 -0.121 0.019 0.158 0.018
#> drift_eta -0.502 0.018 -0.536 -0.502 -0.469 -0.501
#> diff_eta 0.547 0.049 0.461 0.543 0.653 0.544
#> mvarYobs 0.492 0.013 0.467 0.492 0.517 0.491
#> cint 5.207 0.133 4.938 5.209 5.469 5.200Which parameters differ between cohorts?
ctScoreTest() tests, without refitting, whether a
covariate would improve the model, here the cohort as a factor, and for
which parameters:
covariates <- unique(dat[, c('id', 'cohort')])
covariates$cohort <- factor(covariates$cohort)
ctScoreTest(f1, covariates = covariates, tests = 'covariates')
#> Score tests at the fitted model (laplace route, 200 subjects)
#>
#> Covariate cohort (factor): joint LM = 442, df = 21, p = 5e-04
#> parameter estimate se estimate_natural p p_adj
#> diff_eta NA NA NA <5e-04 0.00117
#> mvarYobs NA NA NA <5e-04 0.00117
#> popsd_T0m_eta NA NA NA <5e-04 0.00117
#> drift_eta NA NA NA 0.0010 0.00175
#> T0m_eta NA NA NA 0.0175 0.02450
#> popsd_cint NA NA NA 0.1340 0.15600
#> cint NA NA NA 0.7600 0.76000The tests flag several parameters. In a model that leaves the cohorts
out, one cohort difference can show up in several parameters: a cohort’s
smaller measurement error, for instance, can look like smaller random
change in the process (diff_eta). The drift and the
measurement error are the differences the design suggests, so the next
model adds those, and the tests are run again on it.
Cohort effects
In the model, the cohorts are dummy variables, with the first cohort
as the reference. tipredDefault = FALSE stops them from
affecting every parameter, and the tipreds field of the
drift and measurement error names the predictors that affect them. The
cohorts shift these parameters, while the size of the individual
differences stays the same in every cohort.
cohorts <- 'tipreds = c(cohort2, cohort3, cohort4)'
m2 <- ctModel(type = 'ct',
manifestNames = 'Yobs', latentNames = 'eta',
LAMBDA = 1, CINT = 'cint', MANIFESTMEANS = 0,
TIpredNames = c('cohort2', 'cohort3', 'cohort4'), tipredDefault = FALSE,
DRIFT = paste('drift_eta', cohorts, sep = ', '),
MANIFESTVAR = paste('mvar_Yobs', cohorts, sep = ', '))
f2 <- ctFit(dat, m2, cores = 2)
summary() reports the cohort effects as
tipreds, each on the scale of the parameter it affects:
summary(f2)$tipreds
#> mean sd 2.5% 50% 97.5% mode z
#> tip_cohort2_drift_eta -0.076 0.031 -0.130 -0.079 -0.009 -0.079 -2.498
#> tip_cohort2_mvar_Yobs -0.029 0.036 -0.099 -0.029 0.039 -0.031 -0.820
#> tip_cohort3_drift_eta -0.155 0.021 -0.189 -0.157 -0.111 -0.158 -7.267
#> tip_cohort3_mvar_Yobs -0.494 0.049 -0.598 -0.494 -0.400 -0.494 -10.009
#> tip_cohort4_drift_eta -0.215 0.016 -0.241 -0.217 -0.179 -0.217 -13.422
#> tip_cohort4_mvar_Yobs -0.473 0.049 -0.566 -0.474 -0.382 -0.473 -9.633Compared with the first cohort, the drift of the older cohorts is more negative, and their measurement error smaller.
ctScoreTest(f2, covariates = covariates, tests = 'covariates')
#> Score tests at the fitted model (laplace route, 200 subjects)
#>
#> Covariate cohort (factor): joint LM = 14.1, df = 15, p = 0.662
#> parameter estimate se estimate_natural p p_adj
#> T0m_eta NA NA NA 0.089 0.592
#> drift_eta NA NA NA 0.242 0.592
#> popsd_T0m_eta NA NA NA 0.270 0.592
#> popsd_cint NA NA NA 0.438 0.592
#> mvar_Yobs NA NA NA 0.501 0.592
#> diff_eta NA NA NA 0.507 0.592
#> cint NA NA NA 0.626 0.626
#>
#> Covariate cohort2 (in the model, on the parameters it does not act on): joint LM = 4.81, df = 3, p = 0.208
#> parameter estimate se estimate_natural p p_adj
#> T0m_eta -0.01310 0.0101 -0.1310 0.191 0.457
#> diff_eta 0.08360 0.0805 0.0760 0.304 0.457
#> cint -0.00154 0.0120 -0.0154 0.900 0.900
#>
#> Covariate cohort3 (in the model, on the parameters it does not act on): joint LM = 1.39, df = 3, p = 0.729
#> parameter estimate se estimate_natural p p_adj
#> T0m_eta -0.00896 0.00899 -0.08960 0.315 0.945
#> cint -0.00599 0.01340 -0.05990 0.662 0.949
#> diff_eta -0.00224 0.04100 -0.00203 0.949 0.949
#>
#> Covariate cohort4 (in the model, on the parameters it does not act on): joint LM = 2.98, df = 3, p = 0.392
#> parameter estimate se estimate_natural p p_adj
#> T0m_eta 0.00629 0.00455 0.0629 0.168 0.354
#> cint 0.01110 0.01070 0.1110 0.293 0.354
#> diff_eta -0.03900 0.04270 -0.0354 0.354 0.354With the drift and measurement error effects in the model, the tests find nothing more for the cohorts to explain. The diffusion and the starting values were flagged before because the model without cohorts had no other way to show the differences in drift and measurement error.
Cohort differences in the individual differences
A random effect has one standard deviation for everyone. To let the
size of the individual differences differ between cohorts too, the
stable differences can be written as a second latent process instead.
That process, intercept, never changes (its drift and
diffusion are 0) and drives eta with a fixed effect of 1.
Its starting value differs between children through T0VAR,
and the cohorts can then affect that variance. The random effects are
turned off, since T0VAR now holds the individual
differences.
m3 <- ctModel(type = 'ct',
manifestNames = 'Yobs', latentNames = c('eta', 'intercept'),
LAMBDA = matrix(c(1, 0), nrow = 1),
CINT = 0,
DRIFT = c(
paste('drift_eta', cohorts, sep = ', '), 1,
0, 0),
DIFFUSION = c(
'diffusion_eta', 0,
0, 0),
T0MEANS = c('t0_eta, indvarying = FALSE',
't0_intercept, indvarying = FALSE'),
T0VAR = c(
't0var_eta', 0,
't0var_intercept_eta', paste('t0var_intercept', cohorts, sep = ', ')),
MANIFESTMEANS = 0,
MANIFESTVAR = paste('mvar_Yobs', cohorts, sep = ', '),
TIpredNames = c('cohort2', 'cohort3', 'cohort4'), tipredDefault = FALSE)
f3 <- ctFit(dat, m3, cores = 2)
Comparing the models
anova() gives the log likelihood, AIC and BIC of each
fit, and likelihood ratio tests of each against the one above it:
anova(f1, f2, f3)
#> Likelihood-ratio tests, each fit against the one above it
#>
#> npar AIC BIC logLik -2LL Chisq Df Pr(>Chisq)
#> f1 8 4197.7 4243.3 -2090.9 4181.7
#> f2 14 3809.8 3889.6 -1890.9 3781.8 399.923 6 <2e-16 ***
#> f3 17 3813.3 3910.2 -1889.7 3779.3 2.479 3 0.4791
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1The cohort effects on the drift and measurement error improve the fit
a lot. The cohort effects on the size of the individual differences do
not, which is how the data were generated. ctLOO() compares
models by how well they predict data they were not fitted to, by
refitting or by importance sampling.
Predictions by cohort
ctPredict() with removeObs = TRUE gives the
expected course for a child from each cohort, from the covariates alone,
here over the whole age range:
firsts <- dat$id[!duplicated(dat$cohort)]
ctPredict(f2, subjects = firsts, timerange = c(0, 5), timestep = 0.05,
removeObs = TRUE, plot = TRUE, kalmanvec = 'yprior')
Each cohort’s course is drawn beyond the two years it was observed in, and outside those years the curves show only what each cohort’s parameters imply. The cohort with the weakest pull towards equilibrium, the first, keeps growing the longest and settles highest.