Categorical variables in SEM: code predictors, model outcomes and handle ordinal items
A column coded 1, 2 and 3 might represent industries, ordered satisfaction categories or event counts. Treating these codes identically changes the model even when the software accepts every column as numeric.
A variable’s role and measurement meaning determine coding, link functions, thresholds and interpretation. Choosing CB-SEM or PLS-SEM does not make those decisions for you.
Data type and coding require explicit decisions
- Continuous
Numeric distances are meaningful
- Ordinal
Ordered categories; consider spacing
- Binary
Two groups with explicit reference coding
- Nominal
Unordered categories
Conceptual diagram. Declare measurement levels and coding before choosing an estimator.
Source: Lê Minh · Conceptual illustration, not software output.1. Identify the role before choosing a command
A nominal predictor explains differences between categories, a binary outcome asks about event probability, and an ordinal item measures a construct through ordered responses. These are different tasks rather than one data-type conversion problem (Kline, 2023).
| Role | Example | Main decision |
|---|---|---|
| Nominal predictor | Regions A, B and C | Reference category and dummy or contrast coding |
| Binary outcome | Purchase: 0/1 | Probability model and link |
| Ordinal outcome | Dissatisfied, neutral, satisfied | Ordinal model and link assumptions |
| Ordinal indicator | Five ordered responses to an item | Threshold specification and estimator |
| Grouping variable | Organizations or occasions | Measurement comparability before parameter comparisons |
Industry code 3 is not three times industry code 1. Entering the code as continuous imposes a linear trend along an arbitrary ordering. Relabeling industries can then alter results without changing group membership.
2. Code nominal predictors explicitly
With an intercept and K groups, K−1 dummy variables are a conventional option. The lavaan tutorial describes this treatment for exogenous covariates. Other contrasts can be appropriate if their coefficient meanings are explained (The lavaan project, n.d.).
| Group | D_B | D_C |
|---|---|---|
| A | 0 | 0 |
| B | 1 | 0 |
| C | 0 | 1 |
Y = α + b_BD_B + b_CD_C + γX + ε.
Here α is the expected outcome in A when X is zero. The coefficient b_B compares B with A at the same X; it does not compare B with C. That comparison requires the contrast b_B − b_C and its uncertainty, or an appropriate alternative coding.
Including all three dummy variables and an intercept creates linear dependence in the usual specification. Dummy coding also does not make an observational group difference causal.
3. Binary and ordinal outcomes
Logit and probit models connect predictors to binary event probability. In logit, exp(b) is a conditional odds ratio. A probit coefficient is on a latent-response scale and cannot be exponentiated into the same odds-ratio interpretation (Kline, 2023).
For a hypothetical logit coefficient of 0.70, exp(0.70) is approximately 2.01. Conditional odds for group B are about twice those for A. This is not a 101% increase in probability. Probability statements also require the baseline and a meaningful covariate configuration.
Ordinal models use thresholds between response categories. Report category ordering and assess the assumptions of the chosen link. Coding an ordinal predictor as 1, 2 and 3 likewise imposes a numerical trend that needs justification.
Software capabilities matter: the lavaan tutorial covers binary and ordinal endogenous variables, not every multinomial outcome. A CFA command is not a universal generalized-SEM solution (The lavaan project, n.d.).
4. Ordered items and threshold models
An ordinal indicator can be represented through thresholds on an underlying response. The observed category code is distinct from distance on that response. Li’s comparison of MLR and WLSMV shows why performance depends on data conditions rather than a universal category-count rule (Li, 2016).
Inspect category frequencies, constant items, sparse bivariate cells, missingness and coding direction. Do not collapse categories merely to obtain convergence if the change destroys their substantive meaning.
In lavaan, ordered indicators trigger WLSMV, using DWLS estimation with the implementation’s adjusted inference. Do not append missing="fiml" to this ordinal example: the official tutorial states that FIML is not supported for this case (The lavaan project, n.d.).
5. An explicit CFA command template
The input survey.csv must contain s1 through s4, coded only 1–5 or declared missing. The example assumes one reflective SAT factor. It is a template for the reader’s data, not fitted output or validation of a measure.
R/lavaan: CFA with four ordinal indicators
library(lavaan)
dat <- read.csv("survey.csv", na.strings = c("", "NA"), check.names = FALSE)
items <- c("s1", "s2", "s3", "s4")
stopifnot(all(items %in% names(dat)))
valid <- vapply(dat[items], function(x) all(is.na(x) | x %in% 1:5), logical(1))
stopifnot(all(valid))
model <- 'SAT =~ s1 + s2 + s3 + s4'
fit <- cfa(model, data = dat, ordered = items, estimator = "WLSMV")
summary(fit, fit.measures = TRUE, standardized = TRUE)The validation stops on out-of-range values instead of silently converting coding errors to missing. Preserve the original file and report the actual missing-data handling; these commands do not establish a missingness mechanism.
Inspect convergence, thresholds, loadings, standard errors and estimator-appropriate fit output. Counting parameters is not enough to rule out an inadmissible or weakly informed solution. Do not combine adjusted statistics with ordinary ML difference-test formulas without the required correction.
6. Categorical data do not select the SEM family
A nominal predictor may enter several SEM families. An algorithm accepting 0/1 data does not establish that it fits the intended probability model. Check the conceptual representation, equation type and actual estimator (Hair et al., 2022) (Kline, 2023).
For group comparisons, one significant p value and one nonsignificant value do not establish a difference. Examine measurement comparability and test the planned parameter contrast or restrictions. Splitting a continuous score into groups changes the question and requires justification.
7. Report coding, inference and limits
Reporting template
Variable [name] had [K] categories and served as [role]. The reference category/order was [ ]. The model used [coding or link/threshold], estimator [ ] and missing-data handling [ ]. Coefficients are interpreted on [scale], with confidence intervals [ ].
- Codes and labels match the questionnaire.
- Predictor, outcome, indicator and group roles are explicit.
- Reference categories, ordering and links are reported.
- Probit coefficients are not described as odds ratios.
- The estimator and missing-data method are supported by the actual version.
- Sparse cells, solution behavior and uncertainty have been examined.
Conclusion
Establish each variable’s role and scale before selecting software. Correct coding supports correct interpretation; changing SEM families cannot replace that work.
References
- Hair, J. F., Jr., Hult, G. T. M., Ringle, C. M., & Sarstedt, M. (2022). A primer on partial least squares structural equation modeling (PLS-SEM) (3rd ed.). SAGE https://us2.sagepub.com/en-us/nam/a-primer-on-partial-least-squares-structural-equation-modeling-pls-sem/book270548
- Kline, R. B. (2023). Principles and practice of structural equation modeling (5th ed.). The Guilford Press https://www.guilford.com/books/Principles-and-Practice-of-Structural-Equation-Modeling/Rex-Kline/9781462551910
- Li, C.-H. (2016). Confirmatory factor analysis with ordinal data: Comparing robust maximum likelihood and diagonally weighted least squares. Behavior Research Methods, 48, 936–949. https://doi.org/10.3758/s13428-015-0619-7
- The lavaan project (n.d.). Categorical data. https://lavaan.ugent.be/tutorial/cat.html
