I use the longInvariance
function to asssess longitudinal invariance between two time points for interval data; and I am wondering how the correct lavaan
/semTools
R
-code should look like.
It works when I look at one factor at a time; but it generates an error when examining a two factor model.
Example code for one factor below:
model.oneFactor <- '
Factor1T1 =~ Item1 + Item2 + Item3
Factor1T2 =~ Item1t2 + Item2t2 + Item3t2
'
# Create list of variables
var1 <- c("Item1", "Item2", "Item3")
var2 <- c("Item1t2", "Item2t2", "Item3t2")
constrainedVar <- list(var1, var2)
# Invariance of the same factor across timepoints
longInvariance(model.oneFactor, auto=1, constrainAuto=TRUE, varList=constrainedVar, data=data, estimator="MLM", strict=TRUE)
However, when adding a second factor in the model generates an error. Example code for a two-factor model below:
model.twoFactor <- '
Factor1T1 =~ Item1 + Item2 + Item3
Factor2T1 =~ Item4 + Item5 + Item6 + Item7
Factor1T2 =~ Item1t2 + Item2t2 + Item3t2
Factor2T2 =~ Item4t2 + Item5t2 + Item6t2 + Item7t2
'
# Create list of variables
var1 <- c("Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7")
var2 <- c("Item1t2", "Item2t2", "Item3t2", "Item4t2", "Item5t2", "Item6t2", "Item7t2")
constrainedVar <- list(var1, var2)
# Invariance of the same factor across timepoints
longInvariance(model.twoFactor, auto=1, constrainAuto=TRUE, varList=constrainedVar, data=data, estimator="MLM", strict=TRUE)
The generated error is:
Error in longInvariance(model.twoFactor, auto = 1, constrainAuto = TRUE, :
The factor names of the same element of the 'varList' are not the same.
I think you also asked your question on the lavaan Google group.
As it was answered there and written in the semTools
documentation, semTools
only provides longInvariance()
for one single scale. If you have two scales you need to specify the models by hand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With