3

I am running a GLM regression in Python using statsmodels using the following code. I specifically want to implement a log link function. I am able to write R like formulas using Statsmodels.

The following code successfully runs but throws up a Deprecation Warning. Can anyone suggest how to get rid of this warning. Thanks for the help.

Code:

mod = smf.glm(formula='y ~  C(x1) + C(x2) + C(x3) + x4 + x5', data=data,family=sm.families.Gamma(link=sm.families.links.log))
reg = mod.fit()
print(reg.summary())

Warning: DeprecationWarning: Calling Family(..) with a link class as argument is deprecated. Use an instance of a link class instead.

4

3 回答 3

3

我认为以上任何一个答案都不正确。按照警告的指示,正确的方法是使用括号内的链接函数的相应实例:

mod = smf.glm(formula='y ~  C(x1) + C(x2) + C(x3) + x4 + x5', data=data,family=sm.families.Gamma(link=sm.families.links.log()))
reg = mod.fit()
print(reg.summary())
于 2021-08-06T10:16:21.280 回答
0

我正在解决同样的问题。我注意到,如果我删除 () 中的所有内容,结果完全一样,没有错误。模型摘要具有相同的值,并且 AIC 值相同。

带有警告的代码:

glm_poisson_log = sm.GLM(endog, exog, family = sm.families.Poisson(sm.families.links.log))
results = glm_poisson_log.fit()

没有警告的代码:

glm_poisson_log = sm.GLM(endog, exog, family = sm.families.Poisson **()**)
results = glm_poisson_log.fit()

尝试删除链接信息。

这个网站也特别有帮助:https ://www.statsmodels.org/stable/glm.html

于 2020-06-04T22:50:09.917 回答
0

here is the solution:

sm.families.family.Gamma.links
link_g = sm.genmod.families.links.log
link_g

fit = sm.GLM.from_formula(formula, data=df, family=sm.families.Gamma(link_g())).fit()
于 2020-07-14T04:03:43.100 回答