The lavaan package has full support for multiple groups. To request a multiple
group analysis, you need to add the name of the group variable in your dataset
to the argument `group`

in the fitting function. By default, the same model is
fitted in all groups. In the following example, we fit the H&S CFA model for
the two schools (Pasteur and Grant-White).

If you want to fix parameters, or provide starting values, you can use the same
pre-multiplication techniques, but the single argument is now replaced by a
*vector* of arguments, one for each group. If you use a single element instead
of a vector, that element will be applied for all groups (note: this is NOT
true for labels, since this would imply equality constraints). For example:

In the definition of the latent factor `visual`

, we have fixed the factor
loading of the indicator `x3`

to the value '0.6' in the first group, and to the
value '0.8' in the second group, while the factor loading of the indicator `x2`

is fixed to the value '0.5' in both groups. In the definition of the `textual`

factor, two different starting values are provided for the `x5`

indicator; one
for each group. In addition, we have labeled the factor loading of the `x6`

indicator as 'a', but this label is only given to the parameter of the first
group. If you want to provide labels to each of the two groups, you can write
something like `c(a1,a2)*x6`

. Be careful: if you write `c(a,a)*x6`

, both
parameters (in the first and second group) will get the same label, and hence
they will be treated as a single parameter. To verify the effects of these
modifiers, we refit the model:

Sometimes, we wish to fix the value of a parameter in all groups, except
for one particular group. In this group, we wish to freely estimate the
value of that parameter. The modifier for this parameter
is again a vector containing the fixed values for this parameter for each
group, but we can use `NA`

to force a parameter to be free in one (or more)
group(s). Suppose for
example we have four groups. We define a latent variable (say `f`

)
with three indicators. We wish to fix the factor loading of
indicator `item2`

to 1.0 in all but the second group. We can write
something like

If you want to constrain one or more parameters to be equal across groups, you
need to give them the same label. For example, to constrain the factor loading
of the indicator `x3`

to be equal across (two) groups, you can write:

Again, identical labels imply identical parameters, both within and across groups.

Although providing identical labels is a very flexible method to specify
equality constraints for a few parameters, there is a more convenient way to
impose equality constraints on a whole set of parameters (for example: all
factor loadings, or all intercepts). We call these type of constraints *group
equality constraints* and they can be specified by the argument `group.equal`

in the fitting function. For example, to constrain (all) the
factor loadings to be equal across groups, you can proceed as follows:

More 'group equality constraints' can be added. In addition to the factor
loadings, the following keywords are supported in the `group.equal`

argument:

`intercepts`

: the intercepts of the observed variables`means`

: the intercepts/means of the latent variables`residuals`

: the residual variances of the observed variables`residual.covariances`

: the residual covariances of the observed variables`lv.variances`

: the (residual) variances of the latent variables`lv.covariances`

: the (residual) covariances of the latent varibles`regressions`

: all regression coefficients in the model

If you omit the `group.equal`

argument, all parameters are freely estimated in
each group (but the model structure is the same).

But what if you want to constrain a whole group of parameters (say all factor
loadings and intercepts) across groups, except for one or two parameters that
need to stay free in all groups. For this scenario, you can use the argument
`group.partial`

, containing the names of those parameters that need to remain
free. For example:

If you are interested in testing the measurement invariance of a CFA model
across several groups, you can use the function `measurementInvariance()`

which
performs a number of multiple group analyses in a particular sequence, with
increasingly more restrictions on the parameters. (Note: from the 0.5 series
onwards, the `measurementInvariance()`

function has been moved to the
`semTools`

package.) Each model is compared to the baseline model and the
previous model using chi-square difference tests. In addition, the difference
in the fit measure is also shown. Although the current implementation of the
function is still a bit primitive, it does illustrate how the various
components of the lavaan package can be used as building blocks for
constructing higher level functions (such as the `measurementInvariance()`

function), something that is often very hard to accomplish with commercial
software.

By adding the `group.partial`

argument, you can test for partial measurement
invariance by allowing a few parameters to remain free.