Project 2 - EDUS 662 - Confirmatory Factor Analysis (CFA)

Author

Maggie Gatongi

Load Libraries

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(psych)

Attaching package: 'psych'

The following objects are masked from 'package:ggplot2':

    %+%, alpha

Load and View Data

mse_data <- read.csv("Project2_data.csv")
view(mse_data)

View Data Structure

str(mse_data)
'data.frame':   450 obs. of  9 variables:
 $ id        : int  1 2 3 4 5 6 7 8 9 10 ...
 $ gender    : chr  "male" "female" "female" "female" ...
 $ ses       : num  0.1402 0.1493 -0.1112 0.0876 -0.7549 ...
 $ math_score: num  56.2 56.6 50.4 38.1 34.3 ...
 $ career    : chr  "Non-STEM" "Non-STEM" "Non-STEM" "Non-STEM" ...
 $ mse1      : int  3 3 3 3 3 3 3 3 2 4 ...
 $ mse2      : int  2 2 3 2 3 3 2 4 2 4 ...
 $ mse3      : int  3 3 4 3 3 3 3 4 3 4 ...
 $ mse4      : int  3 4 4 2 3 3 3 4 3 4 ...

Select MSE Items from the Data

project2data <- mse_data[, c("mse1", "mse2", "mse3", "mse4")]

view(project2data)
print(project2data)
    mse1 mse2 mse3 mse4
1      3    2    3    3
2      3    2    3    4
3      3    3    4    4
4      3    2    3    2
5      3    3    3    3
6      3    3    3    3
7      3    2    3    3
8      3    4    4    4
9      2    2    3    3
10     4    4    4    4
11     3    3    3    3
12     2    2    2    2
13     4    4    4    4
14     4    4    4    4
15     3    3    2    3
16     2    2    3    3
17     2    3    2    3
18     3    2    3    4
19     4    3    4    4
20     2    2    3    3
21     3    3    2    3
22     2    1    2    3
23     3    2    3    3
24     3    2    3    3
25     4    2    4    4
26     4    4    4    4
27     1    1    1    1
28     2    3    3    3
29     3    3    3    3
30     2    2    2    3
31     4    4    4    4
32     3    3    4    4
33     4    4    4    4
34     3    2    2    3
35     3    3    2    3
36     4    3    3    3
37     3    3    3    3
38     2    3    3    3
39     3    3    3    3
40     1    1    1    1
41     3    3    3    3
42     4    4    4    4
43     2    2    3    3
44     3    2    3    3
45     3    2    3    3
46     3    2    3    3
47     4    3    3    3
48     3    3    3    3
49     3    3    3    3
50     3    2    3    2
51     3    2    3    3
52     3    3    3    3
53     4    2    4    4
54     3    3    3    3
55     4    4    4    4
56     3    3    3    3
57     4    4    4    4
58     3    3    3    3
59     3    3    3    2
60     4    4    4    4
61     3    4    3    4
62     2    3    3    2
63     4    3    4    4
64     3    3    3    3
65     4    4    4    4
66     3    3    3    3
67     4    4    4    4
68     4    4    4    4
69     3    3    2    3
70     3    2    3    3
71     2    1    1    2
72     3    3    3    3
73     4    4    4    4
74     3    3    3    3
75     2    2    3    3
76     3    2    3    3
77     3    2    3    3
78     3    3    3    3
79     2    2    2    2
80     4    3    3    4
81     3    3    3    3
82     3    3    3    3
83     3    3    4    4
84     4    3    3    3
85     2    3    2    2
86     3    3    3    3
87     4    4    4    4
88     4    4    4    4
89     3    2    3    3
90     2    1    3    2
91     3    3    2    3
92     2    1    2    3
93     3    3    3    3
94     1    1    2    1
95     3    4    4    4
96     3    3    2    3
97     3    3    2    3
98     4    4    4    4
99     3    3    4    4
100    3    1    3    3
101    3    3    3    3
102    3    2    2    3
103    4    4    4    4
104    3    2    2    4
105    4    4    4    4
106    4    3    2    2
107    3    3    3    3
108    3    3    3    3
109    3    2    3    3
110    2    3    3    3
111    4    3    3    4
112    3    3    3    4
113    4    4    4    4
114    3    3    2    3
115    3    3    3    3
116    3    3    3    3
117    4    3    2    1
118    2    3    2    2
119    4    3    3    4
120    3    3    3    3
121    2    2    2    2
122    3    2    3    3
123    3    3    3    3
124    3    3    3    3
125    3    3    3    3
126    2    3    3    3
127    2    2    2    3
128    4    4    4    4
129    3    3    3    3
130    4    4    4    4
131    4    4    4    4
132    3    3    3    3
133    3    2    2    3
134    3    3    3    3
135    3    3    3    3
136    2    3    3    2
137    3    3    3    3
138    3    3    3    3
139    2    2    2    2
140    3    3    3    3
141    3    3    4    3
142    3    2    2    2
143    3    3    3    3
144    2    3    3    2
145    3    2    3    3
146    3    3    2    2
147    2    1    3    2
148    3    3    3    3
149    2    2    2    2
150    4    3    3    4
151    4    3    3    4
152    2    2    3    2
153    3    3    2    4
154    3    3    3    3
155    3    3    3    3
156    1    1    1    1
157    4    4    4    4
158    3    3    2    3
159    3    3    3    3
160    3    3    2    4
161    3    2    3    3
162    3    3    3    3
163    3    3    3    3
164    4    4    4    3
165    3    3    4    4
166    4    4    4    4
167    2    1    3    3
168    2    2    3    2
169    2    3    2    3
170    3    3    3    3
171    3    3    4    4
172    2    2    3    2
173    3    3    3    3
174    2    2    2    3
175    2    2    3    3
176    4    4    4    4
177    3    3    3    3
178    3    3    3    3
179    3    3    3    3
180    2    3    2    3
181    3    3    3    3
182    3    3    2    3
183    2    1    3    3
184    3    2    4    3
185    3    2    3    3
186    4    4    4    4
187    3    3    3    3
188    3    2    3    3
189    3    3    3    3
190    3    3    2    3
191    2    2    2    2
192    3    3    3    3
193    3    2    3    3
194    4    2    3    2
195    2    2    2    2
196    2    1    2    3
197    3    2    2    3
198    3    3    3    3
199    1    1    1    1
200    2    2    3    3
201    3    2    2    3
202    2    3    3    2
203    4    3    3    3
204    2    2    3    3
205    3    3    3    3
206    3    3    3    4
207    3    3    3    4
208    3    2    3    3
209    4    3    4    4
210    4    4    4    4
211    2    2    3    3
212    3    3    3    3
213    3    2    2    3
214    2    3    2    2
215    3    3    2    3
216    2    3    2    3
217    3    2    4    3
218    2    2    3    3
219    2    1    3    2
220    3    3    3    3
221    2    1    2    2
222    1    1    1    1
223    4    3    4    4
224    3    3    3    3
225    4    4    4    4
226    2    2    2    3
227    3    3    3    3
228    3    2    3    3
229    3    3    3    3
230    4    4    4    4
231    3    2    3    3
232    2    2    3    2
233    3    3    3    3
234    4    4    4    4
235    3    2    3    2
236    2    2    2    2
237    2    2    2    2
238    3    3    3    3
239    4    4    4    4
240    4    4    3    4
241    3    3    3    4
242    3    2    3    3
243    3    3    3    3
244    4    4    4    4
245    3    4    3    3
246    1    2    2    2
247    3    2    4    3
248    4    4    4    4
249    2    2    2    3
250    2    2    2    2
251    3    3    3    3
252    2    2    3    2
253    2    2    2    2
254    1    1    2    2
255    3    3    3    3
256    3    3    3    3
257    4    3    3    3
258    2    3    3    4
259    2    2    3    3
260    2    2    3    3
261    3    3    2    3
262    3    3    3    3
263    4    4    3    3
264    2    3    3    3
265    4    3    3    3
266    2    2    3    3
267    3    3    3    3
268    1    2    3    4
269    4    4    4    4
270    3    3    4    4
271    3    2    3    3
272    3    3    3    3
273    2    2    3    3
274    4    4    3    3
275    3    3    4    3
276    3    4    4    4
277    3    3    3    3
278    3    3    3    3
279    4    4    4    4
280    2    3    3    3
281    3    2    3    3
282    3    3    3    3
283    3    2    3    3
284    2    2    2    2
285    4    4    4    4
286    2    2    3    3
287    4    4    4    4
288    3    3    3    3
289    3    3    3    3
290    4    4    4    4
291    4    4    4    4
292    3    3    3    3
293    2    2    2    2
294    3    2    3    3
295    2    3    3    3
296    2    2    2    2
297    4    4    4    4
298    3    3    3    3
299    4    4    4    4
300    3    3    3    3
301    2    3    2    3
302    2    2    3    2
303    3    3    4    4
304    4    4    4    4
305    3    3    3    3
306    3    3    3    3
307    3    4    3    4
308    3    2    3    3
309    4    4    4    4
310    3    3    3    3
311    4    3    4    3
312    2    2    1    2
313    2    3    3    3
314    3    3    3    3
315    4    3    4    4
316    3    2    3    3
317    3    3    3    3
318    2    2    3    4
319    4    4    3    4
320    3    3    3    3
321    3    3    3    3
322    2    3    4    4
323    3    3    3    3
324    4    4    4    4
325    4    3    3    3
326    3    2    3    3
327    3    2    3    3
328    3    3    2    3
329    4    4    3    4
330    2    4    3    2
331    3    3    3    3
332    4    3    3    4
333    3    3    3    3
334    3    2    3    3
335    4    4    4    4
336    3    2    3    3
337    4    3    4    4
338    4    3    3    4
339    2    3    3    4
340    4    4    4    4
341    3    3    3    3
342    3    4    4    4
343    3    3    3    1
344    4    4    4    4
345    4    4    4    4
346    3    3    4    3
347    3    2    3    3
348    3    3    3    3
349    3    3    3    3
350    4    4    4    4
351    3    3    3    3
352    4    4    4    4
353    2    2    3    3
354    3    2    2    3
355    4    3    4    4
356    4    4    4    4
357    3    3    3    3
358    3    2    3    3
359    4    4    4    4
360    2    2    2    2
361    3    2    3    3
362    4    3    3    4
363    3    3    3    3
364    3    3    2    3
365    4    4    4    4
366    4    3    4    4
367    4    4    4    2
368    3    3    2    3
369    3    3    3    3
370    3    3    4    4
371    4    4    4    4
372    3    3    3    3
373    3    3    3    3
374    3    3    3    3
375    3    3    3    4
376    4    4    4    4
377    3    2    3    4
378    3    3    3    3
379    3    3    4    4
380    3    3    3    2
381    3    2    4    4
382    3    2    2    3
383    3    3    3    3
384    3    3    3    4
385    3    2    3    3
386    2    2    2    2
387    4    4    4    4
388    3    2    2    3
389    3    3    3    3
390    3    3    3    3
391    4    3    4    4
392    3    3    3    3
393    2    2    2    2
394    3    3    3    4
395    2    3    2    2
396    4    4    4    3
397    2    1    2    3
398    2    2    3    2
399    2    2    3    2
400    4    3    2    3
401    4    4    3    4
402    2    3    3    3
403    2    2    2    2
404    4    4    4    4
405    4    4    4    4
406    4    4    4    4
407    3    2    3    3
408    3    3    3    3
409    3    3    3    3
410    3    3    3    3
411    3    3    3    3
412    2    1    2    2
413    4    3    4    4
414    2    2    3    2
415    4    4    3    4
416    4    3    4    4
417    4    3    3    3
418    2    2    3    3
419    3    2    3    3
420    4    4    4    4
421    4    3    2    3
422    3    3    3    3
423    2    2    3    3
424    3    4    4    4
425    3    2    3    4
426    3    3    2    3
427    4    4    4    4
428    4    3    4    4
429    4    4    4    3
430    3    3    3    3
431    4    3    3    3
432    4    4    4    4
433    3    3    3    3
434    3    2    3    3
435    3    2    3    3
436    3    3    3    3
437    2    2    2    2
438    3    2    3    3
439    1    1    1    2
440    4    4    4    4
441    4    4    4    4
442    3    3    3    3
443    1    1    1    1
444    3    2    3    3
445    3    3    2    3
446    4    4    4    4
447    3    3    3    2
448    2    2    2    2
449    3    3    3    3
450    3    4    3    4

Checking for Normality

The data is not normal given the hz test statistic () Since the p-value is less than 0.05, we will reject the null hypothesis. This suggests that the dataset does NOT follow a multivariate normal distribution.

#  Install and load the MVN package

#install.packages("MVN")

library(MVN)

# Henze-Zirkler's multivariate normality test

hz_test <- mvn(data = project2data, mvnTest = "hz")

# Display the results

hz_test
$multivariateNormality
           Test       HZ p value MVN
1 Henze-Zirkler 33.94104       0  NO

$univariateNormality
              Test  Variable Statistic   p value Normality
1 Anderson-Darling   mse1      34.1727  <0.001      NO    
2 Anderson-Darling   mse2      29.6210  <0.001      NO    
3 Anderson-Darling   mse3      39.0862  <0.001      NO    
4 Anderson-Darling   mse4      40.5581  <0.001      NO    

$Descriptives
       n     Mean   Std.Dev Median Min Max 25th 75th       Skew    Kurtosis
mse1 450 3.000000 0.7461855      3   1   4    3    4 -0.3530132 -0.26181042
mse2 450 2.820000 0.7958971      3   1   4    2    3 -0.2503107 -0.41732108
mse3 450 3.024444 0.7043155      3   1   4    3    3 -0.3774284  0.03432538
mse4 450 3.120000 0.6992201      3   1   4    3    4 -0.5187700  0.28405032

Model Specification

# Install and load the lavaan package

#install.packages("lavaan")
library(lavaan)
This is lavaan 0.6-18
lavaan is FREE software! Please report any bugs.

Attaching package: 'lavaan'
The following object is masked from 'package:psych':

    cor2cov
# specify the model

model <- 'mse =~ mse1 + mse2 + mse3 + mse4'

Model Estimation: Robust Maximum Likelihood

 cfa(model, data = project2data, estimator = "MLR", bootstrap = 1000)
lavaan 0.6-18 ended normally after 22 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         8

  Number of observations                           450

Model Test User Model:
                                              Standard      Scaled
  Test Statistic                                19.471      14.946
  Degrees of freedom                                 2           2
  P-value (Chi-square)                           0.000       0.001
  Scaling correction factor                                  1.303
    Yuan-Bentler correction (Mplus variant)                       

Model Estimation

onefactor_fit<- cfa(model, data=project2data, estimator = "MLR", bootstrap = 1000) 

Model Evaluation before modification

summary(onefactor_fit, fit.measures=TRUE, standardized=TRUE) 
lavaan 0.6-18 ended normally after 22 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         8

  Number of observations                           450

Model Test User Model:
                                              Standard      Scaled
  Test Statistic                                19.471      14.946
  Degrees of freedom                                 2           2
  P-value (Chi-square)                           0.000       0.001
  Scaling correction factor                                  1.303
    Yuan-Bentler correction (Mplus variant)                       

Model Test Baseline Model:

  Test statistic                              1036.086     636.985
  Degrees of freedom                                 6           6
  P-value                                        0.000       0.000
  Scaling correction factor                                  1.627

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.983       0.979
  Tucker-Lewis Index (TLI)                       0.949       0.938
                                                                  
  Robust Comparative Fit Index (CFI)                         0.984
  Robust Tucker-Lewis Index (TLI)                            0.951

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -1490.557   -1490.557
  Scaling correction factor                                  1.375
      for the MLR correction                                      
  Loglikelihood unrestricted model (H1)      -1480.821   -1480.821
  Scaling correction factor                                  1.360
      for the MLR correction                                      
                                                                  
  Akaike (AIC)                                2997.113    2997.113
  Bayesian (BIC)                              3029.987    3029.987
  Sample-size adjusted Bayesian (SABIC)       3004.598    3004.598

Root Mean Square Error of Approximation:

  RMSEA                                          0.139       0.120
  90 Percent confidence interval - lower         0.087       0.074
  90 Percent confidence interval - upper         0.199       0.172
  P-value H_0: RMSEA <= 0.050                    0.003       0.008
  P-value H_0: RMSEA >= 0.080                    0.968       0.925
                                                                  
  Robust RMSEA                                               0.137
  90 Percent confidence interval - lower                     0.078
  90 Percent confidence interval - upper                     0.205
  P-value H_0: Robust RMSEA <= 0.050                         0.010
  P-value H_0: Robust RMSEA >= 0.080                         0.944

Standardized Root Mean Square Residual:

  SRMR                                           0.022       0.022

Parameter Estimates:

  Standard errors                             Sandwich
  Information bread                           Observed
  Observed information based on                Hessian

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  mse =~                                                                
    mse1              1.000                               0.635    0.852
    mse2              0.999    0.042   23.537    0.000    0.634    0.797
    mse3              0.899    0.046   19.454    0.000    0.571    0.811
    mse4              0.904    0.043   21.093    0.000    0.574    0.822

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .mse1              0.153    0.022    6.805    0.000    0.153    0.275
   .mse2              0.230    0.022   10.359    0.000    0.230    0.364
   .mse3              0.169    0.018    9.434    0.000    0.169    0.342
   .mse4              0.158    0.024    6.725    0.000    0.158    0.325
    mse               0.403    0.037   10.745    0.000    1.000    1.000

The model demonstrates a good fit, with the following factor loadings and fit indices: χ²(2) , CFI = 0.983, TLI = 0.949, RMSEA = 0.139, and SRMR = 0.022. Of the fit indixces. However, the chi-square index ( χ²(2) = 19.41, p < 0.05) did not demonstrate a good fit as the p-value was < 0.05. The standardized factor loadings for mse factor were 0.852 for mse1, 0.797 for mse2, 0.811 for mse3, and 0.822 for mse4. These results indicate that the observed variables can be explained by the mse factor, and the model provides a good fit to the data.

CFA Visualization before modification

# Install and load the semPlot package

#install.packages("semPlot")
library("semPlot")

# Create a visual diagram of the CFA or SEM model.

semPaths(onefactor_fit, whatLabels="std", sizeMan=10, edge.label.cex=1) # "std"=> displaying standardized values; change sizeMan and edge.label.cex to adjust the font size

Model Modification

modificationindices(onefactor_fit, sort. = TRUE)
    lhs op  rhs     mi    epc sepc.lv sepc.all sepc.nox
10 mse1 ~~ mse2 20.312  0.072   0.072    0.383    0.383
15 mse3 ~~ mse4 20.312  0.058   0.058    0.357    0.357
11 mse1 ~~ mse3  7.648 -0.040  -0.040   -0.247   -0.247
14 mse2 ~~ mse4  7.648 -0.040  -0.040   -0.209   -0.209
12 mse1 ~~ mse4  3.102 -0.026  -0.026   -0.165   -0.165
13 mse2 ~~ mse3  3.102 -0.025  -0.025   -0.129   -0.129

Specification of Modified Model

Modification with added mse3 and mse4 correlation based on modificaiton indices results. The is followed by fitting the model again. The chi-square p-value has improved as a result (p>.05).

model2 <-'mse =~ mse1 + mse2 + mse3 + mse4
          mse3~~mse4'

# Fit the model again

onefactor_fit2<- cfa(model2, data=project2data, estimator = "MLR", bootstrap = 1000)

# Summarize the modified model

summary(onefactor_fit2, fit.measures=TRUE, standardized=TRUE)
lavaan 0.6-18 ended normally after 22 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         9

  Number of observations                           450

Model Test User Model:
                                              Standard      Scaled
  Test Statistic                                 0.412       0.310
  Degrees of freedom                                 1           1
  P-value (Chi-square)                           0.521       0.578
  Scaling correction factor                                  1.330
    Yuan-Bentler correction (Mplus variant)                       

Model Test Baseline Model:

  Test statistic                              1036.086     636.985
  Degrees of freedom                                 6           6
  P-value                                        0.000       0.000
  Scaling correction factor                                  1.627

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    1.000       1.000
  Tucker-Lewis Index (TLI)                       1.003       1.007
                                                                  
  Robust Comparative Fit Index (CFI)                         1.000
  Robust Tucker-Lewis Index (TLI)                            1.005

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -1481.027   -1481.027
  Scaling correction factor                                  1.364
      for the MLR correction                                      
  Loglikelihood unrestricted model (H1)      -1480.821   -1480.821
  Scaling correction factor                                  1.360
      for the MLR correction                                      
                                                                  
  Akaike (AIC)                                2980.054    2980.054
  Bayesian (BIC)                              3017.037    3017.037
  Sample-size adjusted Bayesian (SABIC)       2988.475    2988.475

Root Mean Square Error of Approximation:

  RMSEA                                          0.000       0.000
  90 Percent confidence interval - lower         0.000       0.000
  90 Percent confidence interval - upper         0.107       0.086
  P-value H_0: RMSEA <= 0.050                    0.707       0.815
  P-value H_0: RMSEA >= 0.080                    0.136       0.065
                                                                  
  Robust RMSEA                                               0.000
  90 Percent confidence interval - lower                     0.000
  90 Percent confidence interval - upper                     0.118
  P-value H_0: Robust RMSEA <= 0.050                         0.712
  P-value H_0: Robust RMSEA >= 0.080                         0.159

Standardized Root Mean Square Residual:

  SRMR                                           0.003       0.003

Parameter Estimates:

  Standard errors                             Sandwich
  Information bread                           Observed
  Observed information based on                Hessian

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  mse =~                                                                
    mse1              1.000                               0.656    0.880
    mse2              0.986    0.046   21.283    0.000    0.647    0.814
    mse3              0.820    0.041   19.779    0.000    0.538    0.765
    mse4              0.827    0.041   20.304    0.000    0.543    0.777

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
 .mse3 ~~                                                               
   .mse4              0.056    0.017    3.369    0.001    0.056    0.282

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .mse1              0.125    0.020    6.166    0.000    0.125    0.225
   .mse2              0.214    0.024    8.990    0.000    0.214    0.338
   .mse3              0.206    0.020   10.476    0.000    0.206    0.416
   .mse4              0.193    0.027    7.073    0.000    0.193    0.396
    mse               0.431    0.037   11.521    0.000    1.000    1.000

The model demonstrates a strong fit to the data, with excellent factor loadings and fit indices: χ²(1) = 0.412, p = 0.521; CFI = 1.000, TLI = 1.003; RMSEA = 0.000; and SRMR = 0.003. The standardized factor loadings for mse factor were 0.880 for mse1, 0.814 for mse2, 0.765 for mse3, and 0.777 for mse4. Additionally, the mse3 and mse4 items showed a weak positive correlation (r = 0.282). These results indicate that the observed variables are well-explained by their respective factors, and the model provides a good fit to the data.

CFA Visualization after modification (Model 2)

# Create a visual diagram of the modified CFA model.

semPaths(onefactor_fit2, whatLabels="std", sizeMan=10, edge.label.cex=1) # "std"=> displaying standardized values; change sizeMan and edge.label.cex to adjust the font size

Model2 Modification

Modification indices between correlations are equal, based on results.

modificationindices(onefactor_fit2, sort. = TRUE)
    lhs op  rhs    mi    epc sepc.lv sepc.all sepc.nox
15 mse2 ~~ mse4 0.412 -0.009  -0.009   -0.046   -0.046
12 mse1 ~~ mse3 0.412 -0.009  -0.009   -0.059   -0.059
13 mse1 ~~ mse4 0.412  0.010   0.010    0.061    0.061
14 mse2 ~~ mse3 0.412  0.009   0.009    0.045    0.045

Obtain factor scores from the modified CFA model

# Compute the factor scores

factorscores <- lavPredict(onefactor_fit2) # lavPredict(): This function computes the factor scores for the latent variables (e.g., verbal and math) based on the fitted CFA model (twofactor_fit).

factorscores <- as.data.frame(factorscores)  # Convert matrix to dataframe

# Descriptive Statistics for Factor Scores:

library("psych")
describe(factorscores$mse)
   vars   n mean   sd median trimmed  mad   min  max range  skew kurtosis   se
X1    1 450    0 0.62   0.02    0.02 0.56 -1.87 0.96  2.83 -0.27     0.15 0.03
#describe(factorscores$math)

# Column-binds two datasets

newdata <- cbind(project2data, factorscores)  # column-bind two data sets
head(newdata) # Display the first six rows of newdata.
  mse1 mse2 mse3 mse4         mse
1    3    2    3    3 -0.21136343
2    3    2    3    4 -0.04336235
3    3    3    4    4  0.33683102
4    3    2    3    2 -0.37936452
5    3    3    3    3  0.01729400
6    3    3    3    3  0.01729400

Composite Reliability (Coefficient Omega)

Composite Reliability (McDonald’s Omega) calculates the ratio of the variance explained by the latent factor to the total variance (true + error), making it a more flexible and accurate reliability measure than Cronbach’s Alpha, especially when factor loadings vary across items.

  • Coefficient Omega (McDonald’s Omega): A measure of internal consistency reliability, particularly useful when items load on multiple factors or when factor loadings are unequal. It is often considered a more robust alternative to Cronbach’s alpha.

  • Cronbach’s Alpha: A traditional measure of internal consistency, which assumes that all items are equally reliable and load on a single factor. It can underestimate reliability in some cases, which is why omega is preferred in more complex models.

# Install and load the semTools package

#install.packages("semTools")
library("semTools")
 
###############################################################################
This is semTools 0.5-6
All users of R (or SEM) are invited to submit functions or ideas for functions.
###############################################################################

Attaching package: 'semTools'
The following objects are masked from 'package:psych':

    reliability, skew
The following object is masked from 'package:readr':

    clipboard
# Report "omega" & "alpha" for this study

reliability(onefactor_fit2)  
             mse
alpha  0.8903129
omega  0.8698698
omega2 0.8698698
omega3 0.8698351
avevar 0.6601952
  • Alpha (Cronbach’s Alpha) for mse =0.890 which is approximately 0.90

    • Cronbach’s alpha is a traditional measure of internal consistency. The value indicates excellent reliability, as values above 0.90 are considered very strong. Alpha assumes that all items have equal factor loadings, which can sometimes underestimate the true reliability in more complex models.
  • Omega (McDonald’s Omega) for mse = 0.869

    • Omega is generally regarded as a more robust measure of reliability, especially when factor loadings differ across items or when the construct is multidimensional. The omega value is slightly below 0.90, indicating close to excellent internal consistency.