# NOT RUN {
# Computing bifactor indices from fitted lavaan object
# (using mirt object is similar). Use of the unidimensional
# model is optional; it is only used to compute ARPB.
# }
# NOT RUN {
SRS_UnidimensionalModel <-
"SRS =~ SRS_1 + SRS_2 + SRS_3 + SRS_4 + SRS_5 +
SRS_6 + SRS_7 + SRS_8 + SRS_9 + SRS_10 +
SRS_11 + SRS_12 + SRS_13 + SRS_14 + SRS_15 +
SRS_16 + SRS_17 + SRS_18 + SRS_19 + SRS_20"
SRS_Unidimensional <- lavaan::cfa(SRS_UnidimensionalModel,
SRS_data,
ordered = paste0("SRS_", 1:20),
orthogonal = TRUE)
SRS_BifactorModel <-
"SRS =~ SRS_1 + SRS_2 + SRS_3 + SRS_4 + SRS_5 +
SRS_6 + SRS_7 + SRS_8 + SRS_9 + SRS_10 +
SRS_11 + SRS_12 + SRS_13 + SRS_14 + SRS_15 +
SRS_16 + SRS_17 + SRS_18 + SRS_19 + SRS_20
Function =~ SRS_5 + SRS_9 + SRS_12 + SRS_15 + SRS_18
Pain =~ SRS_1 + SRS_2 + SRS_8 + SRS_11 + SRS_17
SelfImage =~ SRS_4 + SRS_6 + SRS_10 + SRS_14 + SRS_19
MentalHealth =~ SRS_3 + SRS_7 + SRS_13 + SRS_16 + SRS_20"
SRS_bifactor <- lavaan::cfa(SRS_BifactorModel,
SRS_data,
ordered = paste0("SRS_", 1:20),
orthogonal = TRUE)
bifactorIndices(SRS_bifactor, UniLambda = SRS_Unidimensional)
# }
# NOT RUN {
# Computing bifactor indices from standardized factor loading matrices
Lambda <- matrix(c(.82, .10, 0, 0,
.77, .35, 0, 0,
.79, .32, 0, 0,
.66, .39, 0, 0,
.51, 0, .71, 0,
.56, 0, .43, 0,
.68, 0, .13, 0,
.60, 0, .50, 0,
.83, 0, 0, .47,
.60, 0, 0, .27,
.78, 0, 0, .28,
.55, 0, 0, .75),
ncol = 4, byrow = TRUE)
colnames(Lambda) <- c("General", "SF1", "SF2", "SF3")
bifactorIndices(Lambda)
# bifactorIndices can also be used on two-tier models
MTMM_model <- "
Trait1 =~ T1M1_1 + T1M1_2 + T1M1_3 +
T1M2_1 + T1M2_2 + T1M2_3 +
T1M3_1 + T1M3_2 + T1M3_3
Trait2 =~ T2M1_1 + T2M1_2 + T2M1_3 +
T2M2_1 + T2M2_2 + T2M2_3 +
T2M3_1 + T2M3_2 + T2M3_3
Trait3 =~ T3M1_1 + T3M1_2 + T3M1_3 +
T3M2_1 + T3M2_2 + T3M2_3 +
T3M3_1 + T3M3_2 + T3M3_3
Method1 =~ T1M1_1 + T1M1_2 + T1M1_3 +
T2M1_1 + T2M1_2 + T2M1_3 +
T3M1_1 + T3M1_2 + T3M1_3
Method2 =~ T1M2_1 + T1M2_2 + T1M2_3 +
T2M2_1 + T2M2_2 + T2M2_3 +
T3M2_1 + T3M2_2 + T3M2_3
Method3 =~ T1M3_1 + T1M3_2 + T1M3_3 +
T2M3_1 + T2M3_2 + T2M3_3 +
T3M3_1 + T3M3_2 + T3M3_3
Trait1 ~~ 0*Method1
Trait1 ~~ 0*Method2
Trait1 ~~ 0*Method3
Trait2 ~~ 0*Method1
Trait2 ~~ 0*Method2
Trait2 ~~ 0*Method3
Trait3 ~~ 0*Method1
Trait3 ~~ 0*Method2
Trait3 ~~ 0*Method3
Method1 ~~ 0*Method2
Method1 ~~ 0*Method3
Method2 ~~ 0*Method3"
MTMM_fit <- lavaan::cfa(MTMM_model, MTMM_data)
bifactorIndices(MTMM_fit)
# }
Run the code above in your browser using DataLab