How to perform longitudinal invariance testing with a two-factor CFA model using R's lavaan package?

I’m trying to test longitudinal invariance for a two-factor model using the longInvariance function from the semTools package in R. I’ve successfully done this for a single-factor model, but I’m running into issues when I extend it to two factors.

Here’s a simplified version of my attempt:

model_2f <- '
  F1_T1 =~ Q1 + Q2 + Q3
  F2_T1 =~ Q4 + Q5 + Q6
  F1_T2 =~ Q1_t2 + Q2_t2 + Q3_t2
  F2_T2 =~ Q4_t2 + Q5_t2 + Q6_t2
'

vars_t1 <- c('Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6')
vars_t2 <- c('Q1_t2', 'Q2_t2', 'Q3_t2', 'Q4_t2', 'Q5_t2', 'Q6_t2')
constrained_vars <- list(vars_t1, vars_t2)

longInvariance(model_2f, auto=1, constrainAuto=TRUE, 
               varList=constrained_vars, data=my_data, 
               estimator='MLM', strict=TRUE)

The code returns an error indicating that the factor names in the elements of varList do not match. Has anyone encountered this issue before? What would be the correct way to set up this model and ensure proper configuration for a two-factor longitudinal invariance test?

hey climbing mountain, i’ve run into this before. try splitting ur varList by factor:

varList ← list(
F1 = list(c(‘Q1’,‘Q2’,‘Q3’), c(‘Q1_t2’,‘Q2_t2’,‘Q3_t2’)),
F2 = list(c(‘Q4’,‘Q5’,‘Q6’), c(‘Q4_t2’,‘Q5_t2’,‘Q6_t2’))
)

this should help longInvariance match variables to factors. let me kno if it works!

Hey there, ClimbingMountain! :wave:

I totally get your frustration with the two-factor longitudinal invariance test. It can be a real head-scratcher, right? :thinking:

Have you considered tweaking your varList setup? From what I can see, the longInvariance function might be expecting factor-specific variable lists. Maybe try something like this:

varList <- list(
  F1 = list(c('Q1', 'Q2', 'Q3'), c('Q1_t2', 'Q2_t2', 'Q3_t2')),
  F2 = list(c('Q4', 'Q5', 'Q6'), c('Q4_t2', 'Q5_t2', 'Q6_t2'))
)

This way, you’re grouping the variables by factor across time points. It might help the function match up the right variables with the right factors.

Also, have you checked out the measEq.syntax function from semTools? Sometimes it can be easier to generate the syntax for longitudinal invariance tests and then run it manually with lavaan.

What other approaches have you tried so far? I’m super curious to hear more about your research. What kind of data are you working with? Longitudinal studies are always fascinating!

I’ve encountered similar issues when working with multi-factor longitudinal invariance testing. One approach that’s worked for me is to explicitly define the factor structure in the model syntax for each time point. This can help lavaan correctly identify the factor relationships across time.

Consider modifying your model syntax like this:

model_2f <- '
  # Time 1
  F1_T1 =~ Q1 + Q2 + Q3
  F2_T1 =~ Q4 + Q5 + Q6
  
  # Time 2
  F1_T2 =~ Q1_t2 + Q2_t2 + Q3_t2
  F2_T2 =~ Q4_t2 + Q5_t2 + Q6_t2
  
  # Factor covariances
  F1_T1 ~~ F2_T1
  F1_T2 ~~ F2_T2
  F1_T1 ~~ F1_T2
  F2_T1 ~~ F2_T2
'

This explicit definition often resolves factor naming issues. Also, ensure your data frame column names exactly match the variable names in your model. If the issue persists, you might need to manually specify invariance constraints rather than relying on the auto-generation feature.