if (!require(lavaan)) install.packages("lavaan")
Loading required package: lavaan
This is lavaan 0.5-23.1097
lavaan is BETA software! Please report any bugs.
library(lavaan)
lavaan
: Major Depression Criteria across Men and Women (n = 345 each)9 items rated by clinicians on a scale of 0 to 8 (0 = none, 8 = very severely disturbing/disabling)
Note: lavaan
and the semTools
package has a simplified set of syntax commands to assess invariance. However, I will teach you the manual version so that you learn what you are doing first (then you can take their shortcuts on your own).
mddAll = read.table(file = "MDDALL.dat", header = FALSE, quote = "", na.strings = "99999")
#adding names to variables
names(mddAll) = c("sex", paste0("item",1:9))
#recoding sex to specify each group name
mddAll$sex[which(mddAll$sex==0)] = "Female"
mddAll$sex[which(mddAll$sex==1)] = "Male"
In each case, the model for the female reference group is the same and what changes is how the male are allowed to differ.
configuralSyntax = "
#===================================================================================================
#Factor loadings all freely estimated in both groups with label for each group
depress =~ c(L1F, L1M)*item1 + c(L2F, L2M)*item2 + c(L3F, L3M)*item3 +
c(L4F, L4M)*item4 + c(L5F, L5M)*item5 + c(L6F, L6M)*item6 +
c(L7F, L7M)*item7 + c(L8F, L8M)*item8 + c(L9F, L9M)*item9
#===================================================================================================
#Item intercepts all freely estimated in both groups with label for each group
item1 ~ c(I1F, I1M)*1; item2 ~ c(I2F, I2M)*1; item3 ~ c(I3F, I3M)*1;
item4 ~ c(I4F, I4M)*1; item5 ~ c(I5F, I5M)*1; item6 ~ c(I6F, I6M)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8F, I8M)*1; item9 ~ c(I9F, I9M)*1;
#===================================================================================================
#Redidual variances all freely estimated with label for each group
item1 ~~ c(E1F, E1M)*item1; item2 ~~ c(E2F, E2M)*item2; item3 ~~ c(E3F, E3M)*item3;
item4 ~~ c(E4F, E4M)*item4; item5 ~~ c(E5F, E5M)*item5; item6 ~~ c(E6F, E6M)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8F, E8M)*item8; item9 ~~ c(E9F, E9M)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in each group
depress ~~ c(1,1)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in each group
depress ~ c(0,0)*0
#===================================================================================================
"
configuralEstimates = lavaan(model = configuralSyntax, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
The configural model is the first model which allows separate estimation of the factor for each group. As the items are not linked, the factor is not directly comparable.
metricSyntax = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical *********
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts all freely estimated in both groups with label for each group
item1 ~ c(I1F, I1M)*1; item2 ~ c(I2F, I2M)*1; item3 ~ c(I3F, I3M)*1;
item4 ~ c(I4F, I4M)*1; item5 ~ c(I5F, I5M)*1; item6 ~ c(I6F, I6M)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8F, I8M)*1; item9 ~ c(I9F, I9M)*1;
#===================================================================================================
#Redidual variances all freely estimated with label for each group
item1 ~~ c(E1F, E1M)*item1; item2 ~~ c(E2F, E2M)*item2; item3 ~~ c(E3F, E3M)*item3;
item4 ~~ c(E4F, E4M)*item4; item5 ~~ c(E5F, E5M)*item5; item6 ~~ c(E6F, E6M)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8F, E8M)*item8; item9 ~~ c(E9F, E9M)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in male group *****
depress ~~ c(1,NA)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in each group
depress ~ c(0,0)*0
#===================================================================================================
"
metricEstimates = lavaan(model = metricSyntax, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(metricEstimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 48 iterations
Number of observations per group
Female 375
Male 375
Number of missing patterns per group
Female 1
Male 1
Estimator ML Robust
Minimum Function Test Statistic 102.839 99.532
Degrees of freedom 60 60
P-value (Chi-square) 0.000 0.001
Scaling correction factor 1.033
for the Yuan-Bentler correction (Mplus variant)
Chi-square for each group:
Female 54.745 52.985
Male 48.094 46.547
Model test baseline model:
Minimum Function Test Statistic 1343.575 1218.364
Degrees of freedom 72 72
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.966 0.966
Tucker-Lewis Index (TLI) 0.960 0.959
Robust Comparative Fit Index (CFI) 0.968
Robust Tucker-Lewis Index (TLI) 0.961
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -13708.862 -13708.862
Scaling correction factor 0.834
for the MLR correction
Loglikelihood unrestricted model (H1) -13657.442 -13657.442
Scaling correction factor 1.014
for the MLR correction
Number of free parameters 48 48
Akaike (AIC) 27513.724 27513.724
Bayesian (BIC) 27735.488 27735.488
Sample-size adjusted Bayesian (BIC) 27583.069 27583.069
Root Mean Square Error of Approximation:
RMSEA 0.044 0.042
90 Percent Confidence Interval 0.029 0.058 0.027 0.056
P-value RMSEA <= 0.05 0.758 0.818
Robust RMSEA 0.043
90 Percent Confidence Interval 0.027 0.057
Standardized Root Mean Square Residual:
SRMR 0.042 0.042
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Group 1 [Female]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.180 0.082 14.455 0.000 1.180 0.701
item2 (L2) 1.386 0.088 15.667 0.000 1.386 0.687
item3 (L3) 0.888 0.084 10.542 0.000 0.888 0.426
item4 (L4) 1.202 0.091 13.153 0.000 1.202 0.538
item5 (L5) 1.035 0.084 12.301 0.000 1.035 0.485
item6 (L6) 1.191 0.084 14.198 0.000 1.191 0.591
item7 (L7) 0.792 0.092 8.642 0.000 0.792 0.383
item8 (L8) 1.186 0.094 12.595 0.000 1.186 0.555
item9 (L9) 0.647 0.073 8.813 0.000 0.647 0.359
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.439 0.158 2.777 0.005 0.439 0.249
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1F) 4.184 0.089 47.258 0.000 4.184 2.484
.item2 (I2F) 3.725 0.104 35.848 0.000 3.725 1.846
.item3 (I3F) 1.952 0.108 18.058 0.000 1.952 0.936
.item4 (I4F) 3.589 0.114 31.458 0.000 3.589 1.608
.item5 (I5F) 2.256 0.110 20.522 0.000 2.256 1.058
.item6 (I6F) 3.955 0.103 38.237 0.000 3.955 1.961
.item7 (I7F) 3.869 0.106 36.382 0.000 3.869 1.869
.item8 (I8F) 3.595 0.111 32.331 0.000 3.595 1.684
.item9 (I9F) 1.205 0.092 13.053 0.000 1.205 0.669
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1F) 1.444 0.189 7.646 0.000 1.444 0.509
.item2 (E2F) 2.151 0.220 9.794 0.000 2.151 0.528
.item3 (E3F) 3.556 0.190 18.738 0.000 3.556 0.818
.item4 (E4F) 3.540 0.261 13.543 0.000 3.540 0.710
.item5 (E5F) 3.479 0.206 16.850 0.000 3.479 0.765
.item6 (E6F) 2.648 0.261 10.140 0.000 2.648 0.651
.item7 (E7F) 3.656 0.271 13.482 0.000 3.656 0.853
.item8 (E8F) 3.153 0.275 11.465 0.000 3.153 0.692
.item9 (E9F) 2.827 0.195 14.492 0.000 2.827 0.871
depress 1.000 1.000 1.000
R-Square:
Estimate
item1 0.491
item2 0.472
item3 0.182
item4 0.290
item5 0.235
item6 0.349
item7 0.147
item8 0.308
item9 0.129
Group 2 [Male]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.180 0.082 14.455 0.000 1.097 0.675
item2 (L2) 1.386 0.088 15.667 0.000 1.288 0.638
item3 (L3) 0.888 0.084 10.542 0.000 0.825 0.393
item4 (L4) 1.202 0.091 13.153 0.000 1.117 0.506
item5 (L5) 1.035 0.084 12.301 0.000 0.961 0.458
item6 (L6) 1.191 0.084 14.198 0.000 1.107 0.529
item7 (L7) 0.792 0.092 8.642 0.000 0.736 0.324
item8 (L8) 1.186 0.094 12.595 0.000 1.102 0.503
item9 (L9) 0.647 0.073 8.813 0.000 0.601 0.339
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.862 0.187 4.610 0.000 0.862 0.463
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1M) 4.171 0.082 50.608 0.000 4.171 2.568
.item2 (I2M) 3.685 0.104 35.414 0.000 3.685 1.827
.item3 (I3M) 1.739 0.108 16.098 0.000 1.739 0.828
.item4 (I4M) 3.357 0.115 29.160 0.000 3.357 1.522
.item5 (I5M) 2.235 0.109 20.560 0.000 2.235 1.064
.item6 (I6M) 3.661 0.109 33.598 0.000 3.661 1.748
.item7 (I7M) 3.421 0.118 29.014 0.000 3.421 1.506
.item8 (I8M) 3.517 0.112 31.372 0.000 3.517 1.605
.item9 (I9M) 1.259 0.092 13.649 0.000 1.259 0.710
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1M) 1.436 0.203 7.060 0.000 1.436 0.544
.item2 (E2M) 2.412 0.245 9.854 0.000 2.412 0.593
.item3 (E3M) 3.731 0.196 19.064 0.000 3.731 0.846
.item4 (E4M) 3.617 0.258 14.027 0.000 3.617 0.744
.item5 (E5M) 3.488 0.216 16.176 0.000 3.488 0.790
.item6 (E6M) 3.161 0.270 11.688 0.000 3.161 0.721
.item7 (E7M) 4.619 0.260 17.798 0.000 4.619 0.895
.item8 (E8M) 3.587 0.276 12.998 0.000 3.587 0.747
.item9 (E9M) 2.781 0.208 13.395 0.000 2.781 0.885
depress 0.863 0.112 7.728 0.000 1.000 1.000
R-Square:
Estimate
item1 0.456
item2 0.407
item3 0.154
item4 0.256
item5 0.210
item6 0.279
item7 0.105
item8 0.253
item9 0.115
To test if the metric model fits as well as the configural model, we can use the ANOVA function:
anova(configuralEstimates, metricEstimates)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
configuralEstimates 52 27526 27784 98.911
metricEstimates 60 27514 27736 102.839 4.2593 8 0.833
Here, the metric model is the null hypothesis (technically all loadings being equal) and the configural model is the alternative. As the p-value is rather large, the test indicates the null hypotheisis should not be rejected and therefore, the metric model holds (there is no difference in loadings between groups).
scalarSyntax1 = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts set to be equal in both groups so label for each group is identical ****
item1 ~ c(I1, I1)*1; item2 ~ c(I2, I2)*1; item3 ~ c(I3, I3)*1;
item4 ~ c(I4, I4)*1; item5 ~ c(I5, I5)*1; item6 ~ c(I6, I6)*1;
item7 ~ c(I7, I7)*1; item8 ~ c(I8, I8)*1; item9 ~ c(I9, I9)*1;
#===================================================================================================
#Redidual variances all freely estimated with label for each group
item1 ~~ c(E1F, E1M)*item1; item2 ~~ c(E2F, E2M)*item2; item3 ~~ c(E3F, E3M)*item3;
item4 ~~ c(E4F, E4M)*item4; item5 ~~ c(E5F, E5M)*item5; item6 ~~ c(E6F, E6M)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8F, E8M)*item8; item9 ~~ c(E9F, E9M)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in male group
depress ~~ c(1,NA)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in male group ****
depress ~ c(0,NA)*1
#===================================================================================================
"
scalarEstimates1 = lavaan(model = scalarSyntax1, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(scalarEstimates1, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 53 iterations
Number of observations per group
Female 375
Male 375
Number of missing patterns per group
Female 1
Male 1
Estimator ML Robust
Minimum Function Test Statistic 115.309 111.951
Degrees of freedom 68 68
P-value (Chi-square) 0.000 0.001
Scaling correction factor 1.030
for the Yuan-Bentler correction (Mplus variant)
Chi-square for each group:
Female 60.715 58.946
Male 54.594 53.004
Model test baseline model:
Minimum Function Test Statistic 1343.575 1218.364
Degrees of freedom 72 72
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.963 0.962
Tucker-Lewis Index (TLI) 0.961 0.959
Robust Comparative Fit Index (CFI) 0.964
Robust Tucker-Lewis Index (TLI) 0.962
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -13715.097 -13715.097
Scaling correction factor 0.681
for the MLR correction
Loglikelihood unrestricted model (H1) -13657.442 -13657.442
Scaling correction factor 1.014
for the MLR correction
Number of free parameters 40 40
Akaike (AIC) 27510.194 27510.194
Bayesian (BIC) 27694.997 27694.997
Sample-size adjusted Bayesian (BIC) 27567.981 27567.981
Root Mean Square Error of Approximation:
RMSEA 0.043 0.042
90 Percent Confidence Interval 0.029 0.056 0.027 0.055
P-value RMSEA <= 0.05 0.794 0.846
Robust RMSEA 0.042
90 Percent Confidence Interval 0.028 0.056
Standardized Root Mean Square Residual:
SRMR 0.046 0.046
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Group 1 [Female]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.171 0.081 14.385 0.000 1.171 0.696
item2 (L2) 1.377 0.089 15.534 0.000 1.377 0.683
item3 (L3) 0.894 0.084 10.621 0.000 0.894 0.429
item4 (L4) 1.209 0.091 13.343 0.000 1.209 0.541
item5 (L5) 1.033 0.084 12.275 0.000 1.033 0.485
item6 (L6) 1.199 0.083 14.424 0.000 1.199 0.593
item7 (L7) 0.803 0.091 8.853 0.000 0.803 0.386
item8 (L8) 1.184 0.094 12.534 0.000 1.184 0.555
item9 (L9) 0.640 0.074 8.604 0.000 0.640 0.356
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.454 0.159 2.852 0.004 0.454 0.255
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.240 0.077 54.984 0.000 4.240 2.520
.item2 (I2) 3.773 0.092 41.111 0.000 3.773 1.872
.item3 (I3) 1.897 0.087 21.735 0.000 1.897 0.909
.item4 (I4) 3.541 0.096 37.066 0.000 3.541 1.584
.item5 (I5) 2.303 0.090 25.622 0.000 2.303 1.080
.item6 (I6) 3.882 0.091 42.556 0.000 3.882 1.921
.item7 (I7) 3.711 0.087 42.428 0.000 3.711 1.784
.item8 (I8) 3.620 0.094 38.567 0.000 3.620 1.696
.item9 (I9) 1.268 0.072 17.592 0.000 1.268 0.704
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1F) 1.460 0.193 7.576 0.000 1.460 0.516
.item2 (E2F) 2.166 0.223 9.726 0.000 2.166 0.533
.item3 (E3F) 3.555 0.191 18.619 0.000 3.555 0.816
.item4 (E4F) 3.535 0.261 13.520 0.000 3.535 0.708
.item5 (E5F) 3.478 0.206 16.880 0.000 3.478 0.765
.item6 (E6F) 2.648 0.260 10.183 0.000 2.648 0.648
.item7 (E7F) 3.682 0.267 13.767 0.000 3.682 0.851
.item8 (E8F) 3.155 0.277 11.376 0.000 3.155 0.692
.item9 (E9F) 2.834 0.192 14.790 0.000 2.834 0.874
depress 1.000 1.000 1.000
R-Square:
Estimate
item1 0.484
item2 0.467
item3 0.184
item4 0.292
item5 0.235
item6 0.352
item7 0.149
item8 0.308
item9 0.126
Group 2 [Male]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.171 0.081 14.385 0.000 1.089 0.671
item2 (L2) 1.377 0.089 15.534 0.000 1.280 0.635
item3 (L3) 0.894 0.084 10.621 0.000 0.831 0.395
item4 (L4) 1.209 0.091 13.343 0.000 1.123 0.509
item5 (L5) 1.033 0.084 12.275 0.000 0.960 0.457
item6 (L6) 1.199 0.083 14.424 0.000 1.114 0.531
item7 (L7) 0.803 0.091 8.853 0.000 0.746 0.327
item8 (L8) 1.184 0.094 12.534 0.000 1.100 0.502
item9 (L9) 0.640 0.074 8.604 0.000 0.595 0.336
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.879 0.185 4.754 0.000 0.879 0.468
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.240 0.077 54.984 0.000 4.240 2.612
.item2 (I2) 3.773 0.092 41.111 0.000 3.773 1.870
.item3 (I3) 1.897 0.087 21.735 0.000 1.897 0.902
.item4 (I4) 3.541 0.096 37.066 0.000 3.541 1.604
.item5 (I5) 2.303 0.090 25.622 0.000 2.303 1.097
.item6 (I6) 3.882 0.091 42.556 0.000 3.882 1.850
.item7 (I7) 3.711 0.087 42.428 0.000 3.711 1.625
.item8 (I8) 3.620 0.094 38.567 0.000 3.620 1.653
.item9 (I9) 1.268 0.072 17.592 0.000 1.268 0.715
depress -0.112 0.083 -1.345 0.179 -0.120 -0.120
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1M) 1.451 0.200 7.258 0.000 1.451 0.550
.item2 (E2M) 2.431 0.240 10.124 0.000 2.431 0.597
.item3 (E3M) 3.730 0.196 19.059 0.000 3.730 0.844
.item4 (E4M) 3.611 0.258 13.975 0.000 3.611 0.741
.item5 (E5M) 3.489 0.216 16.166 0.000 3.489 0.791
.item6 (E6M) 3.161 0.276 11.468 0.000 3.161 0.718
.item7 (E7M) 4.658 0.277 16.831 0.000 4.658 0.893
.item8 (E8M) 3.588 0.274 13.119 0.000 3.588 0.748
.item9 (E9M) 2.788 0.213 13.105 0.000 2.788 0.887
depress 0.864 0.112 7.720 0.000 1.000 1.000
R-Square:
Estimate
item1 0.450
item2 0.403
item3 0.156
item4 0.259
item5 0.209
item6 0.282
item7 0.107
item8 0.252
item9 0.113
We can check to see if the model fit was worse, which it was not. The p-value below indicates the scalar model fits as well as the metric model.
anova(metricEstimates, scalarEstimates)
Error in anova(metricEstimates, scalarEstimates) :
object 'scalarEstimates' not found
To demonstrate how to determine if a parameter may need freeing, and what happens if we free the parameter to be unequal across groups, we can return to our metric syntax and create a series of new parameters with intercept differences for each of the items.
#get all modification indices
scalarMI1 = modificationindices(scalarEstimates1, free.remove = FALSE, maximum.number = 10000)
#restrict to only means shown
scalarMI1[which(scalarMI1$op == "~1"),]
lhs op rhs block mi mi.scaled epc sepc.lv sepc.all sepc.nox
10 item1 ~1 1 0.653 0.633 -0.052 -0.052 -0.031 -0.031
11 item2 ~1 1 0.193 0.187 -0.034 -0.034 -0.017 -0.017
12 item3 ~1 1 0.340 0.330 0.058 0.058 0.028 0.028
13 item4 ~1 1 0.268 0.260 0.053 0.053 0.024 0.024
14 item5 ~1 1 0.254 0.247 -0.050 -0.050 -0.024 -0.024
15 item6 ~1 1 0.846 0.821 0.082 0.082 0.041 0.041
16 item7 ~1 1 2.648 2.571 0.164 0.164 0.079 0.079
17 item8 ~1 1 0.086 0.084 -0.028 -0.028 -0.013 -0.013
18 item9 ~1 1 0.541 0.525 -0.065 -0.065 -0.036 -0.036
40 item1 ~1 2 0.524 0.508 0.042 0.042 0.026 0.026
41 item2 ~1 2 0.171 0.166 0.030 0.030 0.015 0.015
42 item3 ~1 2 0.357 0.346 -0.061 -0.061 -0.029 -0.029
43 item4 ~1 2 0.275 0.267 -0.054 -0.054 -0.024 -0.024
44 item5 ~1 2 0.256 0.249 0.051 0.051 0.024 0.024
45 item6 ~1 2 0.996 0.967 -0.097 -0.097 -0.046 -0.046
46 item7 ~1 2 3.329 3.232 -0.207 -0.207 -0.090 -0.090
47 item8 ~1 2 0.098 0.095 0.032 0.032 0.015 0.015
48 item9 ~1 2 0.534 0.518 0.064 0.064 0.036 0.036
60 depress ~1 2 0.000 0.000 0.000 0.000 0.000 0.000
For each item, the item intercepts section of the output will show a MI value, which is a Score test. Here, item seven has the largest MI, indicating the item intercepts may be different (but the p-value would be small). For purposes of this example, we will allow the intercept for item seven to vary across groups and re-estimate the model. If this were an actual analysis, we would have left item 7 invariant
scalarSyntax2 = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts set to be equal in both groups so label for each group is identical ****
item1 ~ c(I1, I1)*1; item2 ~ c(I2, I2)*1; item3 ~ c(I3, I3)*1;
item4 ~ c(I4, I4)*1; item5 ~ c(I5, I5)*1; item6 ~ c(I6, I6)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8, I8)*1; item9 ~ c(I9, I9)*1;
#===================================================================================================
#Redidual variances all freely estimated with label for each group
item1 ~~ c(E1F, E1M)*item1; item2 ~~ c(E2F, E2M)*item2; item3 ~~ c(E3F, E3M)*item3;
item4 ~~ c(E4F, E4M)*item4; item5 ~~ c(E5F, E5M)*item5; item6 ~~ c(E6F, E6M)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8F, E8M)*item8; item9 ~~ c(E9F, E9M)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in male group
depress ~~ c(1,NA)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in male group
depress ~ c(0,NA)*1
#===================================================================================================
IntDiff7 := I7F-I7M
"
scalarEstimates2 = lavaan(model = scalarSyntax2, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(scalarEstimates2, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 55 iterations
Number of observations per group
Female 375
Male 375
Number of missing patterns per group
Female 1
Male 1
Estimator ML Robust
Minimum Function Test Statistic 109.216 106.031
Degrees of freedom 67 67
P-value (Chi-square) 0.001 0.002
Scaling correction factor 1.030
for the Yuan-Bentler correction (Mplus variant)
Chi-square for each group:
Female 57.897 56.209
Male 51.318 49.822
Model test baseline model:
Minimum Function Test Statistic 1343.575 1218.364
Degrees of freedom 72 72
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.967 0.966
Tucker-Lewis Index (TLI) 0.964 0.963
Robust Comparative Fit Index (CFI) 0.968
Robust Tucker-Lewis Index (TLI) 0.966
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -13712.050 -13712.050
Scaling correction factor 0.699
for the MLR correction
Loglikelihood unrestricted model (H1) -13657.442 -13657.442
Scaling correction factor 1.014
for the MLR correction
Number of free parameters 41 41
Akaike (AIC) 27506.100 27506.100
Bayesian (BIC) 27695.523 27695.523
Sample-size adjusted Bayesian (BIC) 27565.332 27565.332
Root Mean Square Error of Approximation:
RMSEA 0.041 0.039
90 Percent Confidence Interval 0.026 0.055 0.025 0.053
P-value RMSEA <= 0.05 0.855 0.896
Robust RMSEA 0.040
90 Percent Confidence Interval 0.025 0.054
Standardized Root Mean Square Residual:
SRMR 0.044 0.044
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Group 1 [Female]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.174 0.082 14.377 0.000 1.174 0.698
item2 (L2) 1.381 0.089 15.564 0.000 1.381 0.685
item3 (L3) 0.894 0.084 10.598 0.000 0.894 0.428
item4 (L4) 1.208 0.091 13.309 0.000 1.208 0.540
item5 (L5) 1.034 0.084 12.287 0.000 1.034 0.485
item6 (L6) 1.198 0.083 14.364 0.000 1.198 0.592
item7 (L7) 0.791 0.092 8.603 0.000 0.791 0.382
item8 (L8) 1.185 0.094 12.561 0.000 1.185 0.555
item9 (L9) 0.642 0.074 8.630 0.000 0.642 0.356
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.449 0.159 2.825 0.005 0.449 0.253
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.228 0.078 54.510 0.000 4.228 2.512
.item2 (I2) 3.761 0.092 40.840 0.000 3.761 1.865
.item3 (I3) 1.887 0.087 21.651 0.000 1.887 0.904
.item4 (I4) 3.528 0.096 36.780 0.000 3.528 1.578
.item5 (I5) 2.292 0.090 25.462 0.000 2.292 1.075
.item6 (I6) 3.870 0.092 42.207 0.000 3.870 1.915
.item7 (I7F) 3.869 0.106 36.382 0.000 3.869 1.869
.item8 (I8) 3.609 0.094 38.382 0.000 3.609 1.690
.item9 (I9) 1.261 0.072 17.570 0.000 1.261 0.700
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1F) 1.455 0.191 7.595 0.000 1.455 0.513
.item2 (E2F) 2.160 0.222 9.738 0.000 2.160 0.531
.item3 (E3F) 3.557 0.191 18.613 0.000 3.557 0.817
.item4 (E4F) 3.539 0.261 13.545 0.000 3.539 0.708
.item5 (E5F) 3.478 0.206 16.874 0.000 3.478 0.765
.item6 (E6F) 2.651 0.260 10.205 0.000 2.651 0.649
.item7 (E7F) 3.658 0.271 13.485 0.000 3.658 0.854
.item8 (E8F) 3.154 0.277 11.404 0.000 3.154 0.692
.item9 (E9F) 2.832 0.192 14.743 0.000 2.832 0.873
depress 1.000 1.000 1.000
R-Square:
Estimate
item1 0.487
item2 0.469
item3 0.183
item4 0.292
item5 0.235
item6 0.351
item7 0.146
item8 0.308
item9 0.127
Group 2 [Male]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.174 0.082 14.377 0.000 1.091 0.672
item2 (L2) 1.381 0.089 15.564 0.000 1.283 0.636
item3 (L3) 0.894 0.084 10.598 0.000 0.830 0.395
item4 (L4) 1.208 0.091 13.309 0.000 1.122 0.508
item5 (L5) 1.034 0.084 12.287 0.000 0.961 0.457
item6 (L6) 1.198 0.083 14.364 0.000 1.113 0.530
item7 (L7) 0.791 0.092 8.603 0.000 0.735 0.324
item8 (L8) 1.185 0.094 12.561 0.000 1.101 0.503
item9 (L9) 0.642 0.074 8.630 0.000 0.597 0.337
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.872 0.186 4.696 0.000 0.872 0.466
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.228 0.078 54.510 0.000 4.228 2.604
.item2 (I2) 3.761 0.092 40.840 0.000 3.761 1.864
.item3 (I3) 1.887 0.087 21.651 0.000 1.887 0.897
.item4 (I4) 3.528 0.096 36.780 0.000 3.528 1.598
.item5 (I5) 2.292 0.090 25.462 0.000 2.292 1.091
.item6 (I6) 3.870 0.092 42.207 0.000 3.870 1.844
.item7 (I7M) 3.493 0.123 28.376 0.000 3.493 1.538
.item8 (I8) 3.609 0.094 38.382 0.000 3.609 1.647
.item9 (I9) 1.261 0.072 17.570 0.000 1.261 0.712
depress -0.090 0.083 -1.087 0.277 -0.097 -0.097
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1M) 1.445 0.201 7.186 0.000 1.445 0.548
.item2 (E2M) 2.423 0.242 10.026 0.000 2.423 0.595
.item3 (E3M) 3.733 0.196 19.086 0.000 3.733 0.844
.item4 (E4M) 3.615 0.260 13.913 0.000 3.615 0.742
.item5 (E5M) 3.488 0.216 16.160 0.000 3.488 0.791
.item6 (E6M) 3.166 0.277 11.417 0.000 3.166 0.719
.item7 (E7M) 4.620 0.259 17.804 0.000 4.620 0.895
.item8 (E8M) 3.587 0.274 13.071 0.000 3.587 0.747
.item9 (E9M) 2.787 0.212 13.148 0.000 2.787 0.887
depress 0.864 0.112 7.725 0.000 1.000 1.000
R-Square:
Estimate
item1 0.452
item2 0.405
item3 0.156
item4 0.258
item5 0.209
item6 0.281
item7 0.105
item8 0.253
item9 0.113
Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
IntDiff7 0.377 0.153 2.463 0.014 0.377 0.332
anova(scalarEstimates2, scalarEstimates, metricEstimates)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
metricEstimates 60 27514 27736 102.84
scalarEstimates2 67 27506 27696 109.22 6.3594 7 0.49846
scalarEstimates 68 27510 27695 115.31 5.9296 1 0.01489 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Here we see the model fist significantly better than the previous scalar model (p = 0.01489) when the intercept for this item is freed and yet still fits as well as the metric model, so we will leave this item intercept free and say there is partial metric invariance.
To begin, we will first start with the residual variances, leaving the residual covariance free across groups.
residualSyntax1 = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts set to be equal in both groups so label for each group is identical
item1 ~ c(I1, I1)*1; item2 ~ c(I2, I2)*1; item3 ~ c(I3, I3)*1;
item4 ~ c(I4, I4)*1; item5 ~ c(I5, I5)*1; item6 ~ c(I6, I6)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8, I8)*1; item9 ~ c(I9, I9)*1;
#===================================================================================================
#Redidual variances set to be equal in both groups so label for each group is identical
item1 ~~ c(E1, E1)*item1; item2 ~~ c(E2, E2)*item2; item3 ~~ c(E3, E3)*item3;
item4 ~~ c(E4, E4)*item4; item5 ~~ c(E5, E5)*item5; item6 ~~ c(E6, E6)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8, E8)*item8; item9 ~~ c(E9, E9)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in male group
depress ~~ c(1,NA)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in male group
depress ~ c(0,NA)*1
#===================================================================================================
IntDiff7 := I7F-I7M
"
residualEstimates1 = lavaan(model = residualSyntax1, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(residualEstimates1, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 52 iterations
Number of observations per group
Female 375
Male 375
Number of missing patterns per group
Female 1
Male 1
Estimator ML Robust
Minimum Function Test Statistic 114.059 112.019
Degrees of freedom 75 75
P-value (Chi-square) 0.002 0.004
Scaling correction factor 1.018
for the Yuan-Bentler correction (Mplus variant)
Chi-square for each group:
Female 60.752 59.666
Male 53.306 52.353
Model test baseline model:
Minimum Function Test Statistic 1343.575 1218.364
Degrees of freedom 72 72
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.969 0.968
Tucker-Lewis Index (TLI) 0.971 0.969
Robust Comparative Fit Index (CFI) 0.970
Robust Tucker-Lewis Index (TLI) 0.971
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -13714.472 -13714.472
Scaling correction factor 0.572
for the MLR correction
Loglikelihood unrestricted model (H1) -13657.442 -13657.442
Scaling correction factor 1.014
for the MLR correction
Number of free parameters 33 33
Akaike (AIC) 27494.944 27494.944
Bayesian (BIC) 27647.406 27647.406
Sample-size adjusted Bayesian (BIC) 27542.618 27542.618
Root Mean Square Error of Approximation:
RMSEA 0.037 0.036
90 Percent Confidence Interval 0.022 0.051 0.021 0.050
P-value RMSEA <= 0.05 0.942 0.956
Robust RMSEA 0.037
90 Percent Confidence Interval 0.021 0.050
Standardized Root Mean Square Residual:
SRMR 0.048 0.048
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Group 1 [Female]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.167 0.082 14.180 0.000 1.167 0.696
item2 (L2) 1.372 0.089 15.358 0.000 1.372 0.671
item3 (L3) 0.888 0.083 10.655 0.000 0.888 0.422
item4 (L4) 1.203 0.090 13.341 0.000 1.203 0.537
item5 (L5) 1.031 0.084 12.316 0.000 1.031 0.484
item6 (L6) 1.197 0.083 14.492 0.000 1.197 0.575
item7 (L7) 0.787 0.092 8.593 0.000 0.787 0.381
item8 (L8) 1.178 0.093 12.608 0.000 1.178 0.540
item9 (L9) 0.639 0.074 8.602 0.000 0.639 0.356
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.484 0.160 3.030 0.002 0.484 0.266
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.229 0.078 53.943 0.000 4.229 2.522
.item2 (I2) 3.763 0.093 40.533 0.000 3.763 1.840
.item3 (I3) 1.886 0.087 21.609 0.000 1.886 0.895
.item4 (I4) 3.528 0.096 36.880 0.000 3.528 1.574
.item5 (I5) 2.292 0.090 25.455 0.000 2.292 1.076
.item6 (I6) 3.862 0.091 42.539 0.000 3.862 1.855
.item7 (I7F) 3.869 0.106 36.382 0.000 3.869 1.872
.item8 (I8) 3.609 0.094 38.326 0.000 3.609 1.655
.item9 (I9) 1.261 0.071 17.668 0.000 1.261 0.703
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1) 1.447 0.145 9.954 0.000 1.447 0.515
.item2 (E2) 2.300 0.177 12.965 0.000 2.300 0.550
.item3 (E3) 3.646 0.143 25.449 0.000 3.646 0.822
.item4 (E4) 3.574 0.197 18.123 0.000 3.574 0.712
.item5 (E5) 3.479 0.161 21.647 0.000 3.479 0.766
.item6 (E6) 2.903 0.199 14.558 0.000 2.903 0.670
.item7 (E7F) 3.653 0.271 13.462 0.000 3.653 0.855
.item8 (E8) 3.367 0.207 16.293 0.000 3.367 0.708
.item9 (E9) 2.809 0.143 19.650 0.000 2.809 0.873
depress 1.000 1.000 1.000
R-Square:
Estimate
item1 0.485
item2 0.450
item3 0.178
item4 0.288
item5 0.234
item6 0.330
item7 0.145
item8 0.292
item9 0.127
Group 2 [Male]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.167 0.082 14.180 0.000 1.097 0.674
item2 (L2) 1.372 0.089 15.358 0.000 1.289 0.648
item3 (L3) 0.888 0.083 10.655 0.000 0.834 0.400
item4 (L4) 1.203 0.090 13.341 0.000 1.130 0.513
item5 (L5) 1.031 0.084 12.316 0.000 0.968 0.461
item6 (L6) 1.197 0.083 14.492 0.000 1.124 0.551
item7 (L7) 0.787 0.092 8.593 0.000 0.739 0.325
item8 (L8) 1.178 0.093 12.608 0.000 1.107 0.516
item9 (L9) 0.639 0.074 8.602 0.000 0.600 0.337
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.832 0.151 5.497 0.000 0.832 0.456
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.229 0.078 53.943 0.000 4.229 2.598
.item2 (I2) 3.763 0.093 40.533 0.000 3.763 1.890
.item3 (I3) 1.886 0.087 21.609 0.000 1.886 0.905
.item4 (I4) 3.528 0.096 36.880 0.000 3.528 1.602
.item5 (I5) 2.292 0.090 25.455 0.000 2.292 1.091
.item6 (I6) 3.862 0.091 42.539 0.000 3.862 1.892
.item7 (I7M) 3.493 0.123 28.381 0.000 3.493 1.535
.item8 (I8) 3.609 0.094 38.326 0.000 3.609 1.684
.item9 (I9) 1.261 0.071 17.668 0.000 1.261 0.708
depress -0.091 0.084 -1.084 0.278 -0.097 -0.097
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1) 1.447 0.145 9.954 0.000 1.447 0.546
.item2 (E2) 2.300 0.177 12.965 0.000 2.300 0.581
.item3 (E3) 3.646 0.143 25.449 0.000 3.646 0.840
.item4 (E4) 3.574 0.197 18.123 0.000 3.574 0.737
.item5 (E5) 3.479 0.161 21.647 0.000 3.479 0.788
.item6 (E6) 2.903 0.199 14.558 0.000 2.903 0.697
.item7 (E7M) 4.629 0.260 17.815 0.000 4.629 0.894
.item8 (E8) 3.367 0.207 16.293 0.000 3.367 0.733
.item9 (E9) 2.809 0.143 19.650 0.000 2.809 0.886
depress 0.883 0.111 7.936 0.000 1.000 1.000
R-Square:
Estimate
item1 0.454
item2 0.419
item3 0.160
item4 0.263
item5 0.212
item6 0.303
item7 0.106
item8 0.267
item9 0.114
Defined Parameters:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
IntDiff7 0.377 0.153 2.463 0.014 0.377 0.337
anova(scalarEstimates2, residualEstimates1)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
scalarEstimates2 67 27506 27696 109.22
residualEstimates1 75 27495 27647 114.06 5.269 8 0.7285
Here we see residual invariance holds as the p-value suggests this model fits as well as the last (partial) scalar invariance model.
Next, we will investigate the residual covariance:
residualSyntax2 = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts set to be equal in both groups so label for each group is identical
item1 ~ c(I1, I1)*1; item2 ~ c(I2, I2)*1; item3 ~ c(I3, I3)*1;
item4 ~ c(I4, I4)*1; item5 ~ c(I5, I5)*1; item6 ~ c(I6, I6)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8, I8)*1; item9 ~ c(I9, I9)*1;
#===================================================================================================
#Redidual variances set to be equal in both groups so label for each group is identical
item1 ~~ c(E1, E1)*item1; item2 ~~ c(E2, E2)*item2; item3 ~~ c(E3, E3)*item3;
item4 ~~ c(E4, E4)*item4; item5 ~~ c(E5, E5)*item5; item6 ~~ c(E6, E6)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8, E8)*item8; item9 ~~ c(E9, E9)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group ****
item1 ~~ c(EC12, EC12)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in male group
depress ~~ c(1,NA)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in male group
depress ~ c(0,NA)*1
#===================================================================================================
"
residualEstimates2 = lavaan(model = residualSyntax2, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
anova(residualEstimates1, residualEstimates2)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
residualEstimates1 75 27495 27647 114.06
residualEstimates2 76 27502 27650 123.35 4.1724 1 0.04109 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
The low p-value indicates holding the residual covariance between items 1 and 2 equal made the model fit worse. Therefore, we will leave it separate by group.
structuralVariance = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts set to be equal in both groups so label for each group is identical
item1 ~ c(I1, I1)*1; item2 ~ c(I2, I2)*1; item3 ~ c(I3, I3)*1;
item4 ~ c(I4, I4)*1; item5 ~ c(I5, I5)*1; item6 ~ c(I6, I6)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8, I8)*1; item9 ~ c(I9, I9)*1;
#===================================================================================================
#Redidual variances set to be equal in both groups so label for each group is identical
item1 ~~ c(E1, E1)*item1; item2 ~~ c(E2, E2)*item2; item3 ~~ c(E3, E3)*item3;
item4 ~~ c(E4, E4)*item4; item5 ~~ c(E5, E5)*item5; item6 ~~ c(E6, E6)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8, E8)*item8; item9 ~~ c(E9, E9)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in Male group ****
depress ~~ c(1,1)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in Male group
depress ~ c(0,NA)*1
#===================================================================================================
"
structuralVariance = lavaan(model = structuralVariance, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
anova(residualEstimates1, structuralVariance)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
residualEstimates1 75 27495 27647 114.06
structuralVariance 76 27494 27642 114.90 1.0095 1 0.315
This test reveals setting the factor variance equal does not make the model fit worse, so we can keep them equal.
structuralMean = "
#===================================================================================================
#Factor loadings set to be equal in both groups so label for each group is identical
depress =~ c(L1, L1)*item1 + c(L2, L2)*item2 + c(L3, L3)*item3 +
c(L4, L4)*item4 + c(L5, L5)*item5 + c(L6, L6)*item6 +
c(L7, L7)*item7 + c(L8, L8)*item8 + c(L9, L9)*item9
#===================================================================================================
#Item intercepts set to be equal in both groups so label for each group is identical
item1 ~ c(I1, I1)*1; item2 ~ c(I2, I2)*1; item3 ~ c(I3, I3)*1;
item4 ~ c(I4, I4)*1; item5 ~ c(I5, I5)*1; item6 ~ c(I6, I6)*1;
item7 ~ c(I7F, I7M)*1; item8 ~ c(I8, I8)*1; item9 ~ c(I9, I9)*1;
#===================================================================================================
#Redidual variances set to be equal in both groups so label for each group is identical
item1 ~~ c(E1, E1)*item1; item2 ~~ c(E2, E2)*item2; item3 ~~ c(E3, E3)*item3;
item4 ~~ c(E4, E4)*item4; item5 ~~ c(E5, E5)*item5; item6 ~~ c(E6, E6)*item6;
item7 ~~ c(E7F, E7M)*item7; item8 ~~ c(E8, E8)*item8; item9 ~~ c(E9, E9)*item9;
#===================================================================================================
#Residual covariance freely estimated in both groups with label for each group
item1 ~~ c(EC12F, EC12M)*item2
#===================================================================================================
#Factor variance fixed to 1 for identification in Female group but estimated in Male group ****
depress ~~ c(1,1)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in Male group
depress ~ c(0,0)*0
#===================================================================================================
"
structuralMean = lavaan(model = structuralMean, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(structuralMean, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
lavaan (0.5-23.1097) converged normally after 52 iterations
Number of observations per group
Female 375
Male 375
Number of missing patterns per group
Female 1
Male 1
Estimator ML Robust
Minimum Function Test Statistic 116.143 114.340
Degrees of freedom 77 77
P-value (Chi-square) 0.003 0.004
Scaling correction factor 1.016
for the Yuan-Bentler correction (Mplus variant)
Chi-square for each group:
Female 61.790 60.831
Male 54.353 53.509
Model test baseline model:
Minimum Function Test Statistic 1343.575 1218.364
Degrees of freedom 72 72
P-value 0.000 0.000
User model versus baseline model:
Comparative Fit Index (CFI) 0.969 0.967
Tucker-Lewis Index (TLI) 0.971 0.970
Robust Comparative Fit Index (CFI) 0.970
Robust Tucker-Lewis Index (TLI) 0.972
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -13715.514 -13715.514
Scaling correction factor 0.559
for the MLR correction
Loglikelihood unrestricted model (H1) -13657.442 -13657.442
Scaling correction factor 1.014
for the MLR correction
Number of free parameters 31 31
Akaike (AIC) 27493.027 27493.027
Bayesian (BIC) 27636.250 27636.250
Sample-size adjusted Bayesian (BIC) 27537.813 27537.813
Root Mean Square Error of Approximation:
RMSEA 0.037 0.036
90 Percent Confidence Interval 0.022 0.050 0.021 0.049
P-value RMSEA <= 0.05 0.950 0.961
Robust RMSEA 0.036
90 Percent Confidence Interval 0.021 0.050
Standardized Root Mean Square Residual:
SRMR 0.050 0.050
Parameter Estimates:
Information Observed
Standard Errors Robust.huber.white
Group 1 [Female]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.135 0.068 16.637 0.000 1.135 0.686
item2 (L2) 1.336 0.075 17.802 0.000 1.336 0.661
item3 (L3) 0.860 0.077 11.228 0.000 0.860 0.411
item4 (L4) 1.168 0.083 14.063 0.000 1.168 0.526
item5 (L5) 1.001 0.076 13.194 0.000 1.001 0.473
item6 (L6) 1.161 0.077 15.096 0.000 1.161 0.563
item7 (L7) 0.766 0.086 8.914 0.000 0.766 0.372
item8 (L8) 1.144 0.082 13.946 0.000 1.144 0.529
item9 (L9) 0.622 0.069 9.001 0.000 0.622 0.348
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.485 0.159 3.047 0.002 0.485 0.266
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.176 0.060 69.282 0.000 4.176 2.525
.item2 (I2) 3.702 0.074 50.291 0.000 3.702 1.833
.item3 (I3) 1.845 0.077 24.121 0.000 1.845 0.881
.item4 (I4) 3.473 0.081 42.797 0.000 3.473 1.563
.item5 (I5) 2.245 0.077 29.048 0.000 2.245 1.061
.item6 (I6) 3.808 0.075 50.564 0.000 3.808 1.846
.item7 (I7F) 3.842 0.104 37.048 0.000 3.842 1.866
.item8 (I8) 3.556 0.079 45.035 0.000 3.556 1.644
.item9 (I9) 1.232 0.065 18.878 0.000 1.232 0.689
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1) 1.447 0.145 9.949 0.000 1.447 0.529
.item2 (E2) 2.295 0.178 12.893 0.000 2.295 0.563
.item3 (E3) 3.649 0.143 25.557 0.000 3.649 0.831
.item4 (E4) 3.576 0.197 18.172 0.000 3.576 0.724
.item5 (E5) 3.478 0.161 21.617 0.000 3.478 0.776
.item6 (E6) 2.906 0.199 14.596 0.000 2.906 0.683
.item7 (E7F) 3.654 0.271 13.478 0.000 3.654 0.862
.item8 (E8) 3.368 0.207 16.275 0.000 3.368 0.720
.item9 (E9) 2.807 0.143 19.667 0.000 2.807 0.879
depress 1.000 1.000 1.000
R-Square:
Estimate
item1 0.471
item2 0.437
item3 0.169
item4 0.276
item5 0.224
item6 0.317
item7 0.138
item8 0.280
item9 0.121
Group 2 [Male]:
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
depress =~
item1 (L1) 1.135 0.068 16.637 0.000 1.135 0.686
item2 (L2) 1.336 0.075 17.802 0.000 1.336 0.661
item3 (L3) 0.860 0.077 11.228 0.000 0.860 0.411
item4 (L4) 1.168 0.083 14.063 0.000 1.168 0.526
item5 (L5) 1.001 0.076 13.194 0.000 1.001 0.473
item6 (L6) 1.161 0.077 15.096 0.000 1.161 0.563
item7 (L7) 0.766 0.086 8.914 0.000 0.766 0.336
item8 (L8) 1.144 0.082 13.946 0.000 1.144 0.529
item9 (L9) 0.622 0.069 9.001 0.000 0.622 0.348
Covariances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 ~~
.item2 (EC12) 0.829 0.152 5.448 0.000 0.829 0.455
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (I1) 4.176 0.060 69.282 0.000 4.176 2.525
.item2 (I2) 3.702 0.074 50.291 0.000 3.702 1.833
.item3 (I3) 1.845 0.077 24.121 0.000 1.845 0.881
.item4 (I4) 3.473 0.081 42.797 0.000 3.473 1.563
.item5 (I5) 2.245 0.077 29.048 0.000 2.245 1.061
.item6 (I6) 3.808 0.075 50.564 0.000 3.808 1.846
.item7 (I7M) 3.448 0.116 29.819 0.000 3.448 1.510
.item8 (I8) 3.556 0.079 45.035 0.000 3.556 1.644
.item9 (I9) 1.232 0.065 18.878 0.000 1.232 0.689
depress 0.000 0.000 0.000
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.item1 (E1) 1.447 0.145 9.949 0.000 1.447 0.529
.item2 (E2) 2.295 0.178 12.893 0.000 2.295 0.563
.item3 (E3) 3.649 0.143 25.557 0.000 3.649 0.831
.item4 (E4) 3.576 0.197 18.172 0.000 3.576 0.724
.item5 (E5) 3.478 0.161 21.617 0.000 3.478 0.776
.item6 (E6) 2.906 0.199 14.596 0.000 2.906 0.683
.item7 (E7M) 4.625 0.260 17.769 0.000 4.625 0.887
.item8 (E8) 3.368 0.207 16.275 0.000 3.368 0.720
.item9 (E9) 2.807 0.143 19.667 0.000 2.807 0.879
depress 1.000 1.000 1.000
R-Square:
Estimate
item1 0.471
item2 0.437
item3 0.169
item4 0.276
item5 0.224
item6 0.317
item7 0.113
item8 0.280
item9 0.121
anova(structuralMean, structuralVariance)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
structuralVariance 76 27494 27642 114.90
structuralMean 77 27493 27636 116.14 1.2252 1 0.2683
anova(structuralMean, configuralEstimates)
Scaled Chi Square Difference Test (method = "satorra.bentler.2001")
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
configuralEstimates 52 27526 27784 98.911
structuralMean 77 27493 27636 116.143 18.255 25 0.8314
And here we see the means do not differ by group, nor does the final model differ from the initial configural model. We are done.
The extent to which a confirmatory factor model measuring depression (with nine items each on a nine-point response scale) exhibited measurement and structural invariance between women and men was examined using the lavaan
(Rosseel, 2012) package in R (R Core Team, 2017). Robust maximum likelihood (MLR) estimation was used for all analyses; accordingly, nested model comparisons were conducted using the −2LL rescaled difference test. Women served as the reference group in all invariance models. A configural invariance model was initially specified in which single-factor models were estimated simultaneously within each group; factor mean was fixed to 0 and the factor variance was fixed to 1 for identification within each group. A residual covariance between items 1 and 2 was also estimated in each group as suggested by previous results. As shown in Table 1, the configural model had good fit, and thus a series of model constraints were then applied in successive models to examine potential decreases in fit resulting from measurement or structural non-invariance.
Equality of the unstandardized item factor loadings across groups was then examined in a metric invariance model in which the factor variance was fixed to 1 in women but was freely estimated in men; the factor means were fixed to 0 in both groups. All factor loadings were constrained to be equal across groups; all intercepts and residual variances (and the residual covariance between items 1 and 2) were still permitted to vary across groups. The metric invariance model fit well (see Table 1) and did not result in a significant decrease in fit relative to the configural model, −2ΔLL(8) = 4.26, p = .83. The modification indices suggested no points of localized strain among the constrained loadings. The fact that metric invariance (i.e., “weak invariance”“) held indicates that the items were related to the latent factor equivalently across groups, or more simply, that the same latent factor was being measured in each group.
Equality of the unstandardized item intercepts across groups was then examined in a scalar invariance model. The factor mean and variance were fixed to 0 and 1, respectively, for identification in the women, but the factor mean and variance were then estimated in the men. All factor loadings and item intercepts were constrained to be equal across groups; all residual variances (and the residual covariance between items 1 and 2) were still permitted to differ across groups. The scalar invariance model fit well (see Table 1) and did not result in a significant decrease in fit relative to the metric invariance model, −2ΔLL(8) = 12.39, p = .13. However, examination of the modification indices for parameter differences suggested a point of localized strain; accordingly, a partial scalar invariance model was thus estimated in which the intercept for item 7 (“feelings of worthless or guilt”“) was allowed to differ between groups, resulting in a good-fitting model and a significantly better-fitting model relative to the full scalar invariance model, −2ΔLL(1) = 5.93, p = .01. The partial scalar invariance did not fit significantly worse than the metric invariance model, −2ΔLL(7) = 6.36, p = .50, indicating that partial scalar invariance did hold. The factor that partial scalar invariance (i.e., “strong invariance”) held indicates that both groups have the same expected item response at the same absolute level of the trait, or more simply, that the observed differences in item means between groups is due to factor mean differences only. The exception to this is item 7, for which women are expected to have a higher item response than men at the same absolute trait level of depression.
Equality of the unstandardized residual variances across groups was then examined in a residual variance invariance model. As in the partial scalar invariance model, the factor mean and variance were fixed to 0 and 1, respectively, for identification in the women, but the factor mean and variance were still estimated in the men. All factor loadings, item intercepts (except for item 7), and all residual variances (except for item 7) were constrained to be equal across groups; the residual covariance between item 1 and 2 was still permitted to differ across groups. The residual variance invariance model fit well (see Table 1) and did not result in significant decrease in fit relative to the partial scalar invariance model, −2ΔLL(8) = 5.27, p = .73. The modification indices suggested no points of localized strain among the constrained residual variances. The fact that residual variance invariance (i.e., “strict invariance”) held indicates that the amount of item variance not accounted for by the factor was the same across groups. Finally, equality of the residual covariance between items 1 and 2 across groups was tested and resulted in a significant decrease in fit relative to the residual invariance model, −2ΔLL(1) = 4.18, p = .04, indicating that the residual relationship between items 1 and 2 differed significantly between men and women. The residual covariance between items 1 and 2 was thus permitted to vary across groups in further models.
After achieving partial measurement invariance as just described, structural invariance was then tested with two additional models. First, the factor variance in men (which had been estimated freely) was constrained to 1 (i.e., to be equal to the factor variance in the women), resulting in a nonsignificant decrease in fit relative to the residual invariance model, −2ΔLL(1) = 1.01, p = .31. Thus, men and women had equivalent amounts of individual differences in depression. Second, the factor mean in men (which had been estimated freely) was constrained to 0 (i.e., to be equal to the factor mean in women), resulting in a nonsignificant decrease in fit relative to the factor variance invariance model, −2ΔLL(1) = 1.23, p = .27, indicating that men and women had comparable amounts of depression on average. Thus, in conclusion, these analyses showed that partial measurement invariance was obtained between men and women – that is, the relationships of the items to the latent factor of depression were equivalent in both groups (except for the intercept and residual variance for item 7). These analyses also showed that full structural invariance was obtained between men and women, such that both groups had the same amount of depression and interindividual variation in depression as measured by these nine items. The fact that both the factor variances and item residual variances could be constrained equal across groups also indicates equal reliability of the items (i.e., equal standardized factor loadings) across groups, with the exception of item 7. Model parameters from the final invariance model are given in Table 2.
Table 1 would have model fit statistics for tests of multiple group measurement invariance.
Table 2 would have actual model parameters. (unstandardized and standardized estimates and their SEs, so 4 columns)