This is an example of exploratory LCA with ordinal indicators using
tidySEM, as explained in Van Lissa, C. J.,
Garnier-Villarreal, M., & Anadria, D. (2023). Recommended
Practices in Latent Class Analysis using the Open-Source R-Package
tidySEM. Structural Equation Modeling.
The present example uses synthetic data based on a study by Maene, D’hondt, Van Lissa, Thijs, & Stevens (2022). In a convenience sample of Flemish (Belgian) high-school students with a migration background, this study set out to identify distinct classes based on ordinal indicators of National, Regional, and Heritage identity. Sample size was not justified.
In the original study, the approach to class enumeration was semi-theory driven: The researchers expected to find profiles that were distinct on all three types of identity (national, regional, and heritage) - but the exact number of classes was not pre-specified (hypothesis 1).
Hypothesis 2 stated that adolescents who are nationally integrated would have lower depressive feelings than students from students with other combinations of identifications (hypothesis 2). Hypothesis 3 was that, for assimilated and separated adolescents, there would not be a significant effect of perceived teacher discrimination on depressive symptoms.
Use the command ?tidySEM::maene_identity to view the
data documentation.
To load the data, simply attach the tidySEM package. For
convenience, we assign the indicator data to an object called
df. As the analyses take a long time to run, this tutorial
reduces the data to three identity indicators and collapses their
ordered response categories into three levels. This is a teaching
simplification, do not do this for substantive analyses: collapsing
categories discards information and changes the estimated latent
classes.
# Load required packages
library(tidySEM)
library(ggplot2)
# Load data Keep one indicator for each identity domain and
# collapse adjacent categories. This deliberately smaller
# example makes ordinal mixture estimation faster.
ordinal3 <- function(x) {
z <- as.integer(x)
observed <- sort(unique(z[!is.na(z)]))
if (length(observed) < 3L)
stop("Indicator has fewer than three observed categories")
# Collapse ordered response categories into three
# approximately equal ranges.
groups <- cut(seq_along(observed), breaks = 3L, labels = FALSE)
ordered(groups[match(z, observed)], levels = 1:3)
}
df <- maene_identity[c("Ethnic_1", "Belgian", "Flemish")]
df[] <- lapply(df, ordinal3)
# Auxiliary variables must correspond to the same rows as
# the indicators.
aux_data <- maene_identityWe use tidySEM::descriptives() to describe the data
numerically. Because all items are categorical, we remove columns for
continuous data to de-clutter the table:
desc <- tidySEM::descriptives(df)
desc <- desc[, c("name", "type", "n", "missing", "unique", "mode",
"mode_value", "v")]
descAdditionally, we can plot the data. The ggplot2 function
geom_bar() is useful for ordinal data:
df_plot <- df
names(df_plot) <- paste0("Value.", names(df_plot))
df_plot <- reshape(df_plot, varying = names(df_plot), direction = "long")
ggplot(df_plot, aes(x = Value)) + geom_bar() + facet_wrap(~time,
scales = "free") + theme_bw()As we can see, the descriptives() table provides
invaluable information about the measurement level of the indicators,
which is used to specify the model correctly. If these data had not been
coded as ordinal factors, these descriptive statistics would have
revealed that each variable has only a few distinct values. The
proportion of missing values is reported in the "missing"
column. If any variables had missing values, we would report an MCAR
test with mice::mcar() and explain that missing data are
accounted for using FIML. In our example, we inspect missingness before
proceeding with our analysis.
Before we fit a series of LCA models, we set a random seed using
set.seed(). This is important because there is some
inherent randomness in the estimation procedure, and using a seed
ensures that we (and others) can exactly reproduce the results.
Next, we fit the LCA models. As all variables are ordinal, we can use
the convenience function tidySEM::mx_lca(), which is a
wrapper for the generic function mx_mixture() optimized for
LCA with ordinal data. Any mixture model can be specified through
mx_mixture(). At the time of writing, there are two other
wrapper functions for special cases: mx_profiles(), for
latent profile analysis, and mx_growth_mixture(), for
latent growth analysis and growth mixture models. All of these functions
have arguments data and number of classes. All
variables in data are included in the analysis, so relevant
variables must be selected first.
We consider one- through three-class models. Limiting the number of classes and categories makes this tutorial faster to reproduce. A substantive analysis should investigate a broader range of plausible models and use the original measurement scale where feasible.
In class enumeration, we want to compare a sequence of LCA models
fitted to the data. Convergence must be checked for each fitted model.
If a model with ordinal indicators does not converge, it is possible to
aid convergence using mxTryHardOrdinal(), which expands the
search for optimal parameter values for models with ordinal indicators.
It is part of the family of functions based on
mxTryHard().
Next, we create a model fit table using table_fit() and
retain relevant columns. We also determine whether any models can be
disqualified.
fit <- table_fit(res)
fit[, c("Name", "LL", "n", "Parameters", "BIC", "Entropy", "prob_min",
"n_min", "np_ratio", "np_local")]Inspect the ratio of cases to parameters (np_ratio and
np_local) alongside classification diagnostics such as
entropy and minimum classification probability. Models with small
classes or unstable estimates require particular caution.
Compare the BIC values in the model-fit table. Lower BIC values indicate a preferred balance of fit and complexity. The fitted model ranking may differ from that obtained with the full, uncollapsed dataset.
Assess class sizes, entropy, and classification probabilities for the
fitted three-class solution. The results below are based on the
simplified dataset and should not be compared numerically with the
original full-data example. We can produce a table of results using
table_results(res_final). However, the results are
thresholds, indicating quantiles of a standardized normal distribution.
These may be difficult to interpret. Therefore, we ask for the results
in probability scale:
tab <- table_prob(res_final)
reshape(tab, direction = "wide", v.names = "Probability", timevar = "group",
idvar = c("Variable", "Category"))The results can also be interpreted by plotting the response probabilities:
Use the response-probability plot to compare the identity patterns across classes. Class labels should be chosen based on the newly estimated probabilities rather than carried over from the original analysis.
To address the remaining two hypotheses, we will perform auxiliary analyses. Hypothesis 2 stated that adolescents who are nationally integrated would have lower depressive feelings than students from students with other combinations of identifications (hypothesis 2).
To test this hypothesis, we can call the BCH function and supply the
auxiliary variable depression to the data argument,
omitting the model argument. Below, we estimate an
auxiliary model to compare depressive symptoms across classes:
To obtain an omnibus likelihood ratio test of the significance of
depression differences across classes, as well as pairwise comparisons
between classes, use lr_test(aux_dep). Interpret the
omnibus and pairwise tests using the results from the simplified
example; numerical conclusions from the original analysis do not
necessarily carry over.
Hypothesis 3 was that, for assimilated and separated adolescents, there would not be a significant effect of perceived teacher discrimination on depressive symptoms. To test this hypothesis, we will compare the regression coefficient of discrimination on depressive symptoms across classes.
df_aux <- aux_data[, c("vict_teacher", "depression")]
# Dummy-code vict_teacher
df_aux$vict_teacher <- (as.integer(df_aux$vict_teacher) - 1)
aux_model <- BCH(res_final, model = "depression ~ vict_teacher",
data = df_aux)To view the coefficients of this model, we can use either
coef(aux_model) or
table_results(aux_model, columns = NULL). The regression
coefficients are represented by paths in the class-specific
A matrices.
table_results(aux_model, columns = c("label", "est_sig", "se",
"pval", "confint", "group", "matrix"))There are two ways to test whether the regression coefficients differ across classes.
First, we can use a likelihood-ratio test to compare the regression
coefficients in the class-specific A matrices:
Alternatively, we can use a Wald test to evaluate the equality constraints directly:
Both tests evaluate the null hypothesis that the regression coefficient of perceived teacher discrimination on depressive symptoms is equal across the three latent classes. Interpret the results based on the newly fitted auxiliary model; the original test statistics do not apply to this reduced example.