I have created some simulated data. To keep things simple, lets say I have done the following:
y = (X_1 + X_2 + X_3)/3 + e
Where each X_i is drawn from a normal distribution and I have added correlation by specifying a correlation matrix and then performing a cholesky decomposition. I create a large number of samples and then calculate the corresponding values for y. e is an error term.
Now my goal is do inference but I don't want to answer questions like: What happens to y if I change X_1, holding the other variables constant. Instead, I want to know things like: If I change X_1 and take into account the correlation matrix, what is the effect on y.
I have never done any SEM so I am probably very off but here is what I tried in semopy (I think the notation should be similar to that of lavaan)
model_desc = """
# Regression model
Y ~ X_1 + X_2 + X_3
# Correlations
X_1 ~~ X_2
X_1 ~~ X_3
X_2 ~~ X_3
"""
I then pass in the dataframe containing the simulated values for y, X_1, X_2, X_3.
And while this model runs, I get some strange outputs.For the correlated variables I see the correlation coefficient from my correlation matrix. I.e.,
X1 ~~ X2 has an estimate that is very close to the correlation I have specified. However, the estimates for my target varible (e.g., y ~ X_1) are all zero.
My first question is: is using SEM even the right approach for what I want to achieve? Secondly, where is my implementation going wrong?