# Computing expectation of nonlinear function of multinomial logit

**URL:** <https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575>\
**Category:** General Usage\
**Tags:** numerics, integral\
**Created:** [May 5, 2022, 10:15pm UTC](https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575 "2022-05-05T22:15:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samerb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samerb/32/9242_2.png) [@samerb](https://discourse.julialang.org/u/samerb)\
**Post date:** [May 5, 2022, 10:15pm UTC](https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575/1 "2022-05-05T22:15:25Z")

</div>

Suppose I have constants \{\delta\_j\}\_{j \in J} and have random variables \{\varepsilon\_j\}\_{j\in J} distributed iid according to type I extreme value distribution as in a standard multinomial logit model. Let F: \mathbb{R}^J \rightarrow \mathbb{R} be the joint distribution \varepsilon\_j's. Suppose further that I have a concave function u: \mathbb{R} \rightarrow \mathbb{R}.

I want to compute the expectation \int u \left( \max{\{\delta\_j + \varepsilon\_j \}\_{j \in J}} \right) dF(\varepsilon).

Further, I want to make the \delta\_j's be functions of some other vector of parameters x, and then maximize the function H(x) = \int u \left( \max{\{\delta\_j(x) + \varepsilon\_j \}\_{j \in J}} \right) dF(\varepsilon) over x.

Is there a recommended method for doing this? To compute the integral I could use monte carlo simulation I guess. Toward that end, what is the best way to sample from type I extreme value?

I want to make sure that whatever way I use to compute the integral will make it easy to optimize the integral over the parameters as described in my “Further” sentence above. Any recommendations on this?

Thanks!

---

<div class="post-metadata">

**Author:** ![MeAmSam](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@MeAmSam](https://discourse.julialang.org/u/MeAmSam)\
**Post date:** [June 27, 2023, 5:37pm UTC](https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575/2 "2023-06-27T17:37:03Z")

</div>

Hi!

I am also computing a multinomial logit and am wondering what the best way to do this is. Were you able to solve your problem?

---

<div class="post-metadata">

**Author:** ![samerb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samerb/32/9242_2.png) [@samerb](https://discourse.julialang.org/u/samerb)\
**Post date:** [June 27, 2023, 5:59pm UTC](https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575/3 "2023-06-27T17:59:30Z")

</div>

I don’t remember. Probably not exactly. I do remember learning about something called the invariance property for multinomial logit which can help compute some things analytically. Don’t think that would would help here though. If it’s econ related, you might look at what they’re doing in this [paper](https://www.sciencedirect.com/science/article/abs/pii/S0301421510000765) and refs just to see a paper with logit under nonlinear utility. Train’s Discrete Choice book is a good reference for general stuff around these things.

---

<div class="post-metadata">

**Author:** ![MeAmSam](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@MeAmSam](https://discourse.julialang.org/u/MeAmSam)\
**Post date:** [June 29, 2023, 2:51pm UTC](https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575/4 "2023-06-29T14:51:07Z")

</div>

I’ll look into those - thank you!

---

<div class="post-metadata">

**Author:** ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Post date:** [June 29, 2023, 6:03pm UTC](https://discourse.julialang.org/t/computing-expectation-of-nonlinear-function-of-multinomial-logit/80575/5 "2023-06-29T18:03:25Z")

</div>

Maybe I’m misunderstanding your question. If you’re working with a standard multinomial Logit model, you don’t have to perform any optimization numerically. You’re assuming a specific distribution for F and the integral has a closed-form solution.

If, for example, \delta\left(x\_{j}\right):=\beta x\_{j}, you’ll have the solution \frac{\mathrm{e}^{\beta x\_{j}}}{\sum\_{k}\mathrm{e}^{\beta x\_{k}}}.
