Skip to content

GLM families link classes #1509

Closed
Closed

Description

@josef-pkt

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>)

Activity

  1. josef-pkt commented on Mar 25, 2014

    @josef-pkt
    MemberAuthor

    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?

  2. jseabold commented on Mar 25, 2014

    @jseabold
    Member

    The parameters for the link function are passed to the family. Cf. NegativeBinomial, but, yeah, this looks pretty dumb.

  3. jseabold commented on Mar 25, 2014

    @jseabold
    Member

    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.

  4. josef-pkt commented on Mar 25, 2014

    @josef-pkt
    MemberAuthor

    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.

  5. josef-pkt commented on Mar 25, 2014

    @josef-pkt
    MemberAuthor

    I think we could also add a Stata-like force option to accept "inadmissable" or user defined link classes.

  6. josef-pkt commented on Aug 9, 2014

    @josef-pkt
    MemberAuthor

    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

    >>> print pd.concat((res_probit.params, res_glm_probit.params), axis=1)
                     0         1
    yr_con    0.202947  0.202947
    op_75_79  0.523378  0.523378
    const    -1.253350 -1.253350
    >>> print pd.concat((res_probit.bse, res_glm_probit.bse), axis=1)
                     0         1
    yr_con    0.232729  0.232456
    op_75_79  0.490381  0.487844
    const     0.604882  0.610261
    

    similar cluster robust covariance differ a little bit, PR #1870

    edit: I opened #1878 for low precision in link.probit hessian

  7. added this to the 0.6 milestone on Aug 9, 2014
  8. modified the milestones: 0.7, 0.6 on Sep 26, 2014
  9. jseabold commented on Sep 26, 2014

    @jseabold
    Member

    Moving the milestone since the PR already has 0.7.

  10. modified the milestones: 0.7, 0.13 on Apr 6, 2021
  11. bashtage commented on Jul 30, 2026

    @bashtage
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions