Structural Equation modeling using semopy with constraints and constant

Question:

I would like to do structural equation modeling (SEM) with a latent variable (denoted "UNKOWNlatent" in the example below) in Python using the semopy package.
All parameters should be constraint be greater than zero.

Two questions:

  1. The model with constraints on the parameters seems not to converge (i.e., the example from below when removing the constant "a" from the model description). [It appears to keep on running and no output is produced. I’m not sure how to enable the fit function to print information during the fitting process.] How to change the setting so that it can successfully estimate the model outcomes?
  2. How can I add an overall constant? [If I won’t add a constant, there is a warning. If I try to add a constant, such as "a" in the example below, there is an error that there is no variable "a" in the data. If I add a column with ones to the data, there is an error that the estimated covariance matrix is infinite. ]

Below is an example script to reproduce the error(s). [It is using the univariate_regression_many data from semopy for the sake of a simple example with readily available data even though I don’t want to do conduct univariate regression.]

from semopy import Model
from semopy.examples import univariate_regression_many

desc ="""
UNKOWNlatent =~ a + b * x1 + c * x2 + d * x3
DEFINE(param) a  
DEFINE(param) b 
DEFINE(param) c
DEFINE(param) d
CONSTRAINT(a > 0)
CONSTRAINT(b > 0)
CONSTRAINT(c > 0)
CONSTRAINT(d > 0)
"""
data = univariate_regression_many.get_data()
print(desc)

mod = Model(desc)
res_opt = mod.fit(data)
estimates = mod.inspect()
print(estimates)
Asked By: gnm

||

Answers:

To 1. After adding start values (using, e.g., START(1.0) a b c ) for each parameter the algorithm converges.

To 2. Parameters for constants (i.e., intercepts) seem to be only allowed when using the class "ModelMeans".

Answered By: gnm