# REMEMBER, YOU MUST NAMED ALL ARGUMENT EXCEPT THE CFA ITEMS ARGUMENT
# Fitting a multiple-factor measurement invariance model by passing items.
measurement_invariance(
  x1:x3,
  x4:x6,
  x7:x9,
  data = lavaan::HolzingerSwineford1939,
  group = "school",
  invariance_level = "scalar" # you can change this to metric
)
# Fitting measurement invariance model by passing explicit lavaan model
# I am also going to only test for metric invariance instead of the default scalar invariance
# \donttest{
measurement_invariance(
  model = "visual  =~ x1 + x2 + x3;
           textual =~ x4 + x5 + x6;
           speed   =~ x7 + x8 + x9",
  data = lavaan::HolzingerSwineford1939,
  group = "school",
  invariance_level = "metric"
)
# }
if (FALSE) {
# This will fail because I did not add `model = ` in front of the lavaan model.
# Therefore,you must add the tag in front of all arguments
# For example, `return_result = 'model'` instaed of `model`
measurement_invariance(
  "visual  =~ x1 + x2 + x3;
             textual =~ x4 + x5 + x6;
             speed   =~ x7 + x8 + x9",
  data = lavaan::HolzingerSwineford1939
)
}
Run the code above in your browser using DataLab