# NOT RUN {
## Specify the item-level model (if NO parcels were created)
## This must apply to BOTH competing models
item.syntax <- c(paste0("f1 =~ f1item", 1:9),
paste0("f2 =~ f2item", 1:9))
cat(item.syntax, sep = "\n")
## Below, we reduce the size of this same model by
## applying different parceling schemes
## Specify a 2-factor CFA with correlated factors, using 3-indicator parcels
mod1 <- '
f1 =~ par1 + par2 + par3
f2 =~ par4 + par5 + par6
'
## Specify a more restricted model with orthogonal factors
mod0 <- '
f1 =~ par1 + par2 + par3
f2 =~ par4 + par5 + par6
f1 ~~ 0*f2
'
## names of parcels (must apply to BOTH models)
(parcel.names <- paste0("par", 1:6))
# }
# NOT RUN {
## override default random-number generator to use parallel options
RNGkind("L'Ecuyer-CMRG")
PAVranking(model0 = mod0, model1 = mod1, data = simParcel, nAlloc = 100,
parcel.names = parcel.names, item.syntax = item.syntax,
std.lv = TRUE, # any addition lavaan arguments
parallel = "snow") # parallel options
## POOL RESULTS by treating parcel allocations as multiple imputations.
## Details provided in Sterba & Rights (2016); see ?poolMAlloc.
## save list of data sets instead of fitting model yet
dataList <- parcelAllocation(mod.parcels, data = simParcel, nAlloc = 100,
parcel.names = parcel.names,
item.syntax = item.syntax,
do.fit = FALSE)
## now fit each model to each data set
fit0 <- cfa.mi(mod0, data = dataList, std.lv = TRUE)
fit1 <- cfa.mi(mod1, data = dataList, std.lv = TRUE)
anova(fit0, fit1) # pooled test statistic comparing models
class?lavaan.mi # find more methods for pooling results
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab