I have 12 survey questions (Qs) that were asked during pre- and post-term survey. So I want to do the longitudinal CFA to see whether there was a difference between factor models for pre/post-term surveys
12 survey questions are broken down into 3 latent variables:
Anx =~ Q1 + Q2 + Q3 + Q4
Bel =~ Q5 + Q6 + Q7 + Q8
Eff =~ Q9 + Q10 + Q11 + Q12
so the same questions were asked in pre and post-term surveys.
I was wondering about how to build the configural model :
Model each factor separately for pre and post-term:
overall.model.Bel <- '
Bel.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Bel.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
'
overall.model.Anx <- '
Anx.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Anx.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
'
overall.model.Eff <- '
Eff.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Eff.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
'
Or I should do it all at ones:
overall.model.Bel <- '
Bel.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Bel.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
Anx.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Anx.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
Eff.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Eff.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
'
any other things I should add or modify?
Then build the model
overall.fit <- cfa(model = overall.model,
data = master,
meanstructure = TRUE)
library(equaltestMI)
to do longitudinal CFA? or that one is only for multigroup CFA ( I am not entirely sure what is the difference in the steps between two, except that for multigroup one the groups are independent of each other)In order to test measurement invariance over time, you need your 2nd model but with additional constraints so that lavaan knows which indicators are actually the same item measured repeatedly. This is easy to do with semTools::measEq.syntax()
. It takes your model, adds required pieces of syntax according to settings you make, and fits the model.
In your example that should work as follows:
overall.model.Bel <- '
Bel.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Bel.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
Anx.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Anx.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
Eff.pre =~ Q1.pre+ Q2.pre+ Q3.pre+ Q4.pre
Eff.post =~ Q1.post+ Q2.post+ Q3.post+ Q4.post
'
rep_factors <- list(Bel = c("Bel.pre","Bel.post"),
Anx = c("Anx.pre","Anx.post"),
Eff = c("Eff.pre","Eff.post") )
fit.config <- semTools::measEq.syntax(configural.model = overall.model.Bel,
data = master,
longFacNames = rep_factors,
return.fit = TRUE,
meanstructure = TRUE)