Skip to content

ENH: GLM loglikeobs (Mixed mixin) - #3030

Closed
josef-pkt wants to merge 2 commits into
statsmodels:mainfrom
josef-pkt:mixed_mixin
Closed

josef-pkt wants to merge 2 commits into
statsmodels:mainfrom
josef-pkt:mixed_mixin

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Jun 17, 2016 •

Copy link
Copy Markdown
Member

I have no idea what the status is or where the mixed mixin (from the branch title) is.

Just found this while browsing issues, open PR as reminder, not rebased

about MixedMixin, new module was not added to branch
"M:...\statsmodels_py34\statsmodels\base\mixed.py"
Modified ‎Wednesday, ‎May ‎6, ‎2015, ‏‎11:22:16 AM

special.gammaln(y + 1) -
special.gammaln(self.n - y + 1) + y *
np.log(mu/(1 - mu)) + self.n *
np.log(1 - mu))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there some convention behind where line-breaks are in these expressions? My default is to base them on order-of-operations, so the last three lines would be split at the + instead of at the *. Not a big deal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The line breaks here look a bit unintuitive.
It's copy-paste here, and I don't know why the original has these breaks

Only official convention so far: readability in the eye of the developer and reviewer, with sometimes some usual or unusual reformatting by pep-8 tool

log(scale) + scale*gammaln(1/scale))
where gammaln is the log gamma function.
"""
return - 1./scale * (endog/mu + np.log(mu) + (scale - 1) *

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More recent version simplifies some terms in here.

if scale is None:
# This is just the loglikelihood for classical OLS
nobs = endog.shape[0]
ssr = ss(endog-self.fitted(mu))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like ss is scipy.stats. This is probably intended to be np.sum(endog - self.fitted(mu)**2, axis=0).

@jbrockmendel jbrockmendel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implementing loglikeobs is a really good idea.

One thought that could trim the module down quite a bit is to have the Family class implement a default version of loglike that returns freq_weights.dot(self.loglikeobs(...))

@josef-pkt

Copy link
Copy Markdown
Member Author

loglikeobs versus loglike, and similar score_obs versus score: I thought about it but I'm usually conservative when coding

keeping code duplication, then

  • I can use loglike as a cross-check or unit test for loglikeobs
  • I don't have to think about performance changes in loglike. There are parts that are simpler to compute in sum directly. There is still the open question whether we want to skip/cache some parts that are not relevant for the optimization. Implementing separate loglikeobs and score_obs means I don't have to make up my mind about loglike performance issues.

generic models use automatic sum(xxx_obs), but not in core models.

@jbrockmendel

Copy link
Copy Markdown
Contributor

This shouldn't be that hard to pull over the finish line. The two cases that aren't obvious are

  1. Tweedie where loglike returns np.nan --> does loglikeobs return an array of nans?
  2. Gaussian where loglike takes logs after summing and iweights aren't just weights for the sum.

@josef-pkt

Copy link
Copy Markdown
Member Author

This is most likely obsolete when #3856 is merged

@josef-pkt

Copy link
Copy Markdown
Member Author

Note the changes here are obsolet with merge of #3856

I keep this open for the second part of the title: MixedMixin.
I still need to put that code somewhere, and there is no other issue or PR

@josef-pkt

Copy link
Copy Markdown
Member Author

outdated but not obsolete

there is no GLM.loglike_obs or GLM.loglikeobs
however, it can now be implemented generically because the families have loglike_obs.

discrete and my MixedMixin uses loglikeobs, but we want to switch to loglike_obs. So we need to deprecate loglikeobs in discrete.

@josef-pkt josef-pkt added this to the 0.14 milestone Sep 21, 2021
@josef-pkt

josef-pkt commented Sep 21, 2021 •

Copy link
Copy Markdown
Member Author

families now already have loglike_obs using mu as parameter
GLM itself doesn't have it yet.

It looks like we only need the GLM method with appropriate call to the family, the rest of this PR is obsolete.
#5502 includes the GLM method (closer to current main than the one in here)

aside: We should deprecate loglikeobs where it already exists and use loglike_obs

@josef-pkt josef-pkt closed this Sep 21, 2021
@josef-pkt josef-pkt removed this from the 0.14 milestone Sep 21, 2021
@josef-pkt josef-pkt added the superseded Used for PRs with content that is superseded by a newer PR label Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-genmod superseded Used for PRs with content that is superseded by a newer PR type-enh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants