使用多项回归时如何更改 statsmodels 中因变量的参考类别?

发布于 2025-01-19 09:16:28 字数 494 浏览 0 评论 0原文

我正在尝试更改因变量的参考类别(某人投票支持)使用统计模型。我知道,使用C(社交阶级,治疗(参考= 2))使我可以更改一个自变量的参考类别,在此示例中,社交阶层,但这对因变量不起作用。

logitmodel = smf.mnlogit('C(ELECTIONVOTEALL, Treatment(reference=1)) ~ PMMAY + EUvotedremain +votedyes +C(socialclass, Treatment(reference=2))+ leftRight' , df)
dflogit_fit = logitmodel.fit()

我尝试执行针对因变量的自变量有效的操作,但是这会产生一个错误,该错误指出以下内容:

valueError:endog已评估到具有具有形状的多个列的数组(2038,4)。当变量转换为内og是非数字(例如,bool或str)时,就会发生这种情况。

是否有人知道我如何使用statsmodels更改因变量的参考类别?

I am trying to alter the reference category of the dependent variable (what party somebody voted for) while using statsmodels. I know that using C(socialclass, Treatment(reference=2)) allows me to change the reference category of one of the independent variables, social class in this example but this does not work for the dependent variable.

logitmodel = smf.mnlogit('C(ELECTIONVOTEALL, Treatment(reference=1)) ~ PMMAY + EUvotedremain +votedyes +C(socialclass, Treatment(reference=2))+ leftRight' , df)
dflogit_fit = logitmodel.fit()

I tried to do what had worked for the independent variable to the dependent variable however this produces an error which states the following:

ValueError: endog has evaluated to an array with multiple columns that has shape (2038, 4). This occurs when the variable converted to endog is non-numeric (e.g., bool or str).

Does anybody know how I can change the reference category of the dependent variable using statsmodels?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文