我使用该longInvariance
函数来评估区间数据的两个时间点之间的纵向不变性;我想知道正确的lavaan
/ semTools
R
-code 应该是什么样子。
当我一次只看一个因素时,它就起作用了;但是在检查双因素模型时会产生错误。
以下一个因素的示例代码:
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)
但是,在模型中添加第二个因素时会产生错误。下面的双因素模型的示例代码:
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)
生成的错误是:
Error in longInvariance(model.twoFactor, auto = 1, constrainAuto = TRUE, :
The factor names of the same element of the 'varList' are not the same.