if (FALSE) {
# Load data set "HolzingerSwineford1939" in the lavaan package
data("HolzingerSwineford1939", package = "lavaan")
#-------------------------------------------------------------------------------
# Between-Group Measurement Invariance Evaluation
#..................
# Measurement model with one factor
# Example 1a: Specification of the grouping variable in 'x'
item.invar(HolzingerSwineford1939[, c("x1", "x2", "x3", "x4", "sex")], group = "sex")
# Example 1b: Specification of the grouping variable in 'group'
item.invar(HolzingerSwineford1939[, c("x1", "x2", "x3", "x4")],
group = HolzingerSwineford1939$sex)
# Example 1c: Alternative specification using the 'data' argument
item.invar(x1:x4, data = HolzingerSwineford1939, group = "sex")
# Example 1d: Alternative specification using the argument 'model'
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"), group = "sex")
# Example 1e: Alternative specification using the 'data' and 'model' argument
item.invar(., data = HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"), group = "sex")
#..................
# Measurement model with two factors
item.invar(HolzingerSwineford1939,
model = list(c("x1", "x2", "x3", "x4"),
c("x5", "x6", "x7", "x8")), group = "sex")
#..................
# Configural, metric, scalar, and strict measurement invariance
# Example 2: Evaluate configural, metric, scalar, and strict measurement invariance
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", invar = "strict")
#..................
# Partial measurement invariance
# Example 3: Free second factor loading (L2) and third intercept (T3)
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", partial = c("L2", "T3"), print = c("fit", "est"))
#..................
# Residual covariances
# Example 4a: One residual covariance
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
rescov = c("x3", "x4"), group = "sex")
# Example 4b: Two residual covariances
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
rescov = list(c("x1", "x2"), c("x3", "x4")), group = "sex")
#..................
# Scaled test statistic and cluster-robust standard errors
# Example 5a: Specify cluster variable using a variable name in 'x'
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", cluster = "agemo")
# Example 5b: Specify vector of the cluster variable in the argument 'cluster'
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", cluster = HolzingerSwineford1939$agemo)
#..................
# Default Null model
# Example 6: Specify default null model for computing incremental fit indices
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", null.model = FALSE)
#..................
# Print argument
# Example 7a: Request all results
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", print = "all")
# Example 7b: Request fit indices with ad hoc non-normality correction
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", print.fit = "scaled")
# Example 7c: Request modification indices with value equal or higher than 10
# and highlight residual correlations equal or higher than 0.3
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", print = c("modind", "resid"),
mod.minval = 10, resid.minval = 0.3)
#..................
# Model syntax and lavaan summary of the estimated model
# Example 8
mod <- item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", output = FALSE)
# lavaan model syntax scalar invariance model
cat(mod$model$scalar)
# lavaan summary of the scalar invariance model
lavaan::summary(mod$model.fit$scalar, standardized = TRUE, fit.measures = TRUE)
#-------------------------------------------------------------------------------
# Longitudinal Measurement Invariance Evaluation
# Example 9: Two time points with three indicators at each time point
item.invar(HolzingerSwineford1939,
model = list(c("x1", "x2", "x3"),
c("x5", "x6", "x7")), long = TRUE)
#------------------------------------------------
# Write Results
# Example 10a: Write results into a text file
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", print = "all", write = "Invariance.txt", output = FALSE)
# Example 10b: Write results into an Excel file
item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", print = "all", write = "Invariance.xlsx", output = FALSE)
result <- item.invar(HolzingerSwineford1939, model = c("x1", "x2", "x3", "x4"),
group = "sex", print = "all", output = FALSE)
write.result(result, "Invariance.xlsx")
}
Run the code above in your browser using DataLab