if (!require(lavaan)) install.packages("lavaan")
## Loading required package: lavaan
## This is lavaan 0.6-19
## lavaan is FREE 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")
summary(configuralEstimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan 0.6-19 ended normally after 47 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 56
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 98.911 94.175
## Degrees of freedom 52 52
## P-value (Chi-square) 0.000 0.000
## Scaling correction factor 1.050
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 50.418 50.418
## Male 43.756 43.756
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.963 0.963
## Tucker-Lewis Index (TLI) 0.949 0.949
##
## Robust Comparative Fit Index (CFI) 0.965
## Robust Tucker-Lewis Index (TLI) 0.952
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -13706.898 -13706.898
## Scaling correction factor 0.981
## for the MLR correction
## Loglikelihood unrestricted model (H1) -13657.442 -13657.442
## Scaling correction factor 1.014
## for the MLR correction
##
## Akaike (AIC) 27525.796 27525.796
## Bayesian (BIC) 27784.520 27784.520
## Sample-size adjusted Bayesian (SABIC) 27606.698 27606.698
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.049 0.047
## 90 Percent confidence interval - lower 0.034 0.031
## 90 Percent confidence interval - upper 0.064 0.061
## P-value H_0: RMSEA <= 0.050 0.522 0.636
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.048
## 90 Percent confidence interval - lower 0.032
## 90 Percent confidence interval - upper 0.063
## P-value H_0: Robust RMSEA <= 0.050 0.581
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.039 0.039
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## Group 1 [Female]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## depress =~
## item1 (L1F) 1.251 0.095 13.155 0.000 1.251 0.730
## item2 (L2F) 1.385 0.103 13.426 0.000 1.385 0.688
## item3 (L3F) 0.911 0.104 8.775 0.000 0.911 0.435
## item4 (L4F) 1.140 0.115 9.874 0.000 1.140 0.516
## item5 (L5F) 1.015 0.106 9.615 0.000 1.015 0.477
## item6 (L6F) 1.155 0.103 11.238 0.000 1.155 0.577
## item7 (L7F) 0.764 0.115 6.618 0.000 0.764 0.371
## item8 (L8F) 1.224 0.113 10.817 0.000 1.224 0.569
## item9 (L9F) 0.606 0.094 6.412 0.000 0.606 0.339
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 ~~
## .item2 (EC12) 0.393 0.166 2.364 0.018 0.393 0.230
##
## 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.440
## .item2 (I2F) 3.725 0.104 35.848 0.000 3.725 1.851
## .item3 (I3F) 1.952 0.108 18.058 0.000 1.952 0.933
## .item4 (I4F) 3.589 0.114 31.458 0.000 3.589 1.624
## .item5 (I5F) 2.256 0.110 20.522 0.000 2.256 1.060
## .item6 (I6F) 3.955 0.103 38.237 0.000 3.955 1.975
## .item7 (I7F) 3.869 0.106 36.382 0.000 3.869 1.879
## .item8 (I8F) 3.595 0.111 32.331 0.000 3.595 1.670
## .item9 (I9F) 1.205 0.092 13.053 0.000 1.205 0.674
## depress 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 (E1F) 1.375 0.194 7.090 0.000 1.375 0.468
## .item2 (E2F) 2.132 0.236 9.049 0.000 2.132 0.527
## .item3 (E3F) 3.551 0.201 17.678 0.000 3.551 0.810
## .item4 (E4F) 3.583 0.272 13.166 0.000 3.583 0.734
## .item5 (E5F) 3.501 0.223 15.733 0.000 3.501 0.773
## .item6 (E6F) 2.677 0.269 9.967 0.000 2.677 0.667
## .item7 (E7F) 3.658 0.276 13.270 0.000 3.658 0.862
## .item8 (E8F) 3.137 0.291 10.785 0.000 3.137 0.677
## .item9 (E9F) 2.831 0.195 14.538 0.000 2.831 0.885
## depress 1.000 1.000 1.000
##
## R-Square:
## Estimate
## item1 0.532
## item2 0.473
## item3 0.190
## item4 0.266
## item5 0.227
## item6 0.333
## item7 0.138
## item8 0.323
## item9 0.115
##
##
## Group 2 [Male]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## depress =~
## item1 (L1M) 1.024 0.099 10.384 0.000 1.024 0.642
## item2 (L2M) 1.266 0.112 11.283 0.000 1.266 0.628
## item3 (L3M) 0.805 0.115 7.011 0.000 0.805 0.385
## item4 (L4M) 1.193 0.123 9.729 0.000 1.193 0.535
## item5 (L5M) 0.982 0.113 8.678 0.000 0.982 0.466
## item6 (L6M) 1.159 0.116 10.010 0.000 1.159 0.549
## item7 (L7M) 0.784 0.131 5.994 0.000 0.784 0.343
## item8 (L8M) 1.043 0.121 8.610 0.000 1.043 0.480
## item9 (L9M) 0.647 0.102 6.359 0.000 0.647 0.362
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 ~~
## .item2 (EC12) 0.920 0.205 4.499 0.000 0.920 0.479
##
## 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.613
## .item2 (I2M) 3.685 0.104 35.414 0.000 3.685 1.829
## .item3 (I3M) 1.739 0.108 16.098 0.000 1.739 0.831
## .item4 (I4M) 3.357 0.115 29.160 0.000 3.357 1.506
## .item5 (I5M) 2.235 0.109 20.560 0.000 2.235 1.062
## .item6 (I6M) 3.661 0.109 33.598 0.000 3.661 1.735
## .item7 (I7M) 3.421 0.118 29.014 0.000 3.421 1.498
## .item8 (I8M) 3.517 0.112 31.372 0.000 3.517 1.620
## .item9 (I9M) 1.259 0.092 13.649 0.000 1.259 0.705
## depress 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 (E1M) 1.499 0.216 6.932 0.000 1.499 0.588
## .item2 (E2M) 2.459 0.274 8.989 0.000 2.459 0.606
## .item3 (E3M) 3.727 0.205 18.167 0.000 3.727 0.852
## .item4 (E4M) 3.547 0.291 12.189 0.000 3.547 0.713
## .item5 (E5M) 3.467 0.236 14.716 0.000 3.467 0.783
## .item6 (E6M) 3.111 0.296 10.520 0.000 3.111 0.698
## .item7 (E7M) 4.599 0.279 16.457 0.000 4.599 0.882
## .item8 (E8M) 3.626 0.296 12.267 0.000 3.626 0.769
## .item9 (E9M) 2.770 0.208 13.291 0.000 2.770 0.869
## depress 1.000 1.000 1.000
##
## R-Square:
## Estimate
## item1 0.412
## item2 0.394
## item3 0.148
## item4 0.287
## item5 0.217
## item6 0.302
## item7 0.118
## item8 0.231
## item9 0.131
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.6-19 ended normally after 48 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 57
## Number of equality constraints 9
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 102.839 99.532
## Degrees of freedom 60 60
## P-value (Chi-square) 0.000 0.001
## Scaling correction factor 1.033
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 52.985 52.985
## Male 46.547 46.547
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## 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
##
## Akaike (AIC) 27513.724 27513.724
## Bayesian (BIC) 27735.488 27735.488
## Sample-size adjusted Bayesian (SABIC) 27583.069 27583.069
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.044 0.042
## 90 Percent confidence interval - lower 0.029 0.027
## 90 Percent confidence interval - upper 0.058 0.056
## P-value H_0: RMSEA <= 0.050 0.758 0.818
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.043
## 90 Percent confidence interval - lower 0.027
## 90 Percent confidence interval - upper 0.057
## P-value H_0: Robust RMSEA <= 0.050 0.785
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.042 0.042
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## 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-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## 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.6-19 ended normally after 52 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 58
## Number of equality constraints 18
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 115.309 111.951
## Degrees of freedom 68 68
## P-value (Chi-square) 0.000 0.001
## Scaling correction factor 1.030
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 58.946 58.946
## Male 53.004 53.004
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## 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
##
## Akaike (AIC) 27510.194 27510.194
## Bayesian (BIC) 27694.997 27694.997
## Sample-size adjusted Bayesian (SABIC) 27567.981 27567.981
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.043 0.042
## 90 Percent confidence interval - lower 0.029 0.027
## 90 Percent confidence interval - upper 0.056 0.055
## P-value H_0: RMSEA <= 0.050 0.794 0.846
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.042
## 90 Percent confidence interval - lower 0.028
## 90 Percent confidence interval - upper 0.056
## P-value H_0: Robust RMSEA <= 0.050 0.817
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.046 0.046
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## 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.377 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.611
## .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, scalarEstimates1)
##
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## metricEstimates 60 27514 27736 102.84
## scalarEstimates1 68 27510 27695 115.31 12.398 8 0.1343
anova(configuralEstimates, scalarEstimates1)
##
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## configuralEstimates 52 27526 27784 98.911
## scalarEstimates1 68 27510 27695 115.309 17.01 16 0.385
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 = lavTestScore(scalarEstimates1)
## Warning: lavaan->lavTestScore():
## se is not `standard'; not implemented yet; falling back to ordinary score
## test
#change label values
labelMap = data.frame(
lhs = scalarEstimates1@ParTable$plabel,
parameter = scalarEstimates1@ParTable$label
)
scalarMI1$uni = merge(x = scalarMI1$uni, y = labelMap, by = "lhs", all.x = TRUE)
# reorder by decreasing values of X2:
scalarMI1$uni = scalarMI1$uni[order(scalarMI1$uni$X2, decreasing = TRUE),]
#restrict to only means shown
scalarMI1$uni[grep(x = scalarMI1$uni$parameter, pattern = "I"),]
## lhs op rhs X2 df p.value parameter
## 8 .p16. == .p46. 6.0718895 1 0.0137350 I7
## 7 .p15. == .p45. 1.9260129 1 0.1651953 I6
## 2 .p10. == .p40. 1.2351345 1 0.2664108 I1
## 10 .p18. == .p48. 1.0909281 1 0.2962657 I9
## 4 .p12. == .p42. 0.7109122 1 0.3991411 I3
## 5 .p13. == .p43. 0.5631921 1 0.4529770 I4
## 6 .p14. == .p44. 0.5248213 1 0.4687923 I5
## 3 .p11. == .p41. 0.3798244 1 0.5376972 I2
## 9 .p17. == .p47. 0.1912907 1 0.6618446 I8
For each item, the item intercepts section of the output will show a MI value (her X2), 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.6-19 ended normally after 53 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 58
## Number of equality constraints 17
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 109.216 106.031
## Degrees of freedom 67 67
## P-value (Chi-square) 0.001 0.002
## Scaling correction factor 1.030
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 56.209 56.209
## Male 49.822 49.822
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## 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
##
## Akaike (AIC) 27506.100 27506.100
## Bayesian (BIC) 27695.523 27695.523
## Sample-size adjusted Bayesian (SABIC) 27565.332 27565.332
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.041 0.039
## 90 Percent confidence interval - lower 0.026 0.025
## 90 Percent confidence interval - upper 0.055 0.053
## P-value H_0: RMSEA <= 0.050 0.855 0.896
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.040
## 90 Percent confidence interval - lower 0.025
## 90 Percent confidence interval - upper 0.054
## P-value H_0: Robust RMSEA <= 0.050 0.873
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.044 0.044
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## 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.529 0.096 36.780 0.000 3.529 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.529 0.096 36.780 0.000 3.529 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, scalarEstimates1, metricEstimates)
##
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## 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
## scalarEstimates1 68 27510 27695 115.31 5.9296 1 0.01489 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(scalarEstimates2, metricEstimates)
##
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## 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.4985
anova(scalarEstimates2, configuralEstimates)
##
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## configuralEstimates 52 27526 27784 98.911
## scalarEstimates2 67 27506 27696 109.216 10.736 15 0.7711
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.6-19 ended normally after 54 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 58
## Number of equality constraints 25
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 114.059 112.019
## Degrees of freedom 75 75
## P-value (Chi-square) 0.002 0.004
## Scaling correction factor 1.018
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 59.666 59.666
## Male 52.353 52.353
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## 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
##
## Akaike (AIC) 27494.944 27494.944
## Bayesian (BIC) 27647.406 27647.406
## Sample-size adjusted Bayesian (SABIC) 27542.618 27542.618
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.037 0.036
## 90 Percent confidence interval - lower 0.022 0.021
## 90 Percent confidence interval - upper 0.051 0.050
## P-value H_0: RMSEA <= 0.050 0.942 0.956
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.037
## 90 Percent confidence interval - lower 0.021
## 90 Percent confidence interval - upper 0.050
## P-value H_0: Robust RMSEA <= 0.050 0.948
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.048 0.048
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## 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.279 -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-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## 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-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## 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
#===================================================================================================
"
structuralVarianceEstimates = lavaan(model = structuralVariance, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(structuralVarianceEstimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan 0.6-19 ended normally after 54 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 57
## Number of equality constraints 25
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 114.904 113.113
## Degrees of freedom 76 76
## P-value (Chi-square) 0.003 0.004
## Scaling correction factor 1.016
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 60.259 60.259
## Male 52.854 52.854
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## 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.972
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -13714.894 -13714.894
## Scaling correction factor 0.567
## for the MLR correction
## Loglikelihood unrestricted model (H1) -13657.442 -13657.442
## Scaling correction factor 1.014
## for the MLR correction
##
## Akaike (AIC) 27493.789 27493.789
## Bayesian (BIC) 27641.631 27641.631
## Sample-size adjusted Bayesian (SABIC) 27540.019 27540.019
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.037 0.036
## 90 Percent confidence interval - lower 0.022 0.021
## 90 Percent confidence interval - upper 0.050 0.049
## P-value H_0: RMSEA <= 0.050 0.947 0.958
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.036
## 90 Percent confidence interval - lower 0.021
## 90 Percent confidence interval - upper 0.050
## P-value H_0: Robust RMSEA <= 0.050 0.952
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.050 0.050
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## Group 1 [Female]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## depress =~
## item1 (L1) 1.132 0.069 16.495 0.000 1.132 0.685
## item2 (L2) 1.332 0.076 17.634 0.000 1.332 0.660
## item3 (L3) 0.861 0.076 11.269 0.000 0.861 0.411
## item4 (L4) 1.169 0.083 14.123 0.000 1.169 0.526
## item5 (L5) 1.000 0.076 13.226 0.000 1.000 0.473
## item6 (L6) 1.162 0.077 15.167 0.000 1.162 0.564
## item7 (L7) 0.765 0.086 8.889 0.000 0.765 0.371
## item8 (L8) 1.142 0.082 13.922 0.000 1.142 0.528
## item9 (L9) 0.620 0.069 8.931 0.000 0.620 0.347
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 ~~
## .item2 (EC12) 0.490 0.159 3.077 0.002 0.490 0.268
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 (I1) 4.229 0.078 53.980 0.000 4.229 2.558
## .item2 (I2) 3.763 0.093 40.555 0.000 3.763 1.864
## .item3 (I3) 1.886 0.087 21.616 0.000 1.886 0.900
## .item4 (I4) 3.528 0.096 36.887 0.000 3.528 1.588
## .item5 (I5) 2.292 0.090 25.463 0.000 2.292 1.083
## .item6 (I6) 3.862 0.091 42.543 0.000 3.862 1.873
## .item7 (I7F) 3.869 0.106 36.382 0.000 3.869 1.879
## .item8 (I8) 3.610 0.094 38.348 0.000 3.610 1.670
## .item9 (I9) 1.261 0.071 17.671 0.000 1.261 0.706
## depress 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 (E1) 1.452 0.145 9.988 0.000 1.452 0.531
## .item2 (E2) 2.301 0.178 12.925 0.000 2.301 0.565
## .item3 (E3) 3.646 0.143 25.467 0.000 3.646 0.831
## .item4 (E4) 3.571 0.197 18.119 0.000 3.571 0.723
## .item5 (E5) 3.478 0.161 21.626 0.000 3.478 0.777
## .item6 (E6) 2.900 0.199 14.536 0.000 2.900 0.682
## .item7 (E7F) 3.655 0.271 13.480 0.000 3.655 0.862
## .item8 (E8) 3.368 0.207 16.280 0.000 3.368 0.721
## .item9 (E9) 2.809 0.143 19.649 0.000 2.809 0.880
## depress 1.000 1.000 1.000
##
## R-Square:
## Estimate
## item1 0.469
## item2 0.435
## item3 0.169
## item4 0.277
## item5 0.223
## item6 0.318
## item7 0.138
## item8 0.279
## item9 0.120
##
##
## Group 2 [Male]:
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## depress =~
## item1 (L1) 1.132 0.069 16.495 0.000 1.132 0.685
## item2 (L2) 1.332 0.076 17.634 0.000 1.332 0.660
## item3 (L3) 0.861 0.076 11.269 0.000 0.861 0.411
## item4 (L4) 1.169 0.083 14.123 0.000 1.169 0.526
## item5 (L5) 1.000 0.076 13.226 0.000 1.000 0.473
## item6 (L6) 1.162 0.077 15.167 0.000 1.162 0.564
## item7 (L7) 0.765 0.086 8.889 0.000 0.765 0.335
## item8 (L8) 1.142 0.082 13.922 0.000 1.142 0.528
## item9 (L9) 0.620 0.069 8.931 0.000 0.620 0.347
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 ~~
## .item2 (EC12) 0.834 0.152 5.483 0.000 0.834 0.456
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 (I1) 4.229 0.078 53.980 0.000 4.229 2.558
## .item2 (I2) 3.763 0.093 40.555 0.000 3.763 1.864
## .item3 (I3) 1.886 0.087 21.616 0.000 1.886 0.900
## .item4 (I4) 3.528 0.096 36.887 0.000 3.528 1.588
## .item5 (I5) 2.292 0.090 25.463 0.000 2.292 1.083
## .item6 (I6) 3.862 0.091 42.543 0.000 3.862 1.873
## .item7 (I7M) 3.493 0.123 28.386 0.000 3.493 1.530
## .item8 (I8) 3.610 0.094 38.348 0.000 3.610 1.670
## .item9 (I9) 1.261 0.071 17.671 0.000 1.261 0.706
## depress -0.094 0.085 -1.098 0.272 -0.094 -0.094
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .item1 (E1) 1.452 0.145 9.988 0.000 1.452 0.531
## .item2 (E2) 2.301 0.178 12.925 0.000 2.301 0.565
## .item3 (E3) 3.646 0.143 25.467 0.000 3.646 0.831
## .item4 (E4) 3.571 0.197 18.119 0.000 3.571 0.723
## .item5 (E5) 3.478 0.161 21.626 0.000 3.478 0.777
## .item6 (E6) 2.900 0.199 14.536 0.000 2.900 0.682
## .item7 (E7M) 4.626 0.260 17.771 0.000 4.626 0.888
## .item8 (E8) 3.368 0.207 16.280 0.000 3.368 0.721
## .item9 (E9) 2.809 0.143 19.649 0.000 2.809 0.880
## depress 1.000 1.000 1.000
##
## R-Square:
## Estimate
## item1 0.469
## item2 0.435
## item3 0.169
## item4 0.277
## item5 0.223
## item6 0.318
## item7 0.112
## item8 0.279
## item9 0.120
anova(residualEstimates1, structuralVariance)
## Chi-Squared Test Statistic (scaled)
## Yuan-Bentler correction (Mplus variant)
##
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## Saturated 0 0.00
## Model 75 27495 27647 112.02 112.02 75 0.003626 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
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,NA)*depress
#===================================================================================================
#Factor mean fixed to zero for identification in Female group but estimated in Male group
depress ~ c(0,NA)*0
#===================================================================================================
"
structuralMean = lavaan(model = structuralMean, data = mddAll, estimator = "MLR", mimic = "mplus", group="sex")
summary(structuralMean, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan 0.6-19 ended normally after 54 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 58
## Number of equality constraints 25
##
## Number of observations per group:
## Female 375
## Male 375
## Number of missing patterns per group:
## Female 1
## Male 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 114.059 112.019
## Degrees of freedom 75 75
## P-value (Chi-square) 0.002 0.004
## Scaling correction factor 1.018
## Yuan-Bentler correction (Mplus variant)
## Test statistic for each group:
## Female 59.666 59.666
## Male 52.353 52.353
##
## Model Test Baseline Model:
##
## Test statistic 1343.575 1218.364
## Degrees of freedom 72 72
## P-value 0.000 0.000
## Scaling correction factor 1.103
##
## 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
##
## Akaike (AIC) 27494.944 27494.944
## Bayesian (BIC) 27647.406 27647.406
## Sample-size adjusted Bayesian (SABIC) 27542.618 27542.618
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.037 0.036
## 90 Percent confidence interval - lower 0.022 0.021
## 90 Percent confidence interval - upper 0.051 0.050
## P-value H_0: RMSEA <= 0.050 0.942 0.956
## P-value H_0: RMSEA >= 0.080 0.000 0.000
##
## Robust RMSEA 0.037
## 90 Percent confidence interval - lower 0.021
## 90 Percent confidence interval - upper 0.050
## P-value H_0: Robust RMSEA <= 0.050 0.948
## P-value H_0: Robust RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.048 0.048
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
##
## 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.279 -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
anova(structuralMean, structuralVariance)
## Chi-Squared Test Statistic (scaled)
## Yuan-Bentler correction (Mplus variant)
##
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## Saturated 0 0.00
## Model 75 27495 27647 112.02 112.02 75 0.003626 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(structuralMean, configuralEstimates)
##
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
##
## lavaan->lavTestLRT():
## lavaan NOTE: The "Chisq" column contains standard test statistics, not the
## robust test that should be reported per model. A robust difference test is
## a function of two standard (not robust) statistics.
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## configuralEstimates 52 27526 27784 98.911
## structuralMean 75 27495 27647 114.059 16.018 23 0.8545
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)