Skip to content

ENH: Emit warning in GLM if link does not respect family domain (#2208) - #2212

Merged
josef-pkt merged 1 commit into
statsmodels:masterfrom
kshedden:glm-family-warn-bound
Jan 28, 2015
Merged

josef-pkt merged 1 commit into
statsmodels:masterfrom
kshedden:glm-family-warn-bound

Conversation

@kshedden

Copy link
Copy Markdown
Contributor

Partially (fully?) addresses #2208.

If we go ahead with this, we should add it to GEE too before merging.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 83.05% when pulling 6994f50 on kshedden:glm-family-warn-bound into e76af31 on statsmodels:master.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be easier to maintain if it is in the family where currently the allowed links are defined.
eg. split

domain_safe_links = [...]
links = domain_safe_links + [L.log, L.identity]

or similar

for example Binomial is missing cloglog, and when we add loglog then it only has to be added at one point to the family.

@josef-pkt

Copy link
Copy Markdown
Member

I'm just thinking about weird/unusual cases, which are currently not allowed

link could define a strict subset of the domain: e.g. Poisson with logit link which would bound the poisson intensity/expected value to (0, 1) which is inside the Poisson domain (0, +inf).

current warning is general enough that it can be just interpreted as a domain mismatch.

edit: It not really so weird. IIRC, I've seen an article with a custom link for Poisson that used Logit with multiplicative exposure as approximation to Binomial with counts.

@kshedden
kshedden force-pushed the glm-family-warn-bound branch from 17d07f3 to 0449bce Compare January 28, 2015 13:38
@coveralls

coveralls commented Jan 28, 2015 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 83.048% when pulling 0449bce on kshedden:glm-family-warn-bound into e76af31 on statsmodels:master.

Comment thread statsmodels/genmod/families/family.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can define safe_links = links i.e. as copy of links (so it's defined for all our families)
I think using a list is better than using a tuple so we or users can monkey patch it if necessary.
family.safe_links.append(mylink)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I used a tuple because isinstance requires a tuple not a list. But I can convert the list to a tuple in the isinstance call.

Also added the checks to GEE.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 83.05% when pulling 6e800f2 on kshedden:glm-family-warn-bound into e76af31 on statsmodels:master.

Comment thread statsmodels/genmod/families/family.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I checked: cloglog is a subclass of Logit so should be covered.
maybe a comment in the code as a reminder: something like # other safe links are subclasses

@josef-pkt

Copy link
Copy Markdown
Member

looks good, essentially ready to merge
I will look at this again when I look at the other link checks #1880

can you squash the commits with rebase -i? Ralph just wrote some instructions in a scipy PR
scipy/scipy#4407 (comment)
It needs to have an editor registered with git, but that should work automatically or by default (except on Windows).

Change method of instance comparison

Moved safe_links to be class variable

CDFLink is safe for binomial

Change tuple to list; add link-checking to GEE

Add comment re subclass links
@kshedden
kshedden force-pushed the glm-family-warn-bound branch from 0c3194f to 3b99b60 Compare January 28, 2015 16:04
@kshedden

Copy link
Copy Markdown
Contributor Author

Thanks, rebased and squashed.

@josef-pkt

Copy link
Copy Markdown
Member

Thanks Kerby, rebase looks good

I'll merge after TravisCI reports back.

josef-pkt added a commit that referenced this pull request Jan 28, 2015
ENH: Emit warning in GLM if link does not respect family domain (#2208)
@josef-pkt
josef-pkt merged commit 6441b92 into statsmodels:master Jan 28, 2015
@kshedden
kshedden deleted the glm-family-warn-bound branch February 5, 2015 19:50
@josef-pkt josef-pkt added this to the 0.7 milestone Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants