# Lavaan SEM Ordinal and Categorical variables

In my model I have dichotomous variables (gender, car ownership) and ordinal variables (Income, Employment,...). My question is whether it is possible to construct latent variables using dichotomous and ordered variables? Is that a problem for the analysis? If not, how should I treat them?

I am attaching the part of the model I am trying to make for which I get the warning message: lavaan WARNING: fit measures not available if model did not converge

model <- '

socio =~ x1 + x2 + x3
eco  =~ x4 + x5 + x7

eco ~ social
'
fit <- sem(model, data=dataset2, ordered=c("x2", "x3", "x1", "x4", "x5", "x7"))


Variables x1 - x3 are dichotomous

Variables x4 - x7 are ordinal on a scale 1-5

Yes, there are special ways to handle ordinal and binary variables in Lavaan, you can enter them as numeric variables then when you use the sem() function you specify which are ordinal using the ordered argument.

I wrote up a longer response but then came across this link...

That should give you everything you need to know.

• Its a good idea to post long answers even if a link covers it - this protects against link rot or 3rd party websites updating content. stats.stackexchange.com/help/how-to-answer Oct 19, 2018 at 8:26
• Based on the link in Dimitris' answer, I have a difficult time to understand what lavaan actually does when an endogenous variables is declared to be "ordered". For example, if there is only one endogenous variable in the model, will lavaan then estimate an ordered probit with latent factors? Similarly, it is not really clear to me how discrete measurements are treated - e.g. OpenMx is very clear that discrete measurements are assumed to be interval censored draws from a latent normal distribution. It would be great if someone who's knowledgeable could clarify what's actually going on! Jul 28, 2021 at 15:40

As both @Dimitris Rizopoulos and @Jeremy Miles say, it is possible to fit an SEM using categorical data (i.e., which includes your dichotomous and ordinal variables). There are generally two methods used to go about doing this$$^1$$. The first is the direct method, which treats categorical data as continuous and, as a result, estimates model parameters using the sample correlation/covariance matrix. The second method goes by many names, but here I will refer to the underlying latent response method since it invokes the presence of an underlying latent response/variable through the use of tetrachoric/polychoric correlations to estimate model parameters. Below is some code for fitting your model using each method

## Lavaan Model
# Note model is the same across both methods.
model <- '
socio =~ x1 + x2 + x3
eco  =~ x4 + x5 + x7

eco ~ social
'
## Fitting models
# Fit using the direct method
fit1 <- sem(model, data=dataset2)
# Fit using the underlying latent response method
fit2 <- sem(model, data=dataset2, ordered = colnames(dataset2))


So, to answer your first question, yes, SEM models may be fit using dichotomous and/or ordinary data, and there are multiple ways to do so (for more information, see Wirth & Edwards 2007).

Regarding whether the categorical nature of your data is related to your convergence issues, I agree with @Jeremy Miles that we need more information to answer this question. One possible reason for this I can think of from reading your question is that it could be related to your data. Variables such as employment and gender in particular, are seldom used as indicator variables in latent variable models. While such variables likely display meaningful bivariate associations (e.g., I am sure all variables load onto the socio have meaningful bivariate associations), I am not sure whether a measurement model is a correct way to account for dependencies between variables that load onto the same latent construct. Put differently, it may be a better idea to use something like path analysis to test the relationships among x1-x6, instead of using a SEM$$^2$$.

$$^1$$Note that within each method, there are still important decisions to make, such as the choice of estimation method. For more information on this, see Wirth & Edwards 2007.

$$^2$$ Note that path analysis is simply SEM without the measurement model, and therefore can be estimated using most (if not all) SEM software packages such as lavaan and mplus.

References

Wirth, R. J., & Edwards, M. C. (2007). Item factor analysis: current approaches and future directions. Psychological methods, 12(1), 58.

Ordinal and binary variables are fine in SEM.

The fact that the model does not converge is (mostly) unrelated. We need more information to diagnose that.

• Jeremy, thank you for trying to help me solve the problem. The sample size is 620, so I believe the problem is not in the sample size. Is there a specific way ordinal and binary variables should be treated prior to conducting SEM? Any help is really appreciated! Jul 24, 2018 at 11:25