options(digits = 3) options(width = 100)
In this example, we will show how to use
lslx to conduct multi-group factor analysis.
The example uses data
HolzingerSwineford1939 in the package
lavaan must be installed.
In the following specification,
x9 is assumed to be measurements of 3 latent factors:
model_mgfa <- "visual :=> 1 * x1 + x2 + x3 textual :=> 1 * x4 + x5 + x6 speed :=> 1 * x7 + x8 + x9"
:=> means that the LHS latent factors is defined by the RHS observed variables.
In this model,
visual is mainly measured by
textual is mainly measured by
speed is mainly measured by
x7 are fixed at 1 for scale setting.
The above specification is valid for both groups.
Details of model syntax can be found in the section of Model Syntax via
lslx is written as an
Everytime we conduct analysis with
lslx object must be initialized.
The following code initializes an
lslx object named
library(lslx) lslx_mgfa <- lslx$new(model = model_mgfa, data = lavaan::HolzingerSwineford1939, group_variable = "school", reference_group = "Pasteur")
lslx is the object generator for
lslx object and
new is the build-in method of
lslx to generate a new
The initialization of
lslx requires users to specify a model for model specification (argument
model) and a data set to be fitted (argument
The data set must contain all the observed variables specified in the given model.
Because in this example a multi-group analysis is considered, variable for group labeling (argument
group_variable) must be specified.
In lslx, two types of parameterization can be used in multi-group analysis.
The first type is the same with the traditional multi-group SEM, which treats model parameters in each group separately.
The second type sets one group as reference and treats model parameters in other groups as increments with respect to the reference.
Under the second type of parameterization, the group heterogeneity can be efficiently explored if we treat the increments as penalized parameters.
In this example,
Pasteur is set as reference.
Hence, the parameters in
Grant-White now reflect differences from the reference.
lslx object is initialized, the heterogeneity of a multi-group model can be quickly respecified by
The following code sets
Grant-White as penalized parameters.
Note that parameters in
Grant-White now reflect differences since
Pasteur is set as reference.
lslx_mgfa$penalize_heterogeneity(block = c("y<-1", "y<-f"), group = "Grant-White")
Since the homogeneity of latent factor means may not be a reasonable assumption when examining measurement invariance, the following code relaxes this assumption
lslx_mgfa$free_block(block = "f<-1", group = "Grant-White")
To see more methods to modify a specified model, please check the section of Set-Related Method via
lslx object is initialized, method
$fit_mcp() can be used to fit the specified model into the given data with MCP.
All the fitting result will be stored in the
fitting field of
Unlike traditional SEM analysis,
lslx fits the model into data under all the penalty levels considered.
To summarize the fitting result, a selector to determine an optimal penalty level must be specified.
Available selectors can be found in the section of Penalty Level Selection via
The following code summarize the fitting result under the penalty level selected by Haughton’s Bayesian information criterion (HBIC).
lslx_mgfa$summarize(selector = "hbic")
In this example, we can see that all of the loadings are invariant across the two groups.
However, the intercepts of
x7 seem to be not invariant.
$summarize() method also shows the result of significance tests for the coefficients.
lslx, the default standard errors are calculated based on sandwich formula whenever raw data is available.
It is generally valid even when the model is misspecified and the data is not normal.
However, it may not be valid after selecting an optimal penalty level.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.