Skip to main content
QUICK REVIEW

[Paper Review] semopy 2: A Structural Equation Modeling Package with Random Effects in Python

G. A. Meshcheryakov, Anna A. Igolkina|arXiv (Cornell University)|Jun 2, 2021
Statistical Methods and ApplicationsMathematics36 references9 citations
TL;DR

semopy 2 introduces a Python-based structural equation modeling (SEM) framework with native support for random effects, enabling estimation of complex multilevel models using multiple likelihood and least-squares methods. It extends traditional SEM by modeling matrix-variate normal distributions and incorporating random effects through flexible parameterization of mean and covariance structures, with support for ML, FIML, ULS, GLS, WLS, and DWLS estimation under various distributional assumptions.

ABSTRACT

Structural Equation Modeling (SEM) is an umbrella term that includes numerous multivariate statistical techniques that are employed throughout a plethora of research areas, ranging from social to natural sciences. Until recently, SEM software was either commercial or restricted to niche languages, and the lack of SEM packages compatible with more mainstream programming languages was dire. To combat that, we introduced a Python package semopy 1 that surpassed other state-of-the-art software in terms of performance and estimation accuracy. Yet, it was lacking in functionality and its usage was burdened with unnecessary boilerplate code. Here, we introduce a complete overhaul of semopy that improves upon the previous results and comes with lots of new capabilities. Furthermore, we propose a novel SEM model that combines in itself a notion of random effects from linear mixed models (LMMs) to model numerous phenomena, such as spatial data, time series or population stratification in genetics.

Motivation & Objective

  • To extend structural equation modeling in Python to support random effects and multilevel data structures.
  • To implement a flexible framework for parameterizing mean and covariance matrices in matrix-variate normal models.
  • To support multiple estimation methods—ML, FIML, ULS, GLS, WLS, DWLS—under both normal and non-normal assumptions.
  • To provide robust handling of missing data and degenerate covariance matrices via nearest positive-definite corrections.
  • To enable use of polychoric and polyserial correlations for ordinal variables through heterogeneous correlation matrices.

Proposed method

  • Parameterizes mean and covariance structures using matrix-variate normal distribution, with L and T representing row and column covariances.
  • Derives a negative log-likelihood function for matrix-variate normal models, incorporating trace terms to handle scale invariance.
  • Uses transformation via projection matrix P₁ to re-express data for REML estimation, enabling unbiased covariance estimation.
  • Applies multiple loss functions: Wishart ML, FIML, ULS, GLS, WLS, and DWLS, with WLS using fourth-moment-based weights by Browne (1984).
  • Employs vech operator to vectorize symmetric matrices and allows custom weight matrices W in WLS/DWLS.
  • Implements data correction by replacing degenerate or ill-conditioned covariance matrices with the nearest positive-definite matrix, issuing warnings when needed.

Experimental results

Research questions

  • RQ1How can random effects be effectively modeled within a structural equation modeling framework in Python?
  • RQ2What estimation methods are most appropriate for multilevel or multivariate data when normality assumptions are violated?
  • RQ3How can missing data be handled robustly in SEM without listwise deletion?
  • RQ4What is the impact of using polychoric and polyserial correlations on model estimation in the presence of ordinal variables?
  • RQ5How can matrix-variate normal distributions be used to model both row and column dependencies in multivariate data?

Key findings

  • The matrix-variate ML estimator is derived and implemented as the default method in semopy 2, with a likelihood function that accounts for scale invariance through trace terms.
  • Restricted maximum likelihood (REML) is supported by transforming data via P₁ and estimating residual covariances L_R and T_R under the transformed model.
  • FIML is shown to be equivalent to multivariate normal ML when data are complete, but handles missing data more naturally by excluding missing variables per observation.
  • WLS and DWLS are robust to non-normality, with DWLS being particularly useful when the weight matrix is ill-conditioned or large.
  • The framework issues warnings when sample covariance or correlation matrices are degenerate, replacing them with the nearest positive-definite matrix to ensure numerical stability.
  • The use of polychoric and polyserial correlations allows for valid modeling of ordinal variables by replacing the sample covariance matrix with a heterogeneous correlation matrix.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.