semopy


Factor scores

Models in semopy are equipped with predict_factors method that can be used for factor scores estimation. Let's see how the method works with Political Democracy dataset:

from semopy.examples import political_democracy
from semopy import Model

desc = political_democracy.get_model()
data = political_democracy.get_data()

model = Model(desc)
model.fit(data)
factors = model.predict_factors(data)
print(factors.head())

The output of the above example:

      dem60     dem65     ind60
0 -2.539528 -2.368729 -0.536216
1 -2.345362 -1.513466  0.151093
2  2.925690  2.998107  0.740218
3  2.883632  3.021921  1.244115
4  2.428383  2.422393  0.831255

predict_factors is very versatile and general and can be used with any semopy-compatible model.