Source-linked AI summary

semopy: A Python package for Structural Equation Modeling

Meshcheryakov Georgy, Igolkina Anna

arXiv:1905.09376v2stat.AP

TL;DR

Because existing SEM software was often commercial or R-only and the available Python option was limited, this paper presents semopy, a Python SEM package with a generated-model testing framework for comparison with lavaan. In optimizer tests, SLSQP outperformed other methods, although it sometimes failed to estimate parameters that other methods estimated successfully.

  • Problem

    Existing SEM software was often commercial or non-open-source or lacked Python support, while the available Python package was limited to basic functionality and lacked documentation.

    Source: §1.1 · p. 2
  • Method

    semopy is a Python SEM package that supports observed variables in the structural part and ordinal variables, and the paper describes a framework that generates random models and data for package testing.

    Source: §1 · p. 2
  • Results

    SLSQP clearly outperformed other optimization methods, but sometimes failed to estimate parameters that other methods estimated successfully.

    Source: L-BFGS-B · p. 16
  • Takeaways & Limitations

    When SLSQP fails to estimate parameters, the authors recommend trying other optimization methods.

    Source: L-BFGS-B · p. 16

    The model assumes normally distributed variables with zero means and independent, normally distributed error terms with zero means.

    Source: §2 · p. 6, §2.1 · p. 6

Abstract

from arXiv · show

Structural equation modelling (SEM) is a multivariate statistical technique for estimating complex relationships between observed and latent variables. Although numerous SEM packages exist, each of them has limitations. Some packages are not free or open-source; the most popular package not having this disadvantage is $\textbf{lavaan}$, but it is written in R language, which is behind current mainstream tendencies that make it harder to be incorporated into developmental pipelines (i.e. bioinformatical ones). Thus we developed the Python package $\textbf{semopy}$ to satisfy those criteria. The paper provides detailed examples of package usage and explains it's inner clockworks. Moreover, we developed the unique generator of SEM models to extensively test SEM packages and demonstrated that $\textbf{semopy}$ significantly outperforms $\textbf{lavaan}$ in execution time and accuracy.

1 Introduction

semopy is presented as a Python package for SEM, with support for observed variables in structural relationships and ordinal variables. The introduction motivates the package, outlines its model syntax and quickstart workflow, and previews its implementation and comparisons with lavaan.

1 Introduction

  • semopy supports observed variables in the structural part of general SEM models and also supports ordinal variables.The paper also previews implementation details, usage examples, and comparisons with lavaan.Source: §1 · p. 2

1.1 Why do we need semopy?

  • The authors motivate semopy by the need for Python integration, limitations of existing options, and a stronger way to test SEM methods.They describe commercial tools as closed, popular open-source packages as R-based, and pypsy as limited in functionality and documentation.Source: §1.1 · p. 2

1.2 Model syntax

  • semopy uses lavaan-style syntax to specify regression, measurement, covariance, parameter-fixing, and variable-type relationships.Measurement syntax links one latent variable to its manifest indicators; the syntax also includes an operator for variable types.Source: §1.2 · pp. 3–4

1.3 Quickstart

  • The quickstart workflow specifies a model, loads data to calculate initial parameter values, then initializes an optimizer for estimation.The default objective is the likelihood function and the default optimizer is SLSQP.Source: §1.3 · pp. 4–5

2 Materials and methods

The methods define semopy’s general SEM formulation and its data, objective, optimization, and statistics workflow, then describe a random model-and-data generator for testing.

2.1 Model

  • semopy recasts structural and measurement relations as ω = Bω + ε and z = Λω + δ, with independent, normally distributed, zero-mean errors.The scale is set by fixing the first alphabetically ordered indicator loading to 1; the exogenous observed-variable error covariance defaults to the sample covariance.Source: §2.1 · p. 6, Parameters in Λ matrix · p. 7, Parameters in Ψ matrix · p. 7

2.2 Loading the data

  • semopy accepts continuous variables and ordinal variables, which produce a heterogeneous sample covariance matrix with polychoric and polyserial correlations.Variable types can be specified manually or recognized automatically; normality is the default assumption.Source: §2.2 · pp. 8–9

2.3 Objective functions

2.4 Optimisation methods

  • Available optimizers include SLSQP, L-BFGS-B, PORT routines, Adam, Nesterov, and stochastic gradient descent.PORT incorporates routines for cases with no analytical gradient, a gradient, or both gradient and Hessian.Source: §2.4 · p. 10

2.5 Statistics

  • semopy calculates parameter p-values with a normality-assuming Z-test and supports χ², RMSEA, CFI, TLI, NFI, GFI, and AGFI fit indices.Expected Fisher information is used by default, though users can choose observed information, defined as the likelihood Hessian at the estimate.Source: P-values for parameter estimates · p. 11, Fit indices · p. 11

2.6 Testing framework

  • The testing framework randomly generates SEM structure, parameters, and data; its construction includes structural and measurement components, parameter sampling, and variable values.The paper reports 15 model sets examined in the tests.Source: §2.6 · pp. 12–13

3 Results

The results section compares semopy and lavaan on generated SEM benchmark sets, then describes performance benchmarking and tests of optimization methods.

3 Results

  • 15 generated benchmark sets, each containing 1,000 random models, were used to compare semopy and lavaan.The sets used different generator parameters.Source: §3 · pp. 13–15
  • Optimization failures were counted when estimates diverged from true values, including cases with NaN parameters or an undefined or boundary-violating objective value.Source: §3 · pp. 14–15

3.1 Performance

  • The performance benchmark used a mixed set of models on an AMD A10-4600M computer, and Figure 4 presents performance on a logarithmic scale.Source: §3.1 · p. 16, Figure 4 · p. 16

3.2 Optimisation methods

  • All available optimization methods were tested, and Table 3 reports pairwise counts of models that failed to converge for one method but converged for another.Source: §3.2 · p. 16, Table 3 · p. 16

L-BFGS-B

SLSQP clearly outperforms the other optimization methods, but it does not correctly estimate parameters in every case.

L-BFGS-B

  • SLSQP clearly outperforms the other optimization methods.Source: L-BFGS-B · p. 16
  • In some cases, SLSQP fails to estimate parameters correctly while another method finds a solution.Source: L-BFGS-B · p. 16
  • The authors recommend trying another optimization method when SLSQP fails.Source: L-BFGS-B · p. 16
Loading 1905.09376v2…