-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPSQF6249_Example04_CFA_simulated_lavaan.Rmd
More file actions
1267 lines (874 loc) · 69.1 KB
/
Copy pathPSQF6249_Example04_CFA_simulated_lavaan.Rmd
File metadata and controls
1267 lines (874 loc) · 69.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "PSQF 6249 Example 03"
# output:
# html_document: default
# html_notebook: default
# pdf_document: default
---
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: {
autoNumber: "all",
formatNumber: function (n) {return n}
}
}
});
</script>
## CFA Example Using _Simulated_ Forgiveness of Situations (N = 1103)
The Forgiveness of Situations Subscale includes six items, three of which are reverse-coded, on a seven-point scale:
1. When things go wrong for reasons that can’t be controlled, I get stuck in negative thoughts about it. (R)
2. With time I can be understanding of bad circumstances in my life.
3. If I am disappointed by uncontrollable circumstances in my life, I continue to think negatively about them. (R)
4. I eventually make peace with bad situations in my life.
5. It’s really hard for me to accept negative situations that aren’t anybody’s fault. (R)
6. Eventually I let go of negative thoughts about bad circumstances that are beyond anyone’s control.
Response Anchors:
* 1 = Almost Always False of Me
* 2 = ?
* 3 = More Often False of Me
* 4 = ?
* 5 = More Often True of Me
* 6 = ?
* 7 = Almost Always True of Me
_Note: the data for this example are simulated based on the results of the real data analysis. These results will be different than those reported in the other example file but are used to show you how to execute the syntax in this analysis._
### Package Installation and Loading
For this example, we will be using the ```ggplot2``` (for general plotting), ```melt2``` (for data reshaping before plotting), and ```lavaan``` (for CFA) packages.
```{r setup, include=TRUE}
if (require(ggplot2)==FALSE){
install.packages("ggplot2")
}
library(ggplot2)
if (require(reshape2) == FALSE){
install.packages("reshape2")
}
if (require(lavaan) == FALSE){
install.packages("lavaan")
}
library(lavaan)
if (require(psych) == FALSE){
install.packages("psych")
}
if (require(knitr) == FALSE){
install.packages("knitr")
}
if (require(kableExtra) == FALSE){
install.packages("kableExtra")
}
if (require(semPlot) == FALSE){
install.packages("semPlot")
}
```
### Data Import into R
The data are in a text file named ```Study2.dat``` originally used in Mplus (so no column names were included at the top of the file). The file contains more items than we will use, so we select only the "Forgiveness of Situations" items from the whole file.
```{r data, include=TRUE}
#syntax from previous example: commented to remove for simulation
# #read in data file (Mplus file format so having to label columns)
# hfsData = read.table(file = "Study2.dat", header = FALSE, na.strings = "99999", col.names = c("PersonID", "Self1", "Self2r", "Self3", "Self4r", "Self5", "Self6r", "Other1r", "Other2", "Other3r", "Other4", "Other5r", "Other6", "Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6", "Selfsub", "Othsub", "Sitsub", "HFSsum"))
#
# #select Situations items and PersonID variables
# hfsSituations = hfsData[c("PersonID", "Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6")]
#setting seed for output constancy across machines
set.seed(04092017)
# simulating data for analysis based on results of model04estimates
model04Simulate = "
# SitP loadings (all estimated)
SitP =~ 1.007*Sit2 + 1.064*Sit4 + 0.956*Sit6
# SitN loadings (all estimated)
SitN =~ 1.325*Sit1r + 1.349*Sit3r + 1.009*Sit5r
# Unique Variances:
Sit1r ~~ 1.294*Sit1r; Sit2 ~~ 0.888*Sit2; Sit3r ~~ 0.724*Sit3r; Sit4 ~~ 0.835*Sit4; Sit5r ~~ 1.926*Sit5r; Sit6 ~~ 1.428*Sit6;
# Item Intercepts:
Sit2 ~ 5.289*1
Sit4 ~ 5.359*1
Sit6 ~ 5.321*1
Sit1r ~ 4.547*1
Sit3r ~ 4.896*1
Sit5r ~ 4.860*1
# Factor Covariances
SitP ~~ .564*SitN
"
#generate data
hfsSituations = simulateData(model = model04Simulate, sample.nobs = 1103L, model.type = "sem")
#add ID variable
hfsSituations = data.frame(PersonID = 1:1103, hfsSituations)
#reorder variables to match data file
hfsSituations = hfsSituations[c("PersonID", "Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6")]
```
### Observed Sample Statistics
#### Sample Correlation Matrix
The observed correlation matrix, rounded to three digits:
```{r correlations, include=TRUE}
#here the c() function selects only the variables, not the PersionID variable
round(cor(hfsSituations[c("Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6")]), digits = 3)
```
#### Sample Means and Variances
The observed means, rounded to three digits:
```{r means, include=TRUE}
apply(X = hfsSituations[c("Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6")], MARGIN = 2, FUN = function(x) round(mean(x), digits = 3))
```
The observed variances (using $N$ in the denominator to match ML estimated output and Mplus example), rounded to three digits:
```{r variances, include=TRUE}
apply(X = hfsSituations[c("Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6")], MARGIN = 2, FUN = function(x) round(var(x, na.rm = TRUE)*1102/1103, digits = 3))
```
#### Sample Covariances
To do a CFA analysis, you only really need means, variances, and either correlations or covariances among items. That said, modern methods of estimation use the raw data (often called full information) rather than the summary statistics as the raw data enable better missing data assumptions when using maximum likelihood and Bayesian estimation methods.
The sample covariance matrix can be found from the sample correlations and variances. Each covariance between a pair of variables $y_1$ and $y_2$ is denoted with a $\sigma_{y_1, y_2}$ and each correlation is denoted with a $\rho_{y_1, y_2}$. The variance of a variable is denoted by $\sigma^2_{y_1}$ and the standard deviation of a variable is the square root of the variance $\sqrt{\sigma^2_{y_1}}$. The covariance can be found by taking the correlation and multiplying it by the product of the standard deviations.
$$\sigma_{y_1, y_2} = \rho_{y_1, y_2}\sqrt{\sigma^2_{y_1}}\sqrt{\sigma^2_{y_2}}. $$
Inversely, the correlation can be found by taking the covariance and dividing it by the product of the standard deviations:
$$\rho_{y_1, y_2} = \frac{\sigma_{y_1, y_2}}{\sqrt{\sigma^2_{y_1}}\sqrt{\sigma^2_{y_2}}}. $$
Again, we change the denominator from $N-1$ to $N$ to be consistent with the Mplus example, which calculates covariances using maximum likelihood.
```{r covariances, include=TRUE}
round(cov(hfsSituations[c("Sit1r", "Sit2", "Sit3r", "Sit4", "Sit5r", "Sit6")])*1102/1103, digits = 3)
```
#### Sample Item Response Distributions
The assumptions of CFA (i.e., normally distributed factors, no item-level factor interactions, and conditionally normal distributed items) lead to the overall assumption that our item responses must be normally distributed. From the histograms below, do you think these are normally distributed?
```{r histograms, include=TRUE}
#stack data
melted = melt(hfsSituations, id.vars = "PersonID")
#plot by variable
ggplot(melted, aes(value)) + geom_density() + facet_wrap(~ variable)
```
### Lavaan Syntax
lavaan syntax is constructed using a long text string and saved in a character object. In the example below ```model01SyntaxLong = "``` opens the text string, which continues for multiple lines until the final ```"``` terminates the string. The variable model01Syntax now contains the text of the ```lavaan``` syntax. Within the syntax string, the R comment character ```#``` still functions to comment text around the syntax. Each part of the model syntax corresponds to a set of parameters in the CFA model. You can find information about lavaan at [https://lavaan.ugent.be](https://lavaan.ugent.be).
```{r lavaanLong, include=TRUE}
model01SyntaxLong = "
# Model 1 -- Fully Z-Scored Factor Identification Approach
# Item factor loadings --> list the factor to the left of the =~ and the items to the right, separated by a plus
# Once the factor is defined it can be used in syntax as if it is an observed variable
# Parameters can be fixed to constant values by using the * command; starting values can be specified by using start()*; labels can be implemented with []
Sit =~ Sit1r + Sit2 + Sit3r + Sit4 + Sit5r + Sit6
# Item intercepts --> ~ 1 indicates means or intercepts
# You can put multiple lines of syntax on a single line using a ;
Sit1r ~ 1; Sit2 ~ 1; Sit3r ~ 1; Sit4 ~ 1; Sit5r ~ 1; Sit6 ~ 1;
# Item error (unique) variances and covariances --> use the ~~ command
Sit1r ~~ Sit1r; Sit2 ~~ Sit2; Sit3r ~~ Sit3r; Sit4 ~~ Sit4; Sit5r ~~ Sit5r; Sit6 ~~ Sit6;
# Factor variance
Sit ~~ 100*Sit
# Factor mean (intercept)
Sit ~ 0
"
```
To run lavaan, the syntax string variable is passed to the ```lavaan(model = model01SyntaxLong, ...)``` function. In the function call, we also supply:
* ```data = hfsSituations```: The data frame which contains the variables in the syntax.
* ```estimator = "MLR"```: Enables the use of robust maximum likelihood estimation, which helps for data that are not entirely normal.
* ```mimic = "mplus"```: Ensures compatibility with Mplus output, which is often needed in practice (and is certainly needed for our homework system).
* ```std.lv = TRUE```: Uses the Z-score method of identification, setting all latent variable means to zero, all latent variable variances to one, and estimating all factor loadings.
```{r lavaanRun1, include=TRUE}
model01Estimates = lavaan(model = model01SyntaxLong, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = FALSE)
```
If the model estimation was successful, no errors would be displayed (and no output would be shown). All model information and results are contained within the ```model01Estimates``` object. To access a summary of the results use the ```summary()``` function with the following arguments:
* ```model01Estimates```: The analysis to be summarized.
* ```fit.measures=TRUE```: Provides model fit indices in summary.
* ```rsqaure=TRUE```: Provides the proportion of variance "explained" for each variable ($R^2$).
* ```standardized = TRUE```: Provides standardized estimates in the summary.
```{r lavsummary1, include=TRUE}
summary(model01Estimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
Each section contains different portions of model information.
#### Unstandardized Model Parameter Estmates
##### FACTOR LOADINGS (regression slopes of item response on factor)
```
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
Sit =~
Sit1r 1.234 0.069 17.906 0.000 1.234 0.707
Sit2 0.702 0.074 9.441 0.000 0.702 0.509
Sit3r 1.241 0.063 19.847 0.000 1.241 0.778
Sit4 0.784 0.069 11.333 0.000 0.784 0.559
Sit5r 1.023 0.053 19.179 0.000 1.023 0.596
Sit6 0.819 0.069 11.942 0.000 0.819 0.535
```
##### Intercepts (of Items) – HERE, ARE ACTUAL ITEM MEANS BECAUSE FACTOR MEAN IS ZERO
Note: the last term in the list, ```Sit``` is the "intercept" (mean) of the factor. As it does not have a standard error, this indicates it was fixed to zero and not estimated.
```
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.Sit1r 4.547 0.053 86.474 0.000 4.547 2.604
.Sit2 5.289 0.042 127.346 0.000 5.289 3.834
.Sit3r 4.896 0.048 101.959 0.000 4.896 3.070
.Sit4 5.359 0.042 126.896 0.000 5.359 3.821
.Sit5r 4.860 0.052 94.060 0.000 4.860 2.832
.Sit6 5.321 0.046 115.492 0.000 5.321 3.477
Sit 0.000 0.000 0.000
```
##### Residual (Unique) Variances (variance of error terms)
Note: the last term in the list, ```Sit```, is the variance of the factor. As it does not have a standard error, this indicates it was fixed to one (from the ```std.lv = TRUE``` option we used in the ```lavaan()``` function call) and not estimated.
```
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.Sit1r 1.526 0.149 10.217 0.000 1.526 0.500
.Sit2 1.409 0.128 11.014 0.000 1.409 0.741
.Sit3r 1.004 0.135 7.456 0.000 1.004 0.395
.Sit4 1.352 0.127 10.672 0.000 1.352 0.687
.Sit5r 1.899 0.118 16.025 0.000 1.899 0.645
.Sit6 1.671 0.159 10.517 0.000 1.671 0.714
Sit 1.000 1.000 1.000
```
#### Making use of the unstandardized model estimates:
_Writing out the model—individual predicted values:_
* $Y_1 = \mu_1 + \lambda_1F + e_1 = 4.547 + 1.234F + e_1$
_Writing out the model—predicted item variances and covariances:_
* $Var\left( Y_1 \right) = \left( \lambda^2_1 \right) Var\left(F\right) + Var\left(e_1\right) = (1.234^2)*(1) + 1.526 = 3.049$ (= original item variance)
* $Cov\left( Y_1, Y_2 \right) = \lambda_1 Var\left(F\right) \lambda_2 = (1.234)*(1)*(.702) = .866$ (actual covariance = .577, so the model over-predicted how related items 1 and 2 should be)
#### Plotting Path Diagrams
The R package semPlot helps provide a path diagram of a model. Here is an example:
```{r pathdiagram, include=TRUE}
semPaths(object = model01Estimates, what = "std")
```
#### Standardized Model Parameter Estimates
The last two columns of the summary output, ```Std.lv``` and ```Std.all```, contain the standardized model parameter estimates. To understand the difference between standardized and unstandardized parameter estimates, let's start with the standardized estimates. Standardized regression coefficients (and factor loadings) have a scale that is "units of Y" per "unit of X". That is, the slope/loading, represents the increase in the dependent variable $X$ per unit of the independent variable $X$ (in our case, the factor). The units of $Y$ are given by the standard deviation of $Y$, or $SD(Y)$. Similarly, the units of $X$ are given by the standard deviation of $X$, or $SD(X)$. You can think of the units associated by the fraction $\frac{SD(Y)}{SD(X)}$. So, the first factor loading (a value of 1.234 for the item Sit1r) indicates the numeric response to the item goes up by 1.234 for every one-unit increase in the factor Sit.
The process of standardization removes the units attached to the parameter. So, if the unstandardized factor loadings are expressed in units of $\frac{SD(Y)}{SD(X)}$, the standardized units are achieved by either dividing or multiplying by the appropriate standard deviation to make the numerator or denominator of $\frac{SD(Y)}{SD(X)}$ equal to one. For the standardized estimates under ```std.lv```, the units of the factor $(SD(X))$ are removed (yielding $\frac{SD(Y)}{1}$) by multiplying the estimate by the factor standard deviation. Because the factor standard deviation is set to one, all estimates in this column are the same as the unstandardized estimate. These unstandardized estimates can be used to see how parameters would look under the Z-score identification method another identification method was used.
The standardized estimates listed under ```std.all``` are formed by multiplying the estimate by the standard deviation of the factor and dividing that by the unconditional (raw) standard deviation of the item. For instance, the "fully" standardized factor loading of the first item is found by multiplying the unstandardized coefficient (1.234) by one (the factor standard deviation) and dividing by the item's standard deviation ($\sqrt{3.049}$ -- the square root of the item variance shown at the beginning of this example). The resulting value, $1.234\times\frac{1}{\sqrt{3.049}} = 0.707$, represents the factor loading would the analysis have been run (a) with a Z-score factor identification and (b) on an item that was a Z-score.
The process of standardization is the same for all parameters of the model: intercepts, loadings, and residual (unique) variances. The interpretation of standardized item intercepts is difficult and often these are not reported. The standardized versions of factor loadings and unique variances are commonly reported.
Moreover, in for items measuring one factor, the standardized loadings lead directly to the $R^2$ estimate -- the amount of variance in the item responses explained by the factor. The item $R^2$ is found by the square of the unstandardized factor loading. The R-Square information is found at the end of the model summary, so long as the option ```rsquare = TRUE``` is specified in the ```summary()``` function call.
```
R-Square:
Estimate
Sit1r 0.500
Sit2 0.259
Sit3r 0.605
Sit4 0.313
Sit5r 0.355
Sit6 0.286
```
### Shortening Lavaan Syntax: Lavaan Default Options
The syntax above is designed to show the mapping of all CFA parameters to all lavaan syntax elements. In reality, all you would need to write to define this model is:
```{r lavaanShort, include=TRUE}
model01SyntaxShort = "
Sit =~ Sit1r + Sit2 + Sit3r + Sit4 + Sit5r + Sit6
"
```
The syntax input into the ```sem()``` function uses some defaults:
* All item intercepts are estimated (each item gets its own) and the factor mean is fixed at zero.
* All item error (unique) variances are estimated (each item gets its own).
* All factor variances and covariances are estimated (to do so, the first item after the =~ has its factor loading set to 1 -- a marker item identification method)
Similarly, to run this syntax the ```sem``` function is now called. To see the results, the ```summary``` function is used. The ```sem``` function simplifies the syntax needed to conduct a confirmatory factor analysis. These are demonstrated below. Note the output is identical to what was run previously.
```{r lavaanshort, include=TRUE}
model01EstimatesShort = sem(model = model01SyntaxShort, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = TRUE)
summary(model01EstimatesShort, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
### Alternative Identification Methods
There are multiple equivalent ways of getting the same CFA model, but with different scaling for the factor mean and variance (i.e., different means of identification). Now let’s see the model parameters when using the marker item for model identification instead. In the marker item identification method:
* The first factor loading of a factor (the first variable after the ```=~``` symbol in ```lavaan``` syntax) is set to one
* The factor variance is estimated
* The factor mean is set to zero
* All item intercepts and unique variances are estimated (as done in the Z-score identification method)
#### Factor Mean Zero; Factor Variance Estimated (marker item factor loading)
The ```lavaan``` syntax is the same for the marker item identification, but the call to the ```lavaan()``` function does not include the ```std.lv = TRUE``` option, which defaults to the marker item method of identification:
```{r marker, include=TRUE}
model02Estimates = sem(model = model01SyntaxShort, data = hfsSituations, estimator = "MLR", mimic = "mplus")
summary(model02Estimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
#### Unstandardized Model Results
##### FACTOR LOADINGS (regression slopes of item response on factor)
Here, loading for SIT1R is not tested and has no standard error (```Std.Err```) because it is fixed to one. Also, note the ```Std.lv``` estimates are identical to the unstandardized estimates in the Z-score factor identification method. Further, the ```Std.all``` estimates are equal to the ```Std.all``` estimates in the Z-score factor identification method. These will be equal for all identification methods.
```
Latent Variables:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
Sit =~
Sit1r 1.000 1.317 0.735
Sit2 0.641 0.060 10.741 0.000 0.844 0.596
Sit3r 0.977 0.036 27.335 0.000 1.287 0.796
Sit4 0.625 0.059 10.586 0.000 0.824 0.586
Sit5r 0.737 0.041 17.832 0.000 0.970 0.562
Sit6 0.547 0.058 9.445 0.000 0.720 0.477
```
##### Intercepts (of Items) – EXPECTED Y WHEN FACTOR = 0, or for mean of factor in sample
Here, all are identical to what was found in the previous Z-score standardization. That is because we left the factor mean to be zero.
```
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.Sit1r 4.443 0.054 82.373 0.000 4.443 2.480
.Sit2 5.287 0.043 123.919 0.000 5.287 3.731
.Sit3r 4.778 0.049 98.116 0.000 4.778 2.954
.Sit4 5.314 0.042 125.550 0.000 5.314 3.780
.Sit5r 4.761 0.052 91.624 0.000 4.761 2.759
.Sit6 5.263 0.045 115.739 0.000 5.263 3.485
Sit 0.000 0.000 0.000
```
##### Residual (unique) variances and factor variance
Here, the factor variance is estimated, which is different from the previous identification method.
```
Variances:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.Sit1r 1.475 0.108 13.649 0.000 1.475 0.460
.Sit2 1.294 0.082 15.747 0.000 1.294 0.645
.Sit3r 0.959 0.093 10.279 0.000 0.959 0.367
.Sit4 1.298 0.081 16.072 0.000 1.298 0.657
.Sit5r 2.037 0.108 18.787 0.000 2.037 0.684
.Sit6 1.762 0.088 20.034 0.000 1.762 0.772
Sit 1.734 0.158 10.988 0.000 1.000 1.000
```
#### Estimating Factor Means: Marker Item Loading (=1) and Marker Item Intercept (=0)
To estimate this model, we have to return to the general ```lavaan``` model function. In the syntax below you see ```1*Sit1r```, setting the factor loading for ```Sit1r``` to one (the marker item factor loading). Further, you see ```Sit1r ~ 0``` setting the item intercept of ```Sit1r``` to zero, the marker item intercept. Finally, to estimate the factor mean, we use ```Sit ~ 1```, which estimates the factor mean explicitly.
```{r lavaan3, include=TRUE}
model03Syntax = "
# Model 1 -- Fully Z-Scored Factor Identification Approach
# Item factor loadings --> list the factor to the left of the =~ and the items to the right, separated by a plus
# Once the factor is defined it can be used in syntax as if it is an observed variable
# Parameters can be fixed to constant values by using the * command; starting values can be specified by using start()*; labels can be implemented with []
Sit =~ 1*Sit1r + Sit2 + Sit3r + Sit4 + Sit5r + Sit6
# Item intercepts --> ~ 1 indicates means or intercepts
# You can put multiple lines of syntax on a single line using a ;
Sit1r ~ 0; Sit2 ~ 1; Sit3r ~ 1; Sit4 ~ 1; Sit5r ~ 1; Sit6 ~ 1;
# Item error (unique) variances and covariances --> use the ~~ command
Sit1r ~~ Sit1r; Sit2 ~~ Sit2; Sit3r ~~ Sit3r; Sit4 ~~ Sit4; Sit5r ~~ Sit5r; Sit6 ~~ Sit6;
# Factor variance
Sit ~~ Sit
# Factor mean (intercept)
Sit ~ 1
"
model03Estimates = sem(model = model03Syntax, data = hfsSituations, estimator = "MLR", mimic = "mplus")
summary(model03Estimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
Here, you will note the model is identical to the previous two -- the log-likelihood is 11535.690, same as previously. Now, the intercepts has the mean of item ```Sit1r``` set to zero and the mean of the factor estimated.
```
Intercepts:
Estimate Std.Err z-value P(>|z|) Std.lv Std.all
.Sit1r 0.000 0.000 0.000
.Sit2 2.438 0.268 9.112 0.000 2.438 1.720
.Sit3r 0.436 0.162 2.682 0.007 0.436 0.269
.Sit4 2.536 0.265 9.558 0.000 2.536 1.804
.Sit5r 1.488 0.192 7.768 0.000 1.488 0.862
.Sit6 2.833 0.261 10.862 0.000 2.833 1.876
Sit 4.443 0.054 82.373 0.000 3.374 3.374
```
The mean of the factor is 4.443, which, in this case, is the mean of item ```Sit1r```. That is because the factor loading of the item is set to 1.0. You will also notice that the other item intercepts have changed from previous models. In general, an item's mean is found by adding the item intercept to the product of the factor loading times the factor mean, or $\mu_i + \lambda_i\mu_F$.
### Model Fit Information for a Single-Factor Model (same regardless of factor scaling method):
Calculating model degrees of freedom (v is number of observed variables in a model):
* Total df = $\frac{v(v+1)}{2} + v = 27$
* Number of parameters in our model: 18
* Degrees of freedom = 27-18 = 9
#### Loglikelihood – use for testing differences in model fit across nested models
```
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -11535.690 -11535.690
Scaling correction factor 1.076
for the MLR correction
Loglikelihood unrestricted model (H1) -11342.023 -11342.023
Scaling correction factor 0.994
for the MLR correction
```
* Loglikelihood user model (H0): this is for your specified model
* Scaling correction factor for the MLR correction: indicates how far off from normal=1
* H1 Value: this is for a saturated (perfect) model
#### Information Criteria “smaller is better” – use for nested or non-nested model comparisons
```
Number of free parameters 18 18
Akaike (AIC) 23107.380 23107.380
Bayesian (BIC) 23197.484 23197.484
Sample-size adjusted Bayesian (BIC) 23140.311 23140.311
```
* is # of estimated parameters (“free” to be not 0)
* AIC = (-2*$LL_{H0}$) + (2*estimated parameters)
* BIC = (-2*$LL_{H0}$) + (LN N*estimated parameters)
* Sample-size adjusted Bayesian (BIC) = BIC replacing N with (N + 2) / 24
#### Chi-Square Test of Model Fit (Significance is bad here) for your specified model
```
Estimator ML Robust
Minimum Function Test Statistic 387.333 467.447
Degrees of freedom 9 9
P-value (Chi-square) 0.000 0.000
Scaling correction factor 0.829
for the Yuan-Bentler correction (Mplus variant)
```
* Estimator: Look at robust column for MLR version of test
* Minimum Function Test Statistic: leftover after estimating our one-factor model
* Scaling correction factor for the Yuan-Bentler correction (Mplus variant): indicates how far off from normal=1
Where does this $\chi^2$ value for "model fit" come from? A rescaled −2LL model comparison of this one-factor model (H0) against the saturated model (H1) that perfectly reproduces the data covariances.
#### Where the Saturated (H1) Model Comes From: All Means, Variances, and Covariances Estimated
How to fit the saturated (Unstructured) Baseline Model: Item means, variances, and covariances in original data:
```{r, modelSat, include=TRUE}
modelSaturated = "
# Item intercepts --> ~ 1 indicates means or intercepts
# You can put multiple lines of syntax on a single line using a ;
Sit1r ~ 1; Sit2 ~ 1; Sit3r ~ 1; Sit4 ~ 1; Sit5r ~ 1; Sit6 ~ 1;
# Item variances and covariances --> use the ~~ command
# Variances:
Sit1r ~~ Sit1r; Sit2 ~~ Sit2; Sit3r ~~ Sit3r; Sit4 ~~ Sit4; Sit5r ~~ Sit5r; Sit6 ~~ Sit6;
# Covariances:
Sit1r ~~ Sit2; Sit1r ~~ Sit3r; Sit1r ~~ Sit4; Sit1r ~~ Sit5r; Sit1r ~~ Sit6;
Sit2 ~~ Sit3r; Sit2 ~~ Sit4; Sit2 ~~ Sit5r; Sit2 ~~ Sit6;
Sit3r ~~ Sit4; Sit3r ~~ Sit5r; Sit3r ~~ Sit6;
Sit4 ~~ Sit5r; Sit4 ~~ Sit6;
Sit5r ~~ Sit6;
"
modelSaturatedEstimates = sem(model = modelSaturated, data = hfsSituations, estimator = "MLR", mimic = "mplus")
summary(modelSaturatedEstimates, fit.measures = TRUE)
```
Note that H0 and H1 are now the same! Our H0 model IS the H1 saturated model: the log-likelihood of H0 and H1 are the same. Also, note there are 27 free parameters (six item means, six item variances, and 15 covariances).
```
Loglikelihood and Information Criteria:
Loglikelihood user model (H0) -11342.023 -11342.023
Loglikelihood unrestricted model (H1) -11342.023 -11342.023
Number of free parameters 27 27
Akaike (AIC) 22738.046 22738.046
Bayesian (BIC) 22873.202 22873.202
Sample-size adjusted Bayesian (BIC) 22787.444 22787.444
```
Also note how the model $\chi^2$ test has zero degrees of freedom: this is because all 27 possible free parameters were estimated. This model fits the data perfectly.
```
Estimator ML Robust
Minimum Function Test Statistic 0.000 0.000
Degrees of freedom 0 0
Minimum Function Value 0.0000000000000
Scaling correction factor NA
for the Yuan-Bentler correction (Mplus variant)
```
#### The Rest of the One-Factor Model Fit Statistics
```
User model versus baseline model:
Comparative Fit Index (CFI) 0.817 0.779
Tucker-Lewis Index (TLI) 0.694 0.632
Robust Comparative Fit Index (CFI) 0.816
Robust Tucker-Lewis Index (TLI) 0.693
Root Mean Square Error of Approximation:
RMSEA 0.195 0.215
90 Percent Confidence Interval 0.179 0.212 0.197 0.233
P-value RMSEA <= 0.05 0.000 0.000
Robust RMSEA 0.196
90 Percent Confidence Interval 0.181 0.211
Standardized Root Mean Square Residual:
SRMR 0.079 0.079
```
* CFI/TLI: Want close to one (1 = saturated model)
* RMSEA: Want close to zero (0 = saturated model)
* SRMR (Standardized Root Mean Square Residual): want close to zero (0 = saturated model)
#### Chi-Square Test of Model Fit for the Baseline Model (for the "no covariances" model)
This compares the estimated model to the one that has no covariances. It is a last-resort type model in that if the estimated model has a test with a non-significant p-value, then this indicates there will be no factors to be found in the data.
```
Model test baseline model:
Minimum Function Test Statistic 2076.990 2090.854
Degrees of freedom 15 15
P-value 0.000 0.000
```
Where does this $\chi^2$ value for "fit of the baseline model" come from? A rescaled −2LL model comparison of the independence model with NO covariances to the saturated model.
What’s the point? This baseline model fit test tells us whether there are any covariances at all (i.e., whether it even makes sense to try to fit latent factors to predict them).
#### How to fit the Independence (Null) Baseline Model: Item means and variances, but NO covariances
```{r, modelInd, include=TRUE}
modelIndependence = "
# Item intercepts --> ~ 1 indicates means or intercepts
# You can put multiple lines of syntax on a single line using a ;
Sit1r ~ 1; Sit2 ~ 1; Sit3r ~ 1; Sit4 ~ 1; Sit5r ~ 1; Sit6 ~ 1;
# Item variances and covariances --> use the ~~ command
# Variances:
Sit1r ~~ Sit1r; Sit2 ~~ Sit2; Sit3r ~~ Sit3r; Sit4 ~~ Sit4; Sit5r ~~ Sit5r; Sit6 ~~ Sit6;
"
modelIndependenceEstimates = sem(model = modelIndependence, data = hfsSituations, estimator = "MLR", mimic = "mplus")
summary(modelIndependenceEstimates, fit.measures = TRUE)
```
Note how the test of the model vs. saturated is identical to the test of the model vs. baseline: that indicates this model is the baseline model.
Although not 0, this is the worst possible RMSEA while still allowing separate means and variances per item in these data. RMSEA is a parsimony-corrected absolute fit index (so, its fit is relative to the saturated model).
CFI and TLI are 0 because they are "incremental fit" indices relative to the independence model (which this is).
SRMR is also an absolute fit index (relative to saturated model), so this is the worst it gets for these data, too.
### Poor Model Fit: Need for Model Modifications
For this section, any of the three equivalent single factor models can be used.
#### Modification Indices
So global fit for the one-factor model is not so good (RMSEA = .173, CFI = .732). What do the voodoo modification indices suggest we do to fix it? To get modification indices, use the ```modificationindices()``` function. Here, the function is called with options:
* ```object = model01Estimates```: The model estimates object from which to derive modification indices.
* ```sort. = TRUE```: Sort the output from highest to lowest modification index.
```{r modindices, include=TRUE}
modificationindices(object = model01Estimates, sort. = TRUE)
```
The output includes:
* ```lhs```: Left hand side for parameter (in ```lavaan``` syntax)
* ```op```: Operation of parameter: ```~~``` is for (residual) covariances; ```=~``` is for additional factor loadings. All other ```lavaan``` syntax types are possible, too, but here item means and variances fit perfectly (see below)
* ```rhs```: Right hand side for parameter (in ```lavaan``` syntax)
* ```mi```: Modification index using ML
* ```mi.scaled```: Modification index using MLR (use this one)
* ```epc```: Expected parameter change (from zero)
* ```sepc.lv```: Standardized expected parameter change using ```std.lv``` standardization
* ```sepc.all```: Standardized expected parameter change using ```std.all``` standardization
* ```sepc.nox```: Standardized expected parameter change using ```std.nox``` standardization
Highest values are for error covariances (for unknown multidimensionality).
#### Another approach: Residual Covariance Matrices
Another approach—how about we examine local fit and see where the problems seem to be?
The means and variances of the items will be perfectly reproduced, so that’s not an issue. Misfit results from the difference between the observed and model-predicted covariances.
```lavaan``` gives us the "residual" (defined as observed – predicted) or "leftover" covariance matrix, but it is scale dependent and thus not so helpful. We can use the ```resid()``` function to obtain the residual covariance matrix (observed covariances minus model-implied covariances):
```{r resid, include=TRUE}
resid(object = model01Estimates, type = "raw")
```
```lavaan``` also gives us "normalized" residuals, which can be thought of as z-scores for how large the residual leftover covariance is in absolute terms. Because the denominator decreases with sample size, however, these values may be inflated in large samples, so look for relatively large values.
"Normalized" Residuals for Inter-Item Covariances = (observed – predicted) / SD(observed):
```{r residN, include=TRUE}
resid(object = model01Estimates, type = "normalized")
```
NEGATIVE NORMALIZED RESIDUAL: Less related than you predicted (don’t want to be together)
POSITIVE NORMALIZED RESIDUAL: More related than you predicted (want to be more together)
Why might the normalized residuals (leftover correlations) for the positive-worded items be larger than for the negatively-worded items?
These results suggest that wording valence is playing a larger role in the pattern of covariance across items than what the one-factor model predicts. Rather than adding voodoo covariances among the residuals for specific items, how about a two-factor model based on wording instead?
### Model 4. Fully Z-Scored, 2-Factor Model
Here, we use the shortened syntax and the ```sem()``` function to get results.
```{r model04, include=TRUE}
model04Syntax = "
# SitP loadings (all estimated)
SitP =~ Sit2 + Sit4 + Sit6
# SitN loadings (all estimated)
SitN =~ Sit1r + Sit3r + Sit5r
"
model04Estimates = sem(model = model04Syntax, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = TRUE)
summary(model04Estimates, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
This model fits better (we would call this good fit). We can also compare the fit of this model with Model 1 using the ```anova()``` function. Here, the null hypothesis is that Model 1 fits as well as Model 4.
```{r modelComp, include=TRUE}
anova(model01Estimates, model04Estimates)
```
This function conducts the MLR version of the likelihood ratio test for us. The significant difference indicates that Model 4 fits better than Model 1.
Let’s see: Any more local fit problems? The modification indices are better (values of a little over 10 seem okay).
```{r postFit, include=TRUE}
modificationindices(object = model04Estimates, sort. = TRUE)
```
The normalized residuals have two values that are bigger in absolute value than 2:
```{r postFit2, include=TRUE}
resid(object = model04Estimates, type = "normalized")
```
Because we have no real theoretical or defensible reason to fit any of these suggested parameters, we will not add any new parameters. This will be about as good as it gets.
Here is the path diagram of the model using the standardized estimates:
```{r path4, include=TRUE}
semPaths(object = model04Estimates, what = "std")
```
### Calculating Reliabilities
As we have demonstrated good model fit, estimates of trait reliabilities can now be found. Although I do not dispense such advice, many people use a CFA to indicate model fit then proceed to use sum scores for each trait in a model. I do not like this because sum scores are perfectly correlated with the factor scores from the parallel items model -- but we never tested that model (should it not fit we may get a reversal in the rank ordering of people by score).
#### Reliabilities for Sum Scores (Omega)
That said, reliabilities for sum scores can be found by using CFA model parameters. This reliability coefficient is called "Omega" by Rod McDonald and is calculated:
$$ \rho_\omega = \frac{\sigma^2_F\left( \sum_{i=1}^{Items} \lambda_i \right)^2}{\sigma^2_F\left( \sum_{i=1}^{Items} \lambda_i \right)^2 \sum_{i=1}^{Items} \sum_{j=1}^{Items} \psi_{ij}}$$
In words, Omega = Var(Factor)* (Sum of loadings)^2 / [ Var(Factor)* (Sum of loadings)^2 + Sum of error variances + 2* Sum of error covariances]
#### Calculating Omega from ```lavaan```
Through the use of parameter labels and new parameters, you can use ```lavaan``` to calculate Omega. In this syntax, the terms before the items are labels representing the factor loadings and unique variances. They can be used later in the syntax to form new parameters or to put constraints on the model.
```{r model04Omega, include=TRUE}
model04SyntaxOmega = "
# SitP loadings (all estimated)
SitP =~ L2*Sit2 + L4*Sit4 + L6*Sit6
# SitN loadings (all estimated)
SitN =~ L1*Sit1r + L3*Sit3r + L5*Sit5r
# Unique Variances:
Sit1r ~~ E1*Sit1r; Sit2 ~~ E2*Sit2; Sit3r ~~ E3*Sit3r; Sit4 ~~ E4*Sit4; Sit5r ~~ E5*Sit5r; Sit6 ~~ E6*Sit6;
# Calculate Omega Reliability for Sum Scores:
OmegaP := ((L2 + L4 + L6)^2) / ( ((L2 + L4 + L6)^2) + E2 + E4 + E6)
OmegaN := ((L1 + L3 + L5)^2) / ( ((L1 + L3 + L5)^2) + E1 + E3 + E5)
"
model04EstimatesOmega = sem(model = model04SyntaxOmega, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = TRUE)
summary(model04EstimatesOmega, fit.measures = FALSE, rsquare = FALSE, standardized = FALSE, header = FALSE)
```
Calculating Omega through ```lavaan`` also provides its standard error. Note: the Omega equation used above is for the Z-score factor identification method. If the marker-item method is used for factor loadings, then multiply the sum of the loadings by the variance of the factor, as shown in the equation above.
Of note about Omega: If we constrain all factor loadings of a trait to be equal (called Tau-Equivalent), Omega is equal to Alpha. In the syntax below, putting the labels LP and LN in multiple places causes the factor loadings for those places to be constrained to be equal:
```{r model04Alpha, include=TRUE}
model04SyntaxAlpha = "
# SitP loadings (all estimated)
SitP =~ LP*Sit2 + LP*Sit4 + LP*Sit6
# SitN loadings (all estimated)
SitN =~ LN*Sit1r + LN*Sit3r + LN*Sit5r
# Unique Variances:
Sit1r ~~ E1*Sit1r; Sit2 ~~ E2*Sit2; Sit3r ~~ E3*Sit3r; Sit4 ~~ E4*Sit4; Sit5r ~~ E5*Sit5r; Sit6 ~~ E6*Sit6;
# Calculate Omega Reliability for Sum Scores:
OmegaP := ((3*LP)^2) / ( ((3*LP)^2) + E2 + E4 + E6)
OmegaN := ((3*LN)^2) / ( ((3*LN)^2) + E1 + E3 + E5)
"
model04EstimatesAlpha = sem(model = model04SyntaxAlpha, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = TRUE)
summary(model04EstimatesAlpha, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
Compared with what the ```psych``` package gives:
```{r alpha, include=TRUE}
alpha(x = hfsSituations[c("Sit2", "Sit4", "Sit6")], use = "all.obs")
alpha(x = hfsSituations[c("Sit1r", "Sit3r", "Sit5r")], use = "all.obs")
```
#### Reliabilities for Factor Scores
Factor scores have a long history with many critiques and complaints. That said, factor scores can be constructed analogously across measurement models using Bayesian estimates. We will describe this more in a later lecture. For our purposes, in CFA, the two main types of Bayesian Estimates (MAP: Maximum A Posteriori and EAP: Expected A Posteriori) are identical. ```lavaan``` will not provide standard errors for factor scores, so I created a function ```factorScores()``` to not only create the factor scores using EAP (again, identical to MAP) but also to give standard errors for each score. The function takes the ```lavaan``` model output and returns a list of three elements: ```scores``` containing factor scores and standard errors, ```factorCov``` containing the theoretical covariance matrix of the factor scores, and ```factorCor``` the theoretical correlation matrix of the factor scores.
To determine the reliability of a factor score, we must return to our classical notion of what reliability means:
$$ \rho = \frac{Var(True)}{Var(Total)} = \frac{Var(True)}{Var(True) + Var(Error)} = \frac{Var(F)}{Var(F)+SE(F)^2}$$
In CFA, $Var(True)$ is found by the estimated factor variance and $Var(Error)$ comes from the squared standard error of a factor score (from an observation with complete data).
I created a function named ```factorScoreReliability()``` to calculate the reliability for factor scores. Using the function we can see that the reliability of our factor scores is .817 for SitP and .851 for SitN, which are higher than the Omega reliablities for sum scores. In general, factor score reliabilities are greater than what is found in Omega and Alpha due to the use of a prior distribution for the factor itself and due to the factor correlation allowing indirect information from other factors to help in the estimation of each factor.
```{r scores, include=TRUE}
factorScores = function(lavObject){
output = inspect(object = lavObject, what = "est")
sigma = output$lambda %*% output$psi %*% t(output$lambda) + output$theta
modelData = lavObject@Data@X[[1]]
scores = t(output$alpha%*%matrix(1, nrow=1, ncol=dim(modelData)[1]) +output$psi %*% t(output$lambda) %*% solve(sigma)%*%(t(modelData) - output$nu%*%matrix(1, nrow=1, ncol=dim(modelData)[1])))
varscores = output$psi - output$psi %*% t(output$lambda) %*% solve(sigma) %*% output$lambda %*% output$psi
factorSE = sqrt(diag(varscores))
names(factorSE) = paste0(names(factorSE), ".SE")
factorSEmat = matrix(1, nrow=nrow(scores), ncol = 1) %*% matrix(factorSE, nrow = 1, ncol = ncol(scores))
colnames(factorSEmat) = names(factorSE)
result = data.frame(cbind(scores, factorSEmat))
names(result)
odds = seq(1, ncol(result)-1, 2)
evens = seq(2, ncol(result), 2)
result = result[c(odds,evens)]
factorCov = varscores
if (dim(varscores)[1] == 1 & dim(varscores)[2] == 1){
factorCorr = solve(sqrt(varscores)) %*% varscores %*% solve(sqrt(varscores))
} else {
factorCorr = solve(sqrt(diag(diag(varscores)))) %*% varscores %*% solve(sqrt(diag(diag(varscores))))
}
return(list(scores = result, factorCov = factorCov, factorCorr = factorCorr))
}
factorScoreReliability = function(lavObject){
output = inspect(object = lavObject, what = "est")
sigma = output$lambda %*% output$psi %*% t(output$lambda) + output$theta
varscores = output$psi - output$psi %*% t(output$lambda) %*% solve(sigma) %*% output$lambda %*% output$psi
return(diag(output$psi)/(diag(output$psi) + diag(varscores)))
}
factorScoreReliability(lavObject = model04Estimates)
```
### Testing Assumptions of Classical Test Theory
We can also compare the model fit of the CFA model with the tau-equivalent model, essentially testing whether or not CTT (and alpha) is appropriate:
```{r modelComp2, include=TRUE}
anova(model04EstimatesAlpha, model04EstimatesOmega)
```
The significant difference indicates that the tau-equivalent assumptions of equal item loadings do not hold for all of the data. In the Mplus handout, Lesa Hoffman shows that tau equivalence holds for one of the subscales, but we don't need to have tau equivalence to move forward with results as CFA is subsumes the tau-equivalent model (meaning it will be tau equivalent if the data are tau equivalent but can also be more general).
Another model often discussed in CTT is the parallel items model. The CFA version of the parallel items model is a model where all factor loadings for a factor are constrained to be equal and all unique variances for a factor are constrained to be equal. This model is one step more restrictive than the tau equivalent items model. Syntax for this model is as follows:
```{r parallelItems, include=TRUE}
model04SyntaxSB = "
# SitP loadings (all estimated)
SitP =~ LP*Sit2 + LP*Sit4 + LP*Sit6
# SitN loadings (all estimated)
SitN =~ LN*Sit1r + LN*Sit3r + LN*Sit5r
# Unique Variances:
Sit1r ~~ EN*Sit1r; Sit2 ~~ EP*Sit2; Sit3r ~~ EN*Sit3r; Sit4 ~~ EP*Sit4; Sit5r ~~ EN*Sit5r; Sit6 ~~ EP*Sit6;
# Calculate Omega Reliability for Sum Scores:
OmegaP := ((3*LP)^2) / ( ((3*LP)^2) + 3*EP)
OmegaN := ((3*LN)^2) / ( ((3*LN)^2) + 3*EN)
"
model04EstimatesSB = sem(model = model04SyntaxSB, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = TRUE)
summary(model04EstimatesSB, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
```
The values resulting from Omega are the Spearman-Brown reliability estimates. Note that reliability for parallel items < reliability for tau equivalent items < reliability for CFA, but that the estimates are very close. That is common when a model fits the data.
### Examining Factor Score Distributions
The positive factor scores have an estimated mean of 0 with a variance of 0.79 instead of 1.00 (due to the effect of the prior distribution -- this is called "shrinkage"). The SE for each person’s factor score is .472. Treating factor scores as observed variables is like saying SE = 0.
95% confidence interval for positive factor score = Score ± 2*.472 = Score ± .944.
```{r plotF1, include=TRUE}
# calculate factor scores using function above:
fscores = factorScores(lavObject = model04Estimates)
#show variance of factor score:
var(fscores$scores$SitP)
# Histogram overlaid with kernel density curve
ggplot(fscores$scores, aes(x=SitP)) +
geom_histogram(aes(y=..density..), # Histogram with density instead of count on y-axis
binwidth=.5,
colour="black", fill="white") + xlim(c(-4,4)) + labs(title = "Positive Situation Forgiveness Factor Score") +
geom_density(alpha=.2, fill="#FF6666") # Overlay with transparent density plot
```
The negative factor scores have an estimated mean of 0 with a variance of 0.839 instead of 1.00. The SE for each person’s factor score is .418, so the 80% confidence interval is Score ± .836.
The negative factor scores retain more variance (and have a smaller SE) because there is more information in them, due to higher factor loadings (greater reliability) of their items.
```{r plotF2, include=TRUE}
#show variance of factor score:
var(fscores$scores$SitN)
# Histogram overlaid with kernel density curve
ggplot(fscores$scores, aes(x=SitN)) +
geom_histogram(aes(y=..density..), # Histogram with density instead of count on y-axis
binwidth=.5,
colour="black", fill="white") + xlim(c(-4,4)) + labs(title = "Negative Situation Forgiveness Factor Score") +
geom_density(alpha=.2, fill="#FF6666") # Overlay with transparent density plot
```
#### Factor Scores from Parallel Items Model are Sum Scores with a Different Scale
The parallel items model constrains the item factor loadings to be equal and unique variances to be equal for a given factor. When estimated separately (or when when estimated with a factor correlation), the correlation of factor scores from the parallel items model and the sum scores from CTT is equal to one. What this means is that to be able to use sum scores in an analysis, the parallel items model must hold. To demonstrate, the ```lavaan``` syntax below sets the factor covariance to zero (and therefore the correlation between factors to zero) by using 0\* in the statement ```SitP ~~ 0*SitN```:
```{r factorSum, include=TRUE}
model04SyntaxSBzeroCor = "
# SitP loadings (all estimated)
SitP =~ LP*Sit2 + LP*Sit4 + LP*Sit6
# SitN loadings (all estimated)
SitN =~ LN*Sit1r + LN*Sit3r + LN*Sit5r
# Unique Variances:
Sit1r ~~ EN*Sit1r; Sit2 ~~ EP*Sit2; Sit3r ~~ EN*Sit3r; Sit4 ~~ EP*Sit4; Sit5r ~~ EN*Sit5r; Sit6 ~~ EP*Sit6;
SitP ~~ 0*SitN
# Calculate Omega Reliability for Sum Scores:
OmegaP := ((3*LP)^2) / ( ((3*LP)^2) + 3*EP)
OmegaN := ((3*LN)^2) / ( ((3*LN)^2) + 3*EN)
"
model04SyntaxSBzeroCorEstimates = sem(model = model04SyntaxSBzeroCor, data = hfsSituations, estimator = "MLR", mimic = "mplus", std.lv = TRUE)
sumscoresP = apply(X = hfsSituations[c("Sit2", "Sit4", "Sit6")], MARGIN = 1, FUN = sum)
sumscoresN = apply(X = hfsSituations[c("Sit1r", "Sit3r", "Sit5r")], MARGIN = 1, FUN = sum)
fscoresPI = factorScores(lavObject = model04SyntaxSBzeroCorEstimates)
par(mfrow = c(1,2))