[英]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.