我需要用于 2 路聚类的线性模型,这在 statsmodels 中没有正确实现。我想知道是否可以将 stargazer python 库与 linearmodels 包一起使用,而不是与 statsmodels 一起使用。但是当我从线性模型中插入模型时,它会抛出一个错误:请使用经过训练的 OLS 模型作为输入
例子:
from linearmodels.panel import PanelOLS
import pandas as pd
df.set_index(['entity', 'time'], inplace = True)
X = df[["Exog1","Exog2","Exog3"]]
y = df["Dep"]
model = PanelOLS(y, X, entity_effects=True, time_effects=True).fit(cov_type='clustered', cluster_entity=True, cluster_time=True)
print(model)
这按预期输出模型。但是,当我将其插入 int stargazer 时,它会引发以下错误
stargazer = Stargazer([model])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-149-75027b8621a2> in <module>
----> 1 stargazer = Stargazer([model])
~\AppData\Local\Continuum\anaconda3\lib\site-packages\stargazer\stargazer.py in __init__(self, models)
29 self.models = models
30 self.num_models = len(models)
---> 31 self.extract_data()
32 self.reset_params()
33
~\AppData\Local\Continuum\anaconda3\lib\site-packages\stargazer\stargazer.py in extract_data(self)
91 be modified by any rendering parameters.
92 """
---> 93 self.validate_input()
94 self.model_data = []
95 for m in self.models:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\stargazer\stargazer.py in validate_input(self)
43 for m in self.models:
44 if not isinstance(m, RegressionResultsWrapper):
---> 45 raise ValueError('Please use trained OLS models as inputs')
46 targets.append(m.model.endog_names)
47
ValueError: Please use trained OLS models as inputs
我知道 stargazer 可能不支持线性模型,但也许有一种解决方法,可以让我在 Latex 中输出线性模型?