Closed
Labels
Milestone
Description
Why can I not use the class?
it works with the instance sm.families.links.log
>>> mod_glm = sm.GLM(y, x, family=sm.families.Gaussian(link=sm.families.links.Log))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new2_py27\statsmodels\statsmodels\genmod\families\family.py", line 408, in __init__
self.link = link()
File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new2_py27\statsmodels\statsmodels\genmod\families\family.py", line 60, in _setlink
raise ValueError(errmsg % (`self.links`, link))
ValueError: Invalid link for family, should be in [<class 'statsmodels.genmod.families.links.log'>, <class 'statsmodels.genmod.families.links.identity'>, <class 'statsmodels.genmod.families.links.inverse_power'>]. (got <statsmodels.genmod.families.links.Log object at 0x06443830>)
Reacted by Gianr Lazz and Nikita Titov
Activity
josef-pkt commentedon Mar 25, 2014
log is a subclass of Log, not an instance
should the link also take an instance? If we want to have a parameterized link as in robust norms?
jseabold commentedon Mar 25, 2014
The parameters for the link function are passed to the family. Cf. NegativeBinomial, but, yeah, this looks pretty dumb.
jseabold commentedon Mar 25, 2014
I also recall that there may be theoretical concerns for parametric links, depending on the assumptions. E.g., you can't optimize alpha in negative binomial and still have it be in the exponential family so that GLM holds. I don't recall the details though. See Hardin and Hilbe.
josef-pkt commentedon Mar 25, 2014
Yes, you're right about extra parameters.
I was thinking of optimizing them outside, for negative binomial or for a box-cox transformation for example.
(I haven't used GLM in a long time except for running premade examples for testing, and the usage is not "obvious" to me.)
I think
family=sm.families.Gaussian(link=sm.families.links.log)is doing non-linear least squares (almost, except it uses MLE). I didn't realize the connection of using GLM for single index non-linear models before.josef-pkt commentedon Mar 25, 2014
I think we could also add a Stata-like
forceoption to accept "inadmissable" or user defined link classes.josef-pkt commentedon Aug 9, 2014
another case where valid link checking looks too strict
I temporarily turned off valid link checking because this raises an exception
this
mod1 = GLM(endog_bin, exog, family=families.Binomial(links.CDFLink))should be similar/equivalent, IIUC, to Probit
see http://www.ats.ucla.edu/stat/r/dae/probit.htm
Parameters agree, bse don't agree very closely
similar cluster robust covariance differ a little bit, PR #1870
edit: I opened #1878 for low precision in link.probit hessian
ENH: family: add option to turn of valid link check, or warn. see sta…
jseabold commentedon Sep 26, 2014
Moving the milestone since the PR already has 0.7.
bashtage commentedon Jul 30, 2026
Fixed by PR #7579 (clear TypeError when a link class rather than instance is passed to a Family) and PR #7816 (unified the capitalized/lowercase link-alias validity lists). Closing as fixed.