# Possibility of Logit Parameterized Multnomial in Stan

**URL:** <https://discourse.mc-stan.org/t/possibility-of-logit-parameterized-multnomial-in-stan/14527>\
**Category:** Modeling\
**Created:** [April 22, 2020, 10:09pm UTC](https://discourse.mc-stan.org/t/possibility-of-logit-parameterized-multnomial-in-stan/14527 "2020-04-22T22:09:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleshing](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@aleshing](https://discourse.mc-stan.org/u/aleshing)\
**Post date:** [April 22, 2020, 10:09pm UTC](https://discourse.mc-stan.org/t/possibility-of-logit-parameterized-multnomial-in-stan/14527/1 "2020-04-22T22:09:57Z")

</div>

I saw in the latest Stan release that there is now a logit parameterized glm categorical distribution ([https://mc-stan.org/docs/2\_23/functions-reference/categorical-logit-glm.html](https://mc-stan.org/docs/2_23/functions-reference/categorical-logit-glm.html)).

In the logit parameterized glm categorical distribution, you have M outcomes y\in\{1,\cdots,N\}^M, design matrix x\in\mathbb{R}^{M\times K}, intercepts \alpha\in\mathbb{R}^N, and regression coefficients \beta\in\mathbb{R}^{K\times N}. categorical\_logit\_glm calculates the log pmf corresponding to y\_i\sim\textsf{Categorical}(softmax(\alpha + x\_i \beta)).

You could imagine the case where some number m of the M data points share the same covariates in the design matrix (this could occur if all of the covariates are discrete). In this case, I believe it’s the case (based on [https://github.com/stan-dev/math/blob/develop/stan/math/prim/prob/categorical\_logit\_glm\_lpmf.hpp](https://github.com/stan-dev/math/blob/develop/stan/math/prim/prob/categorical_logit_glm_lpmf.hpp), but my c++ isn’t great so it’s hard to tell) that categorical\_logit\_glm will repeat the computations for the pmfs of the m data points m times, even though they only need to be done once (mainly the concern is doing a log\_sum\_exp m times when it only needs to be done once). More generally you could just imagine the case where you have multinomial instead of purely categorical data. Personally I’m motivated by using Stan for log-linear modelling of multivariate categorical data

This repetition of computations could be avoided by passing in the data as a matrix of counts y\in \mathbb{N}^{N \times M}, and having something like a multinomial\_logit\_glm that calculates the log pmf corresponding to y\_i\in\mathbb{N}^N being multinomial, i.e. y\_i\sim\textsf{Multinomial}(N\_i, softmax(\alpha + x\_i \beta)), where N\_i=\sum\_{i=1}^Ny\_i.

Would it be possible for a logit parameterized glm multinomial distribution to be added to stan?

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [April 23, 2020, 7:57am UTC](https://discourse.mc-stan.org/t/possibility-of-logit-parameterized-multnomial-in-stan/14527/2 "2020-04-23T07:57:06Z")

</div>

There’s an open issue for (non-glm) `multinomial_logit`

> <https://github.com/stan-dev/math/issues/1742>
>
> Summary:
> Add a function that matches the existing bernoulli\_logit and categorical\_logit.
> Description:
> This would add a convenience function usable in multi-outcome logistic regression problems....

It’s pretty old, I guess no one got around to implementing it.

As for `glm`, we don’t have `binomial_logit_glm` either.
