Exercise 8 instructions.

Using the ‘bfi’ data from the ‘psych’ package, build a five factor model using lavaan.

Discuss the CFI, RMSEA and TLI of that model. Export a table with the factor loadings.

Make a plot.

Compare the fit of a five factor model to a single factor model (“The general factor of personality”).

Test the measurement invariance for men vs. women in the five factor model. Make a plot.

Make a table and discuss.

Load the data, set the working directory.

Load the data and get some descriptives.

require(psych)
## Loading required package: psych
Data<-psych::bfi
require(skimr)
## Loading required package: skimr
skim(Data)
Data summary
Name Data
Number of rows 2800
Number of columns 28
_______________________
Column type frequency:
numeric 28
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
A1 16 0.99 2.41 1.41 1 1 2 3 6 ▇▂▂▁▁
A2 27 0.99 4.80 1.17 1 4 5 6 6 ▂▁▅▇▇
A3 26 0.99 4.60 1.30 1 4 5 6 6 ▂▂▅▇▆
A4 19 0.99 4.70 1.48 1 4 5 6 6 ▂▁▃▅▇
A5 16 0.99 4.56 1.26 1 4 5 5 6 ▂▂▅▇▆
C1 21 0.99 4.50 1.24 1 4 5 5 6 ▂▂▅▇▅
C2 24 0.99 4.37 1.32 1 4 5 5 6 ▃▂▆▇▅
C3 20 0.99 4.30 1.29 1 4 5 5 6 ▃▂▆▇▅
C4 26 0.99 2.55 1.38 1 1 2 4 6 ▇▂▂▁▁
C5 16 0.99 3.30 1.63 1 2 3 5 6 ▇▂▅▃▂
E1 23 0.99 2.97 1.63 1 2 3 4 6 ▇▂▃▂▂
E2 16 0.99 3.14 1.61 1 2 3 4 6 ▇▂▃▂▂
E3 25 0.99 4.00 1.35 1 3 4 5 6 ▅▃▇▇▃
E4 9 1.00 4.42 1.46 1 4 5 6 6 ▃▂▃▇▆
E5 21 0.99 4.42 1.33 1 4 5 5 6 ▃▂▅▇▅
N1 22 0.99 2.93 1.57 1 2 3 4 6 ▇▂▃▂▁
N2 21 0.99 3.51 1.53 1 2 4 5 6 ▇▃▆▅▃
N3 11 1.00 3.22 1.60 1 2 3 4 6 ▇▂▅▃▂
N4 36 0.99 3.19 1.57 1 2 3 4 6 ▇▃▅▃▂
N5 29 0.99 2.97 1.62 1 2 3 4 6 ▇▂▃▂▂
O1 22 0.99 4.82 1.13 1 4 5 6 6 ▁▂▅▇▇
O2 0 1.00 2.71 1.57 1 1 2 4 6 ▇▂▂▂▁
O3 28 0.99 4.44 1.22 1 4 5 5 6 ▂▂▆▇▅
O4 14 1.00 4.89 1.22 1 4 5 6 6 ▁▁▃▆▇
O5 20 0.99 2.49 1.33 1 1 2 3 6 ▇▂▂▁▁
gender 0 1.00 1.67 0.47 1 1 2 2 2 ▃▁▁▁▇
education 223 0.92 3.19 1.11 1 3 3 4 5 ▂▂▇▂▃
age 0 1.00 28.78 11.13 3 20 26 35 86 ▃▇▂▁▁

Subset data.

Data<-psych::bfi 
big_5<-Data[,c(1:25)]

In exercise 7, we already examined the factorability, which was middling to meritorious. Therefore, we will proceed. Yet, it is worthwhile still exploring the assumption of multivariate normality.

Multivariate normality

There are some missings. You’ll get an error. Here I have listwise removed them.

require(MVN)
big_5_no_miss<-na.omit(big_5)
mvn(big_5_no_miss, multivariatePlot=T)
## $multivariateNormality
##            Test       HZ p value MVN
## 1 Henze-Zirkler 1.054319       0  NO
## 
## $univariateNormality
##                Test  Variable Statistic   p value Normality
## 1  Anderson-Darling    A1      129.3201  <0.001      NO    
## 2  Anderson-Darling    A2      134.3857  <0.001      NO    
## 3  Anderson-Darling    A3      124.0838  <0.001      NO    
## 4  Anderson-Darling    A4      163.7947  <0.001      NO    
## 5  Anderson-Darling    A5      108.0415  <0.001      NO    
## 6  Anderson-Darling    C1      107.6637  <0.001      NO    
## 7  Anderson-Darling    C2       99.2526  <0.001      NO    
## 8  Anderson-Darling    C3       92.4993  <0.001      NO    
## 9  Anderson-Darling    C4      100.8417  <0.001      NO    
## 10 Anderson-Darling    C5       73.8674  <0.001      NO    
## 11 Anderson-Darling    E1       85.6666  <0.001      NO    
## 12 Anderson-Darling    E2       76.1363  <0.001      NO    
## 13 Anderson-Darling    E3       73.1035  <0.001      NO    
## 14 Anderson-Darling    E4      120.9196  <0.001      NO    
## 15 Anderson-Darling    E5      102.2867  <0.001      NO    
## 16 Anderson-Darling    N1       80.4836  <0.001      NO    
## 17 Anderson-Darling    N2       62.6557  <0.001      NO    
## 18 Anderson-Darling    N3       73.6727  <0.001      NO    
## 19 Anderson-Darling    N4       67.8013  <0.001      NO    
## 20 Anderson-Darling    N5       85.0121  <0.001      NO    
## 21 Anderson-Darling    O1      122.7557  <0.001      NO    
## 22 Anderson-Darling    O2      106.5534  <0.001      NO    
## 23 Anderson-Darling    O3       95.7682  <0.001      NO    
## 24 Anderson-Darling    O4      159.2082  <0.001      NO    
## 25 Anderson-Darling    O5      105.3923  <0.001      NO    
## 
## $Descriptives
##       n     Mean  Std.Dev Median Min Max 25th 75th        Skew    Kurtosis
## A1 2436 2.406404 1.407177      2   1   6    1    3  0.83796401 -0.27990169
## A2 2436 4.797209 1.179535      5   1   6    4    6 -1.11880031  1.00641205
## A3 2436 4.598522 1.311355      5   1   6    4    6 -1.01376321  0.46427989
## A4 2436 4.687603 1.485213      5   1   6    4    6 -1.02356587  0.01565904
## A5 2436 4.543514 1.270804      5   1   6    4    5 -0.84391857  0.12691880
## C1 2436 4.525041 1.235258      5   1   6    4    5 -0.86637245  0.32227825
## C2 2436 4.372332 1.319152      5   1   6    4    5 -0.73780864 -0.15203946
## C3 2436 4.300082 1.291202      5   1   6    4    5 -0.67763595 -0.14737260
## C4 2436 2.549672 1.376689      2   1   6    1    4  0.61488991 -0.58893943
## C5 2436 3.305829 1.632720      3   1   6    2    5  0.06052881 -1.23223720
## E1 2436 2.978654 1.631428      3   1   6    2    4  0.37410317 -1.09332917
## E2 2436 3.154351 1.613847      3   1   6    2    4  0.22661706 -1.15162025
## E3 2436 3.984401 1.351766      4   1   6    3    5 -0.46630447 -0.45987134
## E4 2436 4.408867 1.467060      5   1   6    4    6 -0.82073539 -0.31981004
## E5 2436 4.390805 1.343316      5   1   6    4    5 -0.77849487 -0.11090601
## N1 2436 2.943760 1.575909      3   1   6    2    4  0.36897054 -1.02086962
## N2 2436 3.517652 1.533238      4   1   6    2    5 -0.08250293 -1.05865697
## N3 2436 3.224548 1.594674      3   1   6    2    5  0.14112304 -1.18071647
## N4 2436 3.202381 1.569633      3   1   6    2    4  0.19727510 -1.08501749
## N5 2436 2.971264 1.623491      3   1   6    2    4  0.37734052 -1.06769970
## O1 2436 4.812808 1.126613      5   1   6    4    6 -0.90440484  0.45739679
## O2 2436 2.684729 1.552883      2   1   6    1    4  0.61587159 -0.76351993
## O3 2436 4.449918 1.205206      5   1   6    4    5 -0.76957250  0.32182294
## O4 2436 4.925287 1.193136      5   1   6    4    6 -1.23792688  1.17547750
## O5 2436 2.468801 1.324021      2   1   6    1    3  0.76398033 -0.18446774

We should bear in mind that the assumption of multivariate normality is violated.

Lavaan model.

require(lavaan)
## Loading required package: lavaan
## This is lavaan 0.6-17
## lavaan is FREE software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
## 
##     cor2cov
five_factor <- '  # Five factors.
              Agreeable =~ A1 + A2 + A3 + A4 + A5 
              Conscientous =~ C1 + C2 + C3 + C4 + C5
              Extraversion =~ E1 + E2 + E3 + E4 + E5
              Neurotic =~ N1 + N2 + N3 + N4 + N5
              Opennness =~ O1 + O2 + O3 + O4 + O5'
fit_CFA<-cfa(five_factor, data= Data)

Let us examine that massive output file… . As you can see the model converged after 55 iterations. 2436 from the 2800 observations were used (listwise deletion). Read here for other settings.

While the five factor model could be considered an acceptable fit in RMSEA (.078), it was not in terms of TLI (.754) and CFI (.782). (check here)

summary(fit_CFA, fit.measures=T)
## lavaan 0.6.17 ended normally after 55 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        60
## 
##                                                   Used       Total
##   Number of observations                          2436        2800
## 
## Model Test User Model:
##                                                       
##   Test statistic                              4165.467
##   Degrees of freedom                               265
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                             18222.116
##   Degrees of freedom                               300
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.782
##   Tucker-Lewis Index (TLI)                       0.754
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -99840.238
##   Loglikelihood unrestricted model (H1)     -97757.504
##                                                       
##   Akaike (AIC)                              199800.476
##   Bayesian (BIC)                            200148.363
##   Sample-size adjusted Bayesian (SABIC)     199957.729
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.078
##   90 Percent confidence interval - lower         0.076
##   90 Percent confidence interval - upper         0.080
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.037
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.075
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable =~                                        
##     A1                1.000                           
##     A2               -1.579    0.108  -14.650    0.000
##     A3               -2.030    0.134  -15.093    0.000
##     A4               -1.564    0.115  -13.616    0.000
##     A5               -1.804    0.121  -14.852    0.000
##   Conscientous =~                                     
##     C1                1.000                           
##     C2                1.148    0.057   20.152    0.000
##     C3                1.036    0.054   19.172    0.000
##     C4               -1.421    0.065  -21.924    0.000
##     C5               -1.489    0.072  -20.694    0.000
##   Extraversion =~                                     
##     E1                1.000                           
##     E2                1.226    0.051   23.899    0.000
##     E3               -0.921    0.041  -22.431    0.000
##     E4               -1.121    0.047  -23.977    0.000
##     E5               -0.808    0.039  -20.648    0.000
##   Neurotic =~                                         
##     N1                1.000                           
##     N2                0.947    0.024   39.899    0.000
##     N3                0.884    0.025   35.919    0.000
##     N4                0.692    0.025   27.753    0.000
##     N5                0.628    0.026   24.027    0.000
##   Opennness =~                                        
##     O1                1.000                           
##     O2               -1.020    0.068  -14.962    0.000
##     O3                1.373    0.072   18.942    0.000
##     O4                0.437    0.048    9.160    0.000
##     O5               -0.960    0.060  -16.056    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable ~~                                        
##     Conscientous     -0.110    0.012   -9.254    0.000
##     Extraversion      0.304    0.025   12.293    0.000
##     Neurotic          0.141    0.018    7.712    0.000
##     Opennness        -0.093    0.011   -8.446    0.000
##   Conscientous ~~                                     
##     Extraversion     -0.224    0.020  -11.121    0.000
##     Neurotic         -0.250    0.025  -10.117    0.000
##     Opennness         0.130    0.014    9.190    0.000
##   Extraversion ~~                                     
##     Neurotic          0.292    0.032    9.131    0.000
##     Opennness        -0.265    0.021  -12.347    0.000
##   Neurotic ~~                                         
##     Opennness        -0.093    0.022   -4.138    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                1.745    0.052   33.725    0.000
##    .A2                0.807    0.028   28.396    0.000
##    .A3                0.754    0.032   23.339    0.000
##    .A4                1.632    0.051   31.796    0.000
##    .A5                0.852    0.032   26.800    0.000
##    .C1                1.063    0.035   30.073    0.000
##    .C2                1.130    0.039   28.890    0.000
##    .C3                1.170    0.039   30.194    0.000
##    .C4                0.960    0.040   24.016    0.000
##    .C5                1.640    0.059   27.907    0.000
##    .E1                1.814    0.058   31.047    0.000
##    .E2                1.332    0.049   26.928    0.000
##    .E3                1.108    0.038   29.522    0.000
##    .E4                1.088    0.041   26.732    0.000
##    .E5                1.251    0.040   31.258    0.000
##    .N1                0.793    0.037   21.575    0.000
##    .N2                0.836    0.036   23.458    0.000
##    .N3                1.222    0.043   28.271    0.000
##    .N4                1.654    0.052   31.977    0.000
##    .N5                1.969    0.060   32.889    0.000
##    .O1                0.865    0.032   27.216    0.000
##    .O2                1.990    0.063   31.618    0.000
##    .O3                0.691    0.039   17.717    0.000
##    .O4                1.346    0.040   34.036    0.000
##    .O5                1.380    0.045   30.662    0.000
##     Agreeable         0.234    0.030    7.839    0.000
##     Conscientous      0.463    0.036   12.810    0.000
##     Extraversion      0.846    0.062   13.693    0.000
##     Neurotic          1.689    0.073   23.034    0.000
##     Opennness         0.404    0.033   12.156    0.000

Remember that multivariate normality issue?

Lavaan offers many options… .

fit_CFA_robust<-cfa(five_factor, data= Data, estimator='MLR')

The conclusions are by and large the same. Note that the standard errors are now robust. Can you spot the similarities and differences between the ‘original’ and the model with robust errors?

summary(fit_CFA_robust, fit.measures=T)
## lavaan 0.6.17 ended normally after 55 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        60
## 
##                                                   Used       Total
##   Number of observations                          2436        2800
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                              4165.467    3612.178
##   Degrees of freedom                               265         265
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.153
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                             18222.116   15289.285
##   Degrees of freedom                               300         300
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.192
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.782       0.777
##   Tucker-Lewis Index (TLI)                       0.754       0.747
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.784
##   Robust Tucker-Lewis Index (TLI)                            0.755
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -99840.238  -99840.238
##   Scaling correction factor                                  1.216
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)     -97757.504  -97757.504
##   Scaling correction factor                                  1.165
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                              199800.476  199800.476
##   Bayesian (BIC)                            200148.363  200148.363
##   Sample-size adjusted Bayesian (SABIC)     199957.729  199957.729
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.078       0.072
##   90 Percent confidence interval - lower         0.076       0.070
##   90 Percent confidence interval - upper         0.080       0.074
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    0.037       0.000
##                                                                   
##   Robust RMSEA                                               0.077
##   90 Percent confidence interval - lower                     0.075
##   90 Percent confidence interval - upper                     0.080
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         0.025
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.075       0.075
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable =~                                        
##     A1                1.000                           
##     A2               -1.579    0.110  -14.344    0.000
##     A3               -2.030    0.148  -13.750    0.000
##     A4               -1.564    0.128  -12.201    0.000
##     A5               -1.804    0.145  -12.407    0.000
##   Conscientous =~                                     
##     C1                1.000                           
##     C2                1.148    0.051   22.376    0.000
##     C3                1.036    0.061   17.032    0.000
##     C4               -1.421    0.090  -15.828    0.000
##     C5               -1.489    0.103  -14.402    0.000
##   Extraversion =~                                     
##     E1                1.000                           
##     E2                1.226    0.044   27.641    0.000
##     E3               -0.921    0.049  -18.870    0.000
##     E4               -1.121    0.046  -24.109    0.000
##     E5               -0.808    0.045  -17.840    0.000
##   Neurotic =~                                         
##     N1                1.000                           
##     N2                0.947    0.017   55.953    0.000
##     N3                0.884    0.029   30.726    0.000
##     N4                0.692    0.033   20.713    0.000
##     N5                0.628    0.032   19.878    0.000
##   Opennness =~                                        
##     O1                1.000                           
##     O2               -1.020    0.084  -12.094    0.000
##     O3                1.373    0.087   15.803    0.000
##     O4                0.437    0.054    8.153    0.000
##     O5               -0.960    0.075  -12.854    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable ~~                                        
##     Conscientous     -0.110    0.013   -8.670    0.000
##     Extraversion      0.304    0.025   12.231    0.000
##     Neurotic          0.141    0.021    6.776    0.000
##     Opennness        -0.093    0.012   -7.832    0.000
##   Conscientous ~~                                     
##     Extraversion     -0.224    0.021  -10.413    0.000
##     Neurotic         -0.250    0.026   -9.670    0.000
##     Opennness         0.130    0.018    7.080    0.000
##   Extraversion ~~                                     
##     Neurotic          0.292    0.034    8.538    0.000
##     Opennness        -0.265    0.025  -10.512    0.000
##   Neurotic ~~                                         
##     Opennness        -0.093    0.026   -3.588    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                1.745    0.058   29.920    0.000
##    .A2                0.807    0.042   19.134    0.000
##    .A3                0.754    0.046   16.464    0.000
##    .A4                1.632    0.060   27.148    0.000
##    .A5                0.852    0.046   18.657    0.000
##    .C1                1.063    0.053   20.092    0.000
##    .C2                1.130    0.052   21.820    0.000
##    .C3                1.170    0.044   26.585    0.000
##    .C4                0.960    0.054   17.824    0.000
##    .C5                1.640    0.069   23.873    0.000
##    .E1                1.814    0.061   29.746    0.000
##    .E2                1.332    0.062   21.647    0.000
##    .E3                1.108    0.046   23.844    0.000
##    .E4                1.088    0.051   21.169    0.000
##    .E5                1.251    0.047   26.587    0.000
##    .N1                0.793    0.050   15.831    0.000
##    .N2                0.836    0.049   17.060    0.000
##    .N3                1.222    0.053   23.117    0.000
##    .N4                1.654    0.060   27.546    0.000
##    .N5                1.969    0.061   32.246    0.000
##    .O1                0.865    0.038   22.625    0.000
##    .O2                1.990    0.072   27.796    0.000
##    .O3                0.691    0.053   13.126    0.000
##    .O4                1.346    0.054   25.153    0.000
##    .O5                1.380    0.060   22.984    0.000
##     Agreeable         0.234    0.034    6.973    0.000
##     Conscientous      0.463    0.046   10.015    0.000
##     Extraversion      0.846    0.064   13.211    0.000
##     Neurotic          1.689    0.069   24.518    0.000
##     Opennness         0.404    0.036   11.073    0.000

Residual check

Some issues with correlated residuals. This basically allow us to see where we ‘mess up’. You could attempt explicitly modelling those correlations?

require(ggplot2)
require(corrplot)
plot_matrix <- function(matrix_toplot){
corrplot(matrix_toplot, is.corr = FALSE, 
               type = 'lower', 
               order = "original", 
               tl.col='black', tl.cex=.75)}
plot_matrix(residuals(fit_CFA)$cov)

require(lavaan)
five_factor_cor <- '  # Five factors.
              Agreeable =~ A1 + A2 + A3 + A4 + A5 
              Conscientous =~ C1 + C2 + C3 + C4 + C5
              Extraversion =~ E1 + E2 + E3 + E4 + E5
              Neurotic =~ N1 + N2 + N3 + N4 + N5
              Opennness =~ O1 + O2 + O3 + O4 + O5
              
              # Some residuals can covary.
              N4 ~~ C5
              N4 ~~ E2
              N4 ~~ E4'
fit_CFA_cor<-cfa(five_factor_cor, data= Data)

In this case, we have improved in terms of fit.

summary(fit_CFA_cor, fit.measures=T)
## lavaan 0.6.17 ended normally after 57 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        63
## 
##                                                   Used       Total
##   Number of observations                          2436        2800
## 
## Model Test User Model:
##                                                       
##   Test statistic                              4008.238
##   Degrees of freedom                               262
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                             18222.116
##   Degrees of freedom                               300
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.791
##   Tucker-Lewis Index (TLI)                       0.761
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -99761.623
##   Loglikelihood unrestricted model (H1)     -97757.504
##                                                       
##   Akaike (AIC)                              199649.247
##   Bayesian (BIC)                            200014.528
##   Sample-size adjusted Bayesian (SABIC)     199814.362
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.077
##   90 Percent confidence interval - lower         0.075
##   90 Percent confidence interval - upper         0.079
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.004
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.074
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable =~                                        
##     A1                1.000                           
##     A2               -1.577    0.108  -14.667    0.000
##     A3               -2.027    0.134  -15.111    0.000
##     A4               -1.562    0.115  -13.626    0.000
##     A5               -1.805    0.121  -14.874    0.000
##   Conscientous =~                                     
##     C1                1.000                           
##     C2                1.153    0.056   20.449    0.000
##     C3                1.028    0.053   19.310    0.000
##     C4               -1.386    0.063  -21.919    0.000
##     C5               -1.385    0.068  -20.374    0.000
##   Extraversion =~                                     
##     E1                1.000                           
##     E2                1.194    0.052   23.054    0.000
##     E3               -0.949    0.043  -22.191    0.000
##     E4               -1.100    0.047  -23.206    0.000
##     E5               -0.813    0.040  -20.179    0.000
##   Neurotic =~                                         
##     N1                1.000                           
##     N2                0.940    0.023   40.107    0.000
##     N3                0.868    0.024   35.741    0.000
##     N4                0.608    0.024   25.720    0.000
##     N5                0.614    0.026   23.770    0.000
##   Opennness =~                                        
##     O1                1.000                           
##     O2               -1.018    0.068  -14.983    0.000
##     O3                1.371    0.072   19.042    0.000
##     O4                0.435    0.048    9.158    0.000
##     O5               -0.956    0.059  -16.066    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .C5 ~~                                               
##    .N4                0.338    0.038    8.947    0.000
##  .E2 ~~                                               
##    .N4                0.222    0.035    6.367    0.000
##  .E4 ~~                                               
##    .N4               -0.190    0.031   -6.035    0.000
##   Agreeable ~~                                        
##     Conscientous     -0.110    0.012   -9.211    0.000
##     Extraversion      0.302    0.025   12.266    0.000
##     Neurotic          0.142    0.018    7.713    0.000
##     Opennness        -0.094    0.011   -8.457    0.000
##   Conscientous ~~                                     
##     Extraversion     -0.212    0.020  -10.679    0.000
##     Neurotic         -0.246    0.025   -9.788    0.000
##     Opennness         0.133    0.014    9.263    0.000
##   Extraversion ~~                                     
##     Neurotic          0.273    0.032    8.632    0.000
##     Opennness        -0.267    0.021  -12.452    0.000
##   Neurotic ~~                                         
##     Opennness        -0.099    0.023   -4.379    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                1.745    0.052   33.728    0.000
##    .A2                0.807    0.028   28.430    0.000
##    .A3                0.755    0.032   23.419    0.000
##    .A4                1.633    0.051   31.817    0.000
##    .A5                0.850    0.032   26.803    0.000
##    .C1                1.050    0.035   29.773    0.000
##    .C2                1.108    0.039   28.399    0.000
##    .C3                1.164    0.039   30.016    0.000
##    .C4                0.982    0.040   24.280    0.000
##    .C5                1.688    0.059   28.753    0.000
##    .E1                1.844    0.059   31.146    0.000
##    .E2                1.367    0.050   27.503    0.000
##    .E3                1.090    0.037   29.139    0.000
##    .E4                1.106    0.041   27.131    0.000
##    .E5                1.263    0.040   31.276    0.000
##    .N1                0.759    0.037   20.614    0.000
##    .N2                0.826    0.036   23.100    0.000
##    .N3                1.245    0.044   28.493    0.000
##    .N4                1.683    0.051   32.691    0.000
##    .N5                1.985    0.060   32.954    0.000
##    .O1                0.864    0.032   27.238    0.000
##    .O2                1.991    0.063   31.646    0.000
##    .O3                0.691    0.039   17.804    0.000
##    .O4                1.346    0.040   34.045    0.000
##    .O5                1.382    0.045   30.717    0.000
##     Agreeable         0.235    0.030    7.848    0.000
##     Conscientous      0.475    0.037   12.960    0.000
##     Extraversion      0.817    0.061   13.368    0.000
##     Neurotic          1.723    0.074   23.302    0.000
##     Opennness         0.405    0.033   12.200    0.000
anova(fit_CFA_cor,fit_CFA)

Table

Here I have include the table rather than exported. In order to export it, you would use ‘out=’ . You view the example in class.

require(dplyr)
require(stargazer)
results_table<-parameterEstimates(fit_CFA, standardized=TRUE) %>% 
filter(op == "=~") %>% 
dplyr::select('Latent Factor'=lhs, Indicator=rhs, B=est, SE=se, Z=z, 'p value'=pvalue, Beta=std.all)
#export via stargazer. (Other options are ??xtable)
stargazer(results_table, summary = FALSE, type='html', header = F)
Latent Factor Indicator B SE Z p value Beta
1 Agreeable A1 1 0 0.344
2 Agreeable A2 -1.579 0.108 -14.650 0 -0.648
3 Agreeable A3 -2.030 0.134 -15.093 0 -0.749
4 Agreeable A4 -1.564 0.115 -13.616 0 -0.510
5 Agreeable A5 -1.804 0.121 -14.852 0 -0.687
6 Conscientous C1 1 0 0.551
7 Conscientous C2 1.148 0.057 20.152 0 0.592
8 Conscientous C3 1.036 0.054 19.172 0 0.546
9 Conscientous C4 -1.421 0.065 -21.924 0 -0.702
10 Conscientous C5 -1.489 0.072 -20.694 0 -0.620
11 Extraversion E1 1 0 0.564
12 Extraversion E2 1.226 0.051 23.899 0 0.699
13 Extraversion E3 -0.921 0.041 -22.431 0 -0.627
14 Extraversion E4 -1.121 0.047 -23.977 0 -0.703
15 Extraversion E5 -0.808 0.039 -20.648 0 -0.553
16 Neurotic N1 1 0 0.825
17 Neurotic N2 0.947 0.024 39.899 0 0.803
18 Neurotic N3 0.884 0.025 35.919 0 0.721
19 Neurotic N4 0.692 0.025 27.753 0 0.573
20 Neurotic N5 0.628 0.026 24.027 0 0.503
21 Opennness O1 1 0 0.564
22 Opennness O2 -1.020 0.068 -14.962 0 -0.418
23 Opennness O3 1.373 0.072 18.942 0 0.724
24 Opennness O4 0.437 0.048 9.160 0 0.233
25 Opennness O5 -0.960 0.060 -16.056 0 -0.461

O4 scores poor in terms of loadings (\(\beta\)<.3), A1 also does not load very well on its alledged factor (\(\beta\)<.4).

Figure.

Plot

require(semPlot)
require(qgraph)
semPaths(fit_CFA, layout='circle',style = "ram",what="std")

Lisrel style

require(semPlot)
require(qgraph)
semPaths(fit_CFA, layout='circle',style = "lisrel",what="std")

One factor solution.

require(lavaan)
one_factor <- '  # One factor.
              General =~ A1 + A2 + A3 + A4 + A5 + C1 + C2 + C3 + C4 + C5 + E1 + E2 + E3 + E4 + E5 + N1 + N2 + N3 + N4 + N5 + O1 + O2               + O3 + O4 + O5'
fit_CFA_one<-cfa(one_factor, data= Data)

Fit measures. A quick glance at RMSEA, CFI and GFI already tells you that this is not looking great.

summary(fit_CFA_one, fit.measures=T)
## lavaan 0.6.17 ended normally after 65 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        50
## 
##                                                   Used       Total
##   Number of observations                          2436        2800
## 
## Model Test User Model:
##                                                        
##   Test statistic                              10673.239
##   Degrees of freedom                                275
##   P-value (Chi-square)                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                             18222.116
##   Degrees of freedom                               300
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.420
##   Tucker-Lewis Index (TLI)                       0.367
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)            -103094.124
##   Loglikelihood unrestricted model (H1)     -97757.504
##                                                       
##   Akaike (AIC)                              206288.248
##   Bayesian (BIC)                            206578.154
##   Sample-size adjusted Bayesian (SABIC)     206419.292
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.125
##   90 Percent confidence interval - lower         0.123
##   90 Percent confidence interval - upper         0.127
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.116
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   General =~                                          
##     A1                1.000                           
##     A2               -1.819    0.191   -9.520    0.000
##     A3               -2.329    0.239   -9.750    0.000
##     A4               -2.065    0.222   -9.319    0.000
##     A5               -2.489    0.252   -9.882    0.000
##     C1               -1.242    0.146   -8.495    0.000
##     C2               -1.277    0.152   -8.377    0.000
##     C3               -1.201    0.146   -8.250    0.000
##     C4                1.778    0.194    9.158    0.000
##     C5                2.346    0.250    9.386    0.000
##     E1                2.346    0.250    9.387    0.000
##     E2                3.291    0.331    9.930    0.000
##     E3               -2.434    0.249   -9.770    0.000
##     E4               -2.999    0.302   -9.933    0.000
##     E5               -2.277    0.235   -9.679    0.000
##     N1                1.762    0.200    8.797    0.000
##     N2                1.689    0.193    8.757    0.000
##     N3                1.690    0.195    8.649    0.000
##     N4                2.423    0.254    9.522    0.000
##     N5                1.557    0.187    8.349    0.000
##     O1               -1.155    0.135   -8.552    0.000
##     O2                0.782    0.132    5.919    0.000
##     O3               -1.544    0.169   -9.140    0.000
##     O4                0.250    0.087    2.859    0.004
##     O5                0.733    0.116    6.302    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                1.883    0.054   34.598    0.000
##    .A2                1.072    0.032   33.143    0.000
##    .A3                1.196    0.037   32.314    0.000
##    .A4                1.794    0.053   33.548    0.000
##    .A5                1.017    0.032   31.425    0.000
##    .C1                1.376    0.040   34.262    0.000
##    .C2                1.582    0.046   34.314    0.000
##    .C3                1.528    0.044   34.363    0.000
##    .C4                1.590    0.047   33.768    0.000
##    .C5                2.134    0.064   33.432    0.000
##    .E1                2.130    0.064   33.430    0.000
##    .E2                1.560    0.050   30.939    0.000
##    .E3                1.255    0.039   32.209    0.000
##    .E4                1.284    0.042   30.906    0.000
##    .E5                1.304    0.040   32.635    0.000
##    .N1                2.183    0.064   34.091    0.000
##    .N2                2.075    0.061   34.118    0.000
##    .N3                2.267    0.066   34.183    0.000
##    .N4                1.897    0.057   33.138    0.000
##    .N5                2.401    0.070   34.325    0.000
##    .O1                1.140    0.033   34.234    0.000
##    .O2                2.351    0.068   34.752    0.000
##    .O3                1.222    0.036   33.790    0.000
##    .O4                1.417    0.041   34.875    0.000
##    .O5                1.701    0.049   34.720    0.000
##     General           0.096    0.019    5.104    0.000

Model comparison.

As should be abundantly clear, the five factor model is favoured to the one factor model.

anova(fit_CFA,fit_CFA_one)

Group comparison model.

five_factor_groups <- '  # Five factors.
              Agreeable =~ A1 + A2 + A3 + A4 + A5 
              Conscientous =~ C1 + C2 + C3 + C4 + C5
              Extraversion =~ E1 + E2 + E3 + E4 + E5
              Neurotic =~ N1 + N2 + N3 + N4 + N5
              Opennness =~ O1 + O2 + O3 + O4 + O5'
fit_CFA_groups<-cfa(five_factor_groups, data= Data, group="gender")

Massive output again. Notice how there are fewer men (1) than women (2).

summary(fit_CFA_groups)
## lavaan 0.6.17 ended normally after 100 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       170
## 
##   Number of observations per group:               Used       Total
##     1                                              805         919
##     2                                             1631        1881
## 
## Model Test User Model:
##                                                       
##   Test statistic                              4545.267
##   Degrees of freedom                               530
##   P-value (Chi-square)                           0.000
##   Test statistic for each group:
##     1                                         1673.974
##     2                                         2871.293
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## 
## Group 1 [1]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable =~                                        
##     A1                1.000                           
##     A2               -1.806    0.232   -7.799    0.000
##     A3               -2.267    0.282   -8.052    0.000
##     A4               -1.708    0.232   -7.374    0.000
##     A5               -2.181    0.272   -8.015    0.000
##   Conscientous =~                                     
##     C1                1.000                           
##     C2                1.125    0.098   11.471    0.000
##     C3                1.003    0.094   10.722    0.000
##     C4               -1.430    0.114  -12.574    0.000
##     C5               -1.527    0.127  -12.042    0.000
##   Extraversion =~                                     
##     E1                1.000                           
##     E2                1.215    0.081   14.933    0.000
##     E3               -0.919    0.067  -13.811    0.000
##     E4               -1.152    0.077  -15.003    0.000
##     E5               -0.879    0.065  -13.544    0.000
##   Neurotic =~                                         
##     N1                1.000                           
##     N2                0.966    0.046   20.952    0.000
##     N3                0.862    0.045   18.964    0.000
##     N4                0.745    0.047   15.830    0.000
##     N5                0.552    0.045   12.320    0.000
##   Opennness =~                                        
##     O1                1.000                           
##     O2               -0.984    0.120   -8.196    0.000
##     O3                1.356    0.128   10.621    0.000
##     O4                0.518    0.088    5.892    0.000
##     O5               -1.036    0.111   -9.315    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable ~~                                        
##     Conscientous     -0.089    0.019   -4.796    0.000
##     Extraversion      0.295    0.044    6.762    0.000
##     Neurotic          0.108    0.028    3.869    0.000
##     Opennness        -0.081    0.018   -4.636    0.000
##   Conscientous ~~                                     
##     Extraversion     -0.268    0.038   -7.061    0.000
##     Neurotic         -0.266    0.043   -6.215    0.000
##     Opennness         0.135    0.025    5.485    0.000
##   Extraversion ~~                                     
##     Neurotic          0.289    0.056    5.166    0.000
##     Opennness        -0.221    0.035   -6.306    0.000
##   Neurotic ~~                                         
##     Opennness        -0.054    0.037   -1.458    0.145
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                2.722    0.050   54.042    0.000
##    .A2                4.481    0.045  100.003    0.000
##    .A3                4.334    0.047   92.228    0.000
##    .A4                4.427    0.052   84.499    0.000
##    .A5                4.361    0.047   93.244    0.000
##    .C1                4.507    0.043  104.245    0.000
##    .C2                4.255    0.047   91.057    0.000
##    .C3                4.207    0.046   90.966    0.000
##    .C4                2.687    0.050   54.023    0.000
##    .C5                3.489    0.058   59.872    0.000
##    .E1                3.267    0.059   55.599    0.000
##    .E2                3.281    0.057   57.217    0.000
##    .E3                3.902    0.049   79.443    0.000
##    .E4                4.235    0.054   78.568    0.000
##    .E5                4.256    0.048   88.011    0.000
##    .N1                2.845    0.055   51.443    0.000
##    .N2                3.288    0.054   60.772    0.000
##    .N3                2.940    0.054   54.258    0.000
##    .N4                3.201    0.056   57.403    0.000
##    .N5                2.476    0.052   47.228    0.000
##    .O1                4.990    0.038  131.870    0.000
##    .O2                2.589    0.054   47.925    0.000
##    .O3                4.522    0.043  105.746    0.000
##    .O4                4.957    0.042  116.875    0.000
##    .O5                2.394    0.048   50.395    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                1.840    0.094   19.556    0.000
##    .A2                0.957    0.057   16.807    0.000
##    .A3                0.739    0.056   13.318    0.000
##    .A4                1.621    0.088   18.368    0.000
##    .A5                0.800    0.056   14.270    0.000
##    .C1                1.039    0.061   17.165    0.000
##    .C2                1.168    0.070   16.791    0.000
##    .C3                1.254    0.071   17.656    0.000
##    .C4                1.040    0.074   14.090    0.000
##    .C5                1.648    0.105   15.764    0.000
##    .E1                1.826    0.102   17.916    0.000
##    .E2                1.238    0.081   15.329    0.000
##    .E3                1.137    0.066   17.141    0.000
##    .E4                1.073    0.071   15.156    0.000
##    .E5                1.146    0.066   17.413    0.000
##    .N1                0.900    0.069   12.987    0.000
##    .N2                0.901    0.067   13.450    0.000
##    .N3                1.205    0.074   16.209    0.000
##    .N4                1.636    0.091   17.981    0.000
##    .N5                1.737    0.091   19.000    0.000
##    .O1                0.768    0.051   15.006    0.000
##    .O2                1.976    0.108   18.262    0.000
##    .O3                0.765    0.069   11.068    0.000
##    .O4                1.344    0.070   19.341    0.000
##    .O5                1.404    0.082   17.207    0.000
##     Agreeable         0.202    0.049    4.133    0.000
##     Conscientous      0.465    0.063    7.430    0.000
##     Extraversion      0.953    0.114    8.357    0.000
##     Neurotic          1.562    0.126   12.410    0.000
##     Opennness         0.385    0.055    7.035    0.000
## 
## 
## Group 2 [2]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable =~                                        
##     A1                1.000                           
##     A2               -1.531    0.136  -11.294    0.000
##     A3               -2.074    0.178  -11.630    0.000
##     A4               -1.577    0.151  -10.452    0.000
##     A5               -1.799    0.158  -11.413    0.000
##   Conscientous =~                                     
##     C1                1.000                           
##     C2                1.143    0.070   16.408    0.000
##     C3                1.045    0.066   15.790    0.000
##     C4               -1.414    0.079  -17.912    0.000
##     C5               -1.467    0.087  -16.805    0.000
##   Extraversion =~                                     
##     E1                1.000                           
##     E2                1.273    0.070   18.267    0.000
##     E3               -0.960    0.055  -17.358    0.000
##     E4               -1.127    0.062  -18.218    0.000
##     E5               -0.786    0.051  -15.331    0.000
##   Neurotic =~                                         
##     N1                1.000                           
##     N2                0.927    0.027   33.767    0.000
##     N3                0.885    0.029   30.411    0.000
##     N4                0.682    0.029   23.169    0.000
##     N5                0.635    0.031   20.360    0.000
##   Opennness =~                                        
##     O1                1.000                           
##     O2               -1.000    0.082  -12.241    0.000
##     O3                1.404    0.088   15.993    0.000
##     O4                0.401    0.057    7.084    0.000
##     O5               -0.904    0.070  -12.936    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Agreeable ~~                                        
##     Conscientous     -0.104    0.014   -7.444    0.000
##     Extraversion      0.265    0.028    9.565    0.000
##     Neurotic          0.174    0.023    7.389    0.000
##     Opennness        -0.102    0.014   -7.384    0.000
##   Conscientous ~~                                     
##     Extraversion     -0.188    0.023   -8.330    0.000
##     Neurotic         -0.263    0.031   -8.584    0.000
##     Opennness         0.132    0.017    7.617    0.000
##   Extraversion ~~                                     
##     Neurotic          0.314    0.038    8.203    0.000
##     Opennness        -0.292    0.027  -10.813    0.000
##   Neurotic ~~                                         
##     Opennness        -0.096    0.028   -3.488    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                2.251    0.034   66.380    0.000
##    .A2                4.953    0.027  182.186    0.000
##    .A3                4.729    0.032  149.206    0.000
##    .A4                4.816    0.036  132.569    0.000
##    .A5                4.633    0.031  151.909    0.000
##    .C1                4.534    0.031  147.786    0.000
##    .C2                4.430    0.032  136.416    0.000
##    .C3                4.346    0.032  137.354    0.000
##    .C4                2.482    0.034   74.039    0.000
##    .C5                3.215    0.040   80.444    0.000
##    .E1                2.836    0.039   71.867    0.000
##    .E2                3.092    0.040   77.887    0.000
##    .E3                4.025    0.033  122.375    0.000
##    .E4                4.495    0.035  127.198    0.000
##    .E5                4.457    0.033  136.018    0.000
##    .N1                2.993    0.039   76.661    0.000
##    .N2                3.631    0.038   96.528    0.000
##    .N3                3.365    0.040   84.763    0.000
##    .N4                3.203    0.039   82.766    0.000
##    .N5                3.216    0.040   79.597    0.000
##    .O1                4.725    0.028  167.191    0.000
##    .O2                2.732    0.039   70.722    0.000
##    .O3                4.414    0.030  148.657    0.000
##    .O4                4.910    0.029  166.987    0.000
##    .O5                2.506    0.032   77.241    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A1                1.672    0.061   27.599    0.000
##    .A2                0.729    0.031   23.276    0.000
##    .A3                0.762    0.040   19.242    0.000
##    .A4                1.646    0.063   26.115    0.000
##    .A5                0.858    0.038   22.336    0.000
##    .C1                1.076    0.044   24.693    0.000
##    .C2                1.120    0.047   23.685    0.000
##    .C3                1.131    0.046   24.538    0.000
##    .C4                0.914    0.047   19.394    0.000
##    .C5                1.616    0.070   22.975    0.000
##    .E1                1.803    0.071   25.564    0.000
##    .E2                1.375    0.062   22.122    0.000
##    .E3                1.085    0.045   23.948    0.000
##    .E4                1.100    0.049   22.249    0.000
##    .E5                1.296    0.050   25.986    0.000
##    .N1                0.746    0.043   17.277    0.000
##    .N2                0.812    0.042   19.534    0.000
##    .N3                1.209    0.052   23.196    0.000
##    .N4                1.632    0.062   26.259    0.000
##    .N5                1.960    0.073   26.908    0.000
##    .O1                0.896    0.039   22.856    0.000
##    .O2                2.027    0.077   26.193    0.000
##    .O3                0.636    0.046   13.686    0.000
##    .O4                1.344    0.048   28.001    0.000
##    .O5                1.384    0.054   25.697    0.000
##     Agreeable         0.204    0.034    6.065    0.000
##     Conscientous      0.460    0.044   10.409    0.000
##     Extraversion      0.737    0.070   10.519    0.000
##     Neurotic          1.740    0.090   19.362    0.000
##     Opennness         0.407    0.041   10.023    0.000

Group plot.

require(semPlot)
require(qgraph)
semPaths(fit_CFA_groups, layout='circle',style = "lisrel",what="std", combineGroups = F)

Measurement invariance table.

The best fitting model based on both AIC and BIC was one with metric invariance (respectively 199471 and 200341). In terms of RMSEA the model with metric invariance and that with strong invariance scored lowest and was thus the best fit (.077). In absolute terms, CFI favoured either the configural or the metric invariance model (0.775). While the metric invariance model is not an adequate fit in terms of CFI (0.775), it is in RMSEA (.077). Both the \(\Delta\)CFI and \(\Delta\)RMSEA suggested that there was no loss in fit moving from a configural model to a metric invariance model (all <.001).

require(semTools)
MI<-measurementInvariance(model=five_factor_groups, data= Data, group="gender")
## 
## Measurement invariance models:
## 
## Model 1 : fit.configural
## Model 2 : fit.loadings
## Model 3 : fit.intercepts
## Model 4 : fit.means
## 
## 
## Chi-Squared Difference Test
## 
##                 Df    AIC    BIC  Chisq Chisq diff    RMSEA Df diff Pr(>Chisq)
## fit.configural 530 199494 200479 4545.3                                       
## fit.loadings   550 199471 200341 4562.6     17.307 0.000000      20     0.6329
## fit.intercepts 570 199646 200400 4777.9    215.312 0.089542      20     <2e-16
## fit.means      575 199823 200547 4964.1    186.241 0.172512       5     <2e-16
##                   
## fit.configural    
## fit.loadings      
## fit.intercepts ***
## fit.means      ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Fit measures:
## 
##                  cfi rmsea cfi.delta rmsea.delta
## fit.configural 0.775 0.079        NA          NA
## fit.loadings   0.775 0.077     0.000       0.001
## fit.intercepts 0.764 0.078     0.011       0.000
## fit.means      0.754 0.079     0.010       0.001

Look at the beauty below… . If you want to export it. Check ‘xtable’.

require(psytabs)
require(knitr)
tab.1 <- measurementInvarianceTable(MI)
# kable!
colnames(tab.1) <-  c("$\\chi^2$",  "df",   "$\\Delta\\chi^2$", "df",   "p", "CFI", "$\\Delta$CFI", "RMSEA", "$\\Delta$RMSEA", "BIC", "$\\Delta$BIC")
kable(tab.1)
\(\chi^2\) df \(\Delta\chi^2\) df p CFI \(\Delta\)CFI RMSEA \(\Delta\)RMSEA BIC \(\Delta\)BIC
Configural 4545.3 530 NA NA NA 0.775 NA 0.079 NA 200479.4 NA
Metric 4562.6 550 17.3 20 0.633 0.775 0.000 0.077 0.001 200340.8 138.7
Scalar 4777.9 570 215.3 20 0.000 0.764 0.011 0.078 0.000 200400.1 -59.3
Mean 4964.1 575 186.2 5 0.000 0.754 0.010 0.079 -0.001 200547.4 -147.3

THE END!

Session Info.

sessionInfo()
## R version 4.3.2 (2023-10-31)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.4
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: Europe/London
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] knitr_1.45           psytabs_0.5-2        mokken_3.1.0        
##  [4] poLCA_1.6.0.1        MASS_7.3-60          scatterplot3d_0.3-44
##  [7] R2HTML_2.2           rtf_0.4-14.1         plyr_1.8.9          
## [10] semTools_0.5-6       qgraph_1.9.8         semPlot_1.1.6       
## [13] stargazer_5.2.3      dplyr_1.1.3          corrplot_0.92       
## [16] ggplot2_3.4.4        lavaan_0.6-17        MVN_5.9             
## [19] skimr_2.1.5          psych_2.4.1         
## 
## loaded via a namespace (and not attached):
##   [1] mnormt_2.1.1       pbapply_1.7-2      gridExtra_2.3     
##   [4] sandwich_3.0-2     fdrtool_1.2.17     rlang_1.1.3       
##   [7] magrittr_2.0.3     multcomp_1.4-25    rockchalk_1.8.157 
##  [10] compiler_4.3.2     png_0.1-8          vctrs_0.6.5       
##  [13] reshape2_1.4.4     gsl_2.1-8          OpenMx_2.21.8     
##  [16] quadprog_1.5-8     stringr_1.5.1      pkgconfig_2.0.3   
##  [19] fastmap_1.1.1      arm_1.13-1         backports_1.4.1   
##  [22] energy_1.7-11      pbivnorm_0.6.0     utf8_1.2.4        
##  [25] rmarkdown_2.26     nloptr_2.0.3       purrr_1.0.2       
##  [28] xfun_0.43          cachem_1.0.8       kutils_1.73       
##  [31] jsonlite_1.8.8     highr_0.10         jpeg_0.1-10       
##  [34] parallel_4.3.2     cluster_2.1.4      R6_2.5.1          
##  [37] bslib_0.7.0        stringi_1.8.3      car_3.1-2         
##  [40] boot_1.3-28.1      rpart_4.1.21       estimability_1.4.1
##  [43] jquerylib_0.1.4    Rcpp_1.0.11        zoo_1.8-12        
##  [46] base64enc_0.1-3    Matrix_1.6-1.1     splines_4.3.2     
##  [49] nnet_7.3-19        igraph_2.0.3       tidyselect_1.2.0  
##  [52] rstudioapi_0.16.0  abind_1.4-5        yaml_2.3.8        
##  [55] codetools_0.2-19   lattice_0.21-9     tibble_3.2.1      
##  [58] withr_2.5.2        coda_0.19-4        evaluate_0.23     
##  [61] moments_0.14.1     foreign_0.8-85     survival_3.5-7    
##  [64] RcppParallel_5.1.7 zip_2.3.0          pillar_1.9.0      
##  [67] carData_3.0-5      checkmate_2.3.0    nortest_1.0-4     
##  [70] stats4_4.3.2       generics_0.1.3     munsell_0.5.1     
##  [73] scales_1.3.0       minqa_1.2.6        gtools_3.9.4      
##  [76] xtable_1.8-4       glue_1.7.0         mi_1.1            
##  [79] emmeans_1.8.9      Hmisc_5.1-1        tools_4.3.2       
##  [82] data.table_1.14.10 lme4_1.1-35        openxlsx_4.2.5.2  
##  [85] mvtnorm_1.2-3      XML_3.99-0.15      grid_4.3.2        
##  [88] sem_3.1-15         tidyr_1.3.0        colorspace_2.1-0  
##  [91] nlme_3.1-163       repr_1.1.6         htmlTable_2.4.2   
##  [94] Formula_1.2-5      cli_3.6.2          fansi_1.0.6       
##  [97] corpcor_1.6.10     glasso_1.11        gtable_0.3.4      
## [100] R.methodsS3_1.8.2  sass_0.4.9         digest_0.6.35     
## [103] TH.data_1.1-2      htmlwidgets_1.6.2  R.oo_1.25.0       
## [106] htmltools_0.5.8.1  lifecycle_1.0.4    lisrelToR_0.1.5