forked from cddesja/lavaan-reproducible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
little2006-scaling.R
271 lines (228 loc) · 6.02 KB
/
little2006-scaling.R
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
# ------------------------------------------------
# A Non-arbitrary method of identifying and scaling
# latent variables in SEM and MACS models.
#
# Little, Slegers, & Card
#
# Structural Equation Modeling 2006
# ------------------------------------------------
library("lavaan")
# Data ----
# data were available as mean vectors, standard deviation vectors
# and covariance matrices of the indicators by group
# 7th graders
n7 <- 380
means7 <- c(3.13552, 2.99061, 3.06945, 1.70069, 1.52705, 1.54483)
sd7 <- c(0.66770, 0.68506, 0.70672, 0.71418, 0.66320, 0.65276)
lower7 <- '
1.00000
0.75854 1.00000
0.76214 0.78705 1.00000
0.02766 0.00973 -.05762 1.00000
-.06112 -.06105 -.14060 0.78501 1.00000
-.02222 -.05180 -.10250 0.81616 0.81076 1.00000'
seventh.cor <- getCov(lower7, names = c("PosAFF1", "PosAFF2", "PosAFF3", "NegAFF1", "NegAFF2", "NegAFF3"))
seventh.cov <- (sd7 %*% t(sd7)) * seventh.cor
n8 <- 379
means8 <- c(3.07338, 2.84716, 2.97882, 1.71700, 1.57955, 1.55001)
sd8 <- c(0.70299, 0.71780, 0.76208, 0.65011, 0.60168, 0.61420)
lower8 <- '
1.00000
0.81366 1.00000
0.84980 0.83523 1.00000
-0.18804 -0.15524 -0.21520 1.00000
-0.28875 -0.24951 -0.33769 0.78418 1.00000
-0.29342 -0.21022 -0.30553 0.79952 0.83156 1.00000'
eighth.cor <- getCov(lower8, names = c("PosAFF1", "PosAFF2", "PosAFF3", "NegAFF1", "NegAFF2", "NegAFF3"))
eighth.cov <- (sd8 %*% t(sd8)) * eighth.cor
# Combine data into lists ----
cov.grades <- list(seventh.cov, eighth.cov)
mean.grades <- list(means7, means8)
n.grades <- list(n7, n8)
# Method 1: Fixed latent parameters
method1.mod <- '
group: 1
# Measurement Model
Pos =~ PosAFF1 + PosAFF2 + PosAFF3
Neg =~ NegAFF1 + NegAFF2 + NegAFF3
# Intercepts
PosAFF1 ~ 1
PosAFF2 ~ 1
PosAFF3 ~ 1
NegAFF1 ~ 1
NegAFF2 ~ 1
NegAFF3 ~ 1
# Latent Means
Pos ~ 0*1
Neg ~ 0*1
# Latent Covariances
Pos ~~ 1*Pos
Neg ~~ 1*Neg
Pos ~~ Neg
# Residual Variances
PosAFF1 ~~ PosAFF1
PosAFF2 ~~ PosAFF2
PosAFF3 ~~ PosAFF3
NegAFF1 ~~ NegAFF1
NegAFF2 ~~ NegAFF2
NegAFF3 ~~ NegAFF3
group: 2
# Measurement Model
Pos =~ PosAFF1 + PosAFF2 + PosAFF3
Neg =~ NegAFF1 + NegAFF2 + NegAFF3
# Intercepts
PosAFF1 ~ 1
PosAFF2 ~ 1
PosAFF3 ~ 1
NegAFF1 ~ 1
NegAFF2 ~ 1
NegAFF3 ~ 1
# Latent Means
Pos ~ 1
Neg ~ 1
# Latent Covariances
Pos ~~ Pos
Neg ~~ Neg
Pos ~~ Neg
# Residual Variances
PosAFF1 ~~ PosAFF1
PosAFF2 ~~ PosAFF2
PosAFF3 ~~ PosAFF3
NegAFF1 ~~ NegAFF1
NegAFF2 ~~ NegAFF2
NegAFF3 ~~ NegAFF3
'
method1.fit <- lavaan(method1.mod, sample.cov = cov.grades, sample.nobs = n.grades, sample.mean = mean.grades, group.equal = c("loadings", "intercepts"))
summary(method1.fit, standardized = TRUE)
# Method 2a: Fixed marker variable, lowest variance indicators ----
method2a.mod <- '
# Measurement Model
Pos =~ 1*PosAFF1 + PosAFF2 + PosAFF3
Neg =~ NegAFF1 + 1*NegAFF2 + NegAFF3
# Intercepts
PosAFF1 ~ 0*1
PosAFF2 ~ 1
PosAFF3 ~ 1
NegAFF1 ~ 1
NegAFF2 ~ 0*1
NegAFF3 ~ 1
# Latent Means
Pos ~ 1
Neg ~ 1
# Latent Covariances
Pos ~~ Pos
Neg ~~ Neg
Pos ~~ Neg
# Residual Variances
PosAFF1 ~~ PosAFF1
PosAFF2 ~~ PosAFF2
PosAFF3 ~~ PosAFF3
NegAFF1 ~~ NegAFF1
NegAFF2 ~~ NegAFF2
NegAFF3 ~~ NegAFF3
'
method2a.fit <- lavaan(method2a.mod, sample.cov = cov.grades, sample.nobs = n.grades, sample.mean = mean.grades, group.equal = c("loadings", "intercepts"))
summary(method2a.fit, standardized = TRUE)
# Method 2b: Fixed marker variable, middle variance indicators ----
method2b.mod <- '
# Measurement Model
Pos =~ PosAFF1 + 1*PosAFF2 + PosAFF3
Neg =~ NegAFF1 + NegAFF2 + 1*NegAFF3
# Intercepts
PosAFF1 ~ 1
PosAFF2 ~ 0*1
PosAFF3 ~ 1
NegAFF1 ~ 1
NegAFF2 ~ 1
NegAFF3 ~ 0*1
# Latent Means
Pos ~ 1
Neg ~ 1
# Latent Covariances
Pos ~~ Pos
Neg ~~ Neg
Pos ~~ Neg
# Residual Variances
PosAFF1 ~~ PosAFF1
PosAFF2 ~~ PosAFF2
PosAFF3 ~~ PosAFF3
NegAFF1 ~~ NegAFF1
NegAFF2 ~~ NegAFF2
NegAFF3 ~~ NegAFF3
'
method2b.fit <- lavaan(method2b.mod, sample.cov = cov.grades, sample.nobs = n.grades, sample.mean = mean.grades, group.equal = c("loadings", "intercepts"))
summary(method2b.fit, standardized = TRUE)
# Method 2c: Fixed marker variable, highest variance indicators ----
method2c.mod <- '
# Measurement Model
Pos =~ PosAFF1 + PosAFF2 + 1*PosAFF3
Neg =~ 1*NegAFF1 + NegAFF2 + NegAFF3
# Intercepts
PosAFF1 ~ 1
PosAFF2 ~ 1
PosAFF3 ~ 0*1
NegAFF1 ~ 0*1
NegAFF2 ~ 1
NegAFF3 ~ 1
# Latent Means
Pos ~ 1
Neg ~ 1
# Latent Covariances
Pos ~~ Pos
Neg ~~ Neg
Pos ~~ Neg
# Residual Variances
PosAFF1 ~~ PosAFF1
PosAFF2 ~~ PosAFF2
PosAFF3 ~~ PosAFF3
NegAFF1 ~~ NegAFF1
NegAFF2 ~~ NegAFF2
NegAFF3 ~~ NegAFF3
'
method2c.fit <- lavaan(method2c.mod, sample.cov = cov.grades, sample.nobs = n.grades, sample.mean = mean.grades, group.equal = c("loadings", "intercepts"))
summary(method2c.fit, standardized = TRUE)
# Method 3: Effects-coding constraints ----
# - restricts the factor loadings to sum to the number of loadings per factor
# - restricts the intercepts to sum to zero per factor
method3.mod <- '
# Measurement Model
Pos =~ lp1*PosAFF1 + lp2*PosAFF2 + lp3*PosAFF3
Neg =~ ln1*NegAFF1 + ln2*NegAFF2 + ln3*NegAFF3
# Intercepts
PosAFF1 ~ tp1*1
PosAFF2 ~ tp2*1
PosAFF3 ~ tp3*1
NegAFF1 ~ tn1*1
NegAFF2 ~ tn2*1
NegAFF3 ~ tn3*1
# Latent Means
Pos ~ 1
Neg ~ 1
# Latent Covariances
Pos ~~ Pos
Neg ~~ Neg
Pos ~~ Neg
# Residual Variances
PosAFF1 ~~ PosAFF1
PosAFF2 ~~ PosAFF2
PosAFF3 ~~ PosAFF3
NegAFF1 ~~ NegAFF1
NegAFF2 ~~ NegAFF2
NegAFF3 ~~ NegAFF3
# Define constrains for effects-coding
lp1 == 3 - lp2 - lp3
ln1 == 3 - ln2 - ln3
tp1 == 0 - tp2 - tp3
tn1 == 0 - tn2 - tn3
'
method3.fit <- lavaan(method3.mod, sample.cov = cov.grades, sample.nobs = n.grades, sample.mean = mean.grades, group.equal = c("loadings", "intercepts"))
summary(method3.fit, standardized = TRUE)
# Show that the models are equivalent ----
compare.fit <- rbind(
fitmeasures(method1.fit, fit.measures = c("TLI", "CFI", "RMSEA")),
fitmeasures(method2a.fit, fit.measures = c("TLI", "CFI", "RMSEA")),
fitmeasures(method2b.fit, fit.measures = c("TLI", "CFI", "RMSEA")),
fitmeasures(method2c.fit, fit.measures = c("TLI", "CFI", "RMSEA")),
fitmeasures(method3.fit, fit.measures = c("TLI", "CFI", "RMSEA")))
rownames(compare.fit) <- c("Method 1", paste0("Method 2", c("a", "b", "c")), "Method 3")
compare.fit