Hi Jon
No worries! There are various ways to do this, but in all cases you would probably want to condition the observed longitudinal variables on the controls while estimating the LGM. Then you can request factor scores and generate plots based on those. This is also covered explicitly in the
Longitudinal SEM in R seminar by Instats. Here is some example code from Session 2 (out of 8 Sessions) from the seminar. The only change you would need to make is to control for the covariates by predicting the observed time series variables, which this example does not do (a previous example does this):
# Now let's plot predicted individual linear LGM trajectories
# Plot 5
ourModel <- '
I =~ 1*cig97 + 1*cig98 + 1*cig99 + 1*cig00 + 1*cig01 + 1*cig02
S =~ 0*cig97 + 1*cig98 + 2*cig99 + 3*cig00 + 4*cig01 + 5*cig02
'
fit <- growth(ourModel, data = nlsy, mimic="Mplus", estimator="MLR")
plot_dat <- na.omit(data.frame(lavPredict(fit)))
head(plot_dat)
plot_dat$participant_n <-
1:nrow(plot_dat)
ggplot(data=plot_dat) +
scale_x_continuous(name = "Timepoint",
limits=c(0, 5), breaks = c(0, 1, 2, 3, 4, 5),
labels = c('0', '1', '2', '3', '4', '5')) +
scale_y_continuous(name = "Cig Use", limits=c(0,25))+
geom_abline(data = plot_dat, mapping =
aes(slope=S, intercept=I, color = participant_n), alpha = 0.05) +
labs(title = 'Predicted trajectories of Cig Use') +
theme(legend.position = 'none')
Hope this helps!
Mike