Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

11.2 Summary

Summed up, running an EFA with statsmodels follows the same fit-then-inspect workflow as the other models in this book. Please read through the documentation for a detailed overview.

from statsmodels.multivariate.factor import Factor

fa = Factor(endog=data,      # a DataFrame of observed variables
            n_factor=3,      # the number of factors to extract
            method="ml",     # "ml" (maximum likelihood) or "pa" (principal axis)
            corr=None,       # pass a correlation matrix here instead of raw data
            smc=True).fit()  # squared multiple correlations as initial communalities

fa.rotate("oblimin")         # rotate in place

The most important options are:

We can then extract the estimates such as eigenvalues, loadings, and communalities:

import numpy as np

eigenvalues   = np.sort(np.linalg.eigvalsh(data.corr()))[::-1]  # for the Kaiser criterion
loadings      = np.real_if_close(fa.loadings)                   # item x factor matrix
communalities = 1 - fa.uniqueness                               # variance explained per item

print(fa.summary())   # a formatted overview of loadings and uniquenesses