Skip to content

more glm functions #1964

Description

@bnicenboim

Feature request: glms for positive continuous distributions

It would be very useful to include _glm_lpdf functions positive-only data with positively-skewed errors. (See my post here
https://discourse.mc-stan.org/t/trying-to-understand-glm-lp-f-functions-in-stan/16400/5).

In cognitive psychology and psycholinguistics, reaction (and reading) times are usually fit with a lognormal likelihood. So I think that lognormal_glm_lpdf would be for sure useful for wide audience.
A gamma distribution is also not uncommon (also for ecology, https://seananderson.ca/2014/04/08/gamma-glms/), but here there are several posibilities for a link function, inverse link, no link, log link.

Additions by @avehtari:

  • We're missing also binomial_logit_glm (requested in Stan discourse.
  • ordered_probit_glm (we have ordered_logistic_glm)

So the current wish list would be

  • lognormal
  • gamma
  • weibull
  • ordered_probit
  • binomial (added in 2.34 January 2024)

Activity

  1. bob-carpenter commented on Jul 6, 2020

    @bob-carpenter
    Member

    Is this the intended definition, or if not, could you clarify.

    lognormal_glm_lpdf(y, x, alpha, beta, sigma)
      = normal_glm_lpdf(log(y), x, alpha, beta, sigma)
      = lognormal_lpdf(y | exp(alpha + x * beta), sigma)
    

    Edit: The first one would also need a Jacobian if y is a parameter vector.

  2. bnicenboim commented on Jul 6, 2020

    @bnicenboim
    Author

    I mean this:

    lognormal_glm_lpdf(y, x, alpha, beta, sigma)
      = normal_glm_lpdf(log(y), x, alpha, beta, sigma) + -log(y) // this is the Jacobian, right?
    

    ha, well, now that I write it I see that it's so simple that maybe it doesn't need its own function... In any case, most reaction times are fitted this way.

    The gamma is another story, so my request is less dumb :)

  3. SteveBronder commented on Jul 6, 2020

    @SteveBronder
    Collaborator

    If it's a common glm then I don't see any reason to not have lognormal_glm_lpdf tho'

  4. bob-carpenter commented on Jul 7, 2020

    @bob-carpenter
    Member

    Anything that requires a Jacobian is going to be tricky for a lot of our users. Also, I strongly prefer not to have transforms everywhere in code. So I think lognormal_glm_lpdf would make sense.

  5. changed the title [-]glm functions for positive-only data with positively-skewed errors (lognormal and gamma likelihoods)[/-] [+]glm functions for positive continuous distributions (lognormal, gamma, weibull)[/+] on Mar 16, 2022
  6. avehtari commented on Mar 16, 2022

    @avehtari
    Member

    I edited the issue title and suggest adding also weibull_log_glm_* which is very common in survival analysis.
    In survival analysis with censored observations, it would be very useful to have in addition of *_glm_lpdf have corresponding *_glm_lcdf and *_glm_lccdf.

    Of course, it would be nice to have glm's for almost all distributions, but @rok-cesnovar asked to prioritize.

    2.29 release notes say

    An example of a simple but powerful optimization with the --O1 flag. The call
    target += bernoulli_logit_lpmf(y | mx * beta);
    will automatically be replaced with a call to the bernoulli-logit GLM function:
    target += bernoulli_logit_glm_lpmf(y, mx, 0, beta);
    and thus, I'm asking just in case, if that could provide an easier way to get compound speedup without explicitly defining all possible glm functions?

  7. rok-cesnovar commented on Mar 16, 2022

    @rok-cesnovar
    Member

    I'm asking just in case, if that could provide an easier way to get compound speedup without explicitly defining all possible glm functions?

    Unfortunately not, this just replaces calls to used the GLM C++ function instead of the user having to know there is a GLM function.

    Of course, it would be nice to have glm's for almost all distributions, but @rok-cesnovar asked to prioritize.

    I agree it would be nice to have more of them or all of them that make sense, especially with the stanc3 optimization this becomes even more useful as the user doesn't have to know which functions have GLM equivalents.

    Maybe a good project for google summer of code or something like that? Given that we have 6 GLM functions that could serve as templates, this should not be a very demanding task, mostly replicating code and writing tests.

  8. changed the title [-]glm functions for positive continuous distributions (lognormal, gamma, weibull)[/-] [+]more glm functions[/+] on Jul 30, 2022
  9. jachymb commented on Jul 21, 2024

    @jachymb
    Contributor

    Perhaps also exponential distribution glm, please? It should be a special case of Weibull. The link function should probably be 1/x for exponential, same as for gamma.

  10. avehtari commented on Feb 12, 2026

    @avehtari
    Member

    I added ordered_probit to the wishlist (ping @SteveBronder)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions