简体   繁体   English

使用python statsmodels修复summary_col中的标签外生变量

[英]Fix Label Exogenous Variables in summary_col with python statsmodels

I want to produce regression tables like those yielded by summary_col (standard journal tables) but with custom explanatory variable labels.我想生成类似于summary_col(标准期刊表)生成的回归表,但带有自定义解释变量标签。

Is there a way to change the row names saved in the model params attribute?有没有办法更改保存在模型参数属性中的行名称?

As of now I rename variables the closest I can to what I intend, but there ought to be a better way to do this.到目前为止,我将变量重命名为最接近我想要的,但应该有更好的方法来做到这一点。

Suppose you have done假设你已经完成

reg = smf.ols(formula = "y~x1+x2+x3").fit()

I suggest (1) to have a dictionary where you hold all the relabeling: dic = {original_vname: new_name} a (2) a pair of useful functions:我建议 (1) 有一个字典来保存所有的重新标记: dic = {original_vname: new_name} a (2) 一对有用的函数:

def rename_vars(vname): 
    to_ret = vname
    for orig_vname in list(dic.keys()):
        if vname == 'original_vname':
            to_ret = dic['original_vname'] 
    return to_ret

and

def rename_ols(reg): 
    for i in range(len(reg)): 
        reg[i] = rename_vars(reg[i])

Then, just do:然后,只需执行以下操作:

rename_ols(reg.model.exog_names) 

And that's it.就是这样。 Once you call summary_col, the variables will show up with the new labels.调用 summary_col 后,变量将显示新标签。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Statsmodels -python 中使用 SARIMAX 预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using SARIMAX in Statsmodels -python 具有外生变量矩阵的statsmodels SARIMAX大小不同 - statsmodels SARIMAX with exogenous variables matrices are different sizes StatsModels SARIMAX with exogenous variables - 如何提取外生系数 - StatsModels SARIMAX with exogenous variables - how to extract exogenous coefficients 如何使用 statsmodels 的 ARMA 来预测外生变量? - How to use statsmodels' ARMA to predict with exogenous variables? 使用 Statsmodels -python 中的时变回归示例代码预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using Time-varying regression example code in Statsmodels -python 在从 Python 中的 statsmodels 传递到 SARIMAX() 的 exog 参数之前,我们是否需要对外生变量进行差分? - Do we need to do differencing of exogenous variables before passing to exog argument of SARIMAX() from statsmodels in Python? 在Python statsmodels中获取正确的外生最小二乘预测 - Getting correct exogenous least squares prediction in Python statsmodels 当我使用python statsmodels在OLS中添加外生变量时,为什么R-Squared会减少 - Why would R-Squared decrease when I add an exogenous variable in OLS using python statsmodels Python:不要在 statsmodels 摘要中显示假人 - Python: Do not show dummies in statsmodels summary Python 2.7 - statsmodels - 格式化和编写摘要输出 - Python 2.7 - statsmodels - formatting and writing summary output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM