# NOT RUN {
# }
# NOT RUN {
## impose missing data for example
HSMiss <- HolzingerSwineford1939[ , c(paste("x", 1:9, sep = ""),
"ageyr","agemo","school")]
set.seed(12345)
HSMiss$x5 <- ifelse(HSMiss$x5 <= quantile(HSMiss$x5, .3), NA, HSMiss$x5)
age <- HSMiss$ageyr + HSMiss$agemo/12
HSMiss$x9 <- ifelse(age <= quantile(age, .3), NA, HSMiss$x9)
## impute missing data
library(Amelia)
set.seed(12345)
HS.amelia <- amelia(HSMiss, m = 20, noms = "school", p2s = FALSE)
imps <- HS.amelia$imputations
## specify CFA model from lavaan's ?cfa help page
HS.model <- '
visual =~ x1 + b1*x2 + x3
textual =~ x4 + b2*x5 + x6
speed =~ x7 + b3*x8 + x9
'
fit1 <- cfa.mi(HS.model, data = imps, estimator = "mlm")
fit0 <- cfa.mi(HS.model, data = imps, estimator = "mlm", orthogonal = TRUE)
## By default, use D3.
## Must request a chi-squared statistic to be robustified.
lavTestLRT.mi(fit1, h1 = fit0, asymptotic = TRUE)
## Using D2, you can either robustify the pooled naive statistic ...
lavTestLRT.mi(fit1, h1 = fit0, asymptotic = TRUE, test = "D2")
## ... or pool the robust chi-squared statistic
lavTestLRT.mi(fit1, h1 = fit0, asymptotic = TRUE, test = "D2",
pool.robust = TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab