【发布时间】:2019-06-18 05:25:10
【问题描述】:
是否有在 python 中执行验证性因子分析的包?我发现了一些可以在 python 中执行探索性因子分析(scikitlearn、factor_analyzer 等),但我还没有找到可以执行 CFA 的包。
【问题讨论】:
标签: python scikit-learn statistics factor-analysis dimension-reduction
是否有在 python 中执行验证性因子分析的包?我发现了一些可以在 python 中执行探索性因子分析(scikitlearn、factor_analyzer 等),但我还没有找到可以执行 CFA 的包。
【问题讨论】:
标签: python scikit-learn statistics factor-analysis dimension-reduction
Spyder 中的 python 3.7.3 (Anaconda Navigator)
factor_analyzer 也做 CFA:
import pandas as pd
from factor_analyzer import FactorAnalyzer
df= pd.read_csv("test.csv")
from factor_analyzer import (ConfirmatoryFactorAnalyzer, ModelSpecificationParser)
model_dict = {"F1": ["V1", "V2", "V3", "V4"], "F2": ["V5", "V6", "V7", "V8"]}
model_spec = ModelSpecificationParser.parse_model_specification_from_dict(df, model_dict)
cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=False)
cfa.fit(df.values)
cfa.loadings_
【讨论】:
你可以试试包 psy (https://pypi.org/project/psy/)。我找不到它的文档,但我可以阅读用中文编写的 cmets。
例子:
import psy
# items is a pandas data frame containing item data
# Specify how the items are mapped to the factors
# In this case, all mapped to one factor
item_factor_mapping = np.array([[1]] * items.shape[1])
print(psy.cfa(items, item_factor_mapping))
【讨论】: