# Mixed Logit Model in Julia

**URL:** https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995
**Category:** Finance and Economics
**Created:** [June 6, 2019, 8:20am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995 "2019-06-06T08:20:55Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ig\_hdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ig_hdez/32/7938_2.png) [@ig\_hdez](https://discourse.julialang.org/u/ig_hdez)
#### Post date: [June 6, 2019, 8:20am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/1 "2019-06-06T08:20:55Z")

</div>

Hi everyone!

I’ve created a script to estimate Mixed Logit Models based on the codes of Kenneth Train ([Kenneth Train's Software](https://eml.berkeley.edu/~train/software.html)) for MATLAB.

The code and an example can be found here: [https://github.com/ighdez/MultiLogit](https://github.com/ighdez/MultiLogit)

The main script (test\_mixlogit\_KT.jl) is a replication of the example of Train’s MATLAB code using the same dataset. It calls the required Log-Likelihood function (llf\_mxl.jl), some additional functions such as the MLHS sampler (misc.jl) and a BFGS minimizer written for this purpose (bfgsmin.jl).

My idea is to make this code available for those who want to use it for their research and education purposes, but you’re free to contribute/modify/share the code if you want 😉

¡Saludos!

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 6, 2019, 9:23am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/2 "2019-06-06T09:23:30Z")

</div>

> [@ig\_hdez](#):
>
> My idea is to make this code available for those who want to use it for their research and education purposes, but you’re free to contribute/modify/share the code if you want 😉

For these goals, perhaps it would be better to organize into a Julia package, with a `Project.toml`, tests, etc. In contrast to MATLAB, where the culture is to pass scripts around, Julia library software is usually packaged. See

[https://julialang.github.io/Pkg.jl/v1/creating-packages/](https://julialang.github.io/Pkg.jl/v1/creating-packages/)

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [June 6, 2019, 9:50am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/3 "2019-06-06T09:50:16Z")

</div>

I was reading the code, and you use a lot of numerical derivatives, maybe you can offer an option with Algorithmic Differenciation ([ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl)), for example:

```julia
function numhess(f,param; ep=1e-05)
# your code
end

```

can be obtained directly from ForwardDiff! (a magic thing indeed):

```julia
using ForwardDiff
numhess(f,param) = ForwardDiff.Hessian(f,param)

```

---

<div class="post-metadata">

### Author: ![ig\_hdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ig_hdez/32/7938_2.png) [@ig\_hdez](https://discourse.julialang.org/u/ig_hdez)
#### Post date: [June 6, 2019, 9:58am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/4 "2019-06-06T09:58:52Z")

</div>

Thanks for your suggestion, Tamas. I will do it.

---

<div class="post-metadata">

### Author: ![ig\_hdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ig_hdez/32/7938_2.png) [@ig\_hdez](https://discourse.julialang.org/u/ig_hdez)
#### Post date: [June 6, 2019, 9:59am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/5 "2019-06-06T09:59:32Z")

</div>

Agree! I will see how it performs. Thanks!

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [June 7, 2019, 1:36am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/6 "2019-06-07T01:36:14Z")

</div>

[https://github.com/Nosferican/Econometrics.jl](https://github.com/Nosferican/Econometrics.jl) has basic mlogit and ologit. clogit in the works. I would be happy to host the code if you so wish. Feel free to look at the code if that helps.

---

<div class="post-metadata">

### Author: ![rscarpa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rscarpa/32/14678_2.png) [@rscarpa](https://discourse.julialang.org/u/rscarpa)
#### Post date: [May 8, 2020, 9:54am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/7 "2020-05-08T09:54:10Z")

</div>

Hello Jose,  
a very good project. Have you moved this forward? Indeed it is the only application of Julia to mixed logit I found. I tried it and it is pretty fast. Its use could be made more versatile if there was the option to fix some of the random coefficients means to zero, so as to use random error component (with variance, but zero mean) and produce correlation patterns across random coefficients. Do you have any suggestion on how to achieve this in the current set-up?  
Ric

---

<div class="post-metadata">

### Author: ![ig\_hdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ig_hdez/32/7938_2.png) [@ig\_hdez](https://discourse.julialang.org/u/ig_hdez)
#### Post date: [July 28, 2025, 3:39am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/8 "2025-07-28T03:39:12Z")

</div>

Hi all! It’s been a while.

At last, I managed to build a Julia package that combines speed, flexibility and ease of use to estimate Discrete Choice Models. I would like to introduce you DCM.jl.

The software is in development stage, and you can find it in my GitHub: [GitHub - ighdez/DCM.jl](https://github.com/ighdez/DCM.jl)

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [July 28, 2025, 8:21am UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/9 "2025-07-28T08:21:59Z")

</div>

Looks good! Just a word of warning if you ever plan to have this used more widely - there’s approximatly zero choice that this will be accepted with the name `DCM` in the general registry, so if you do want to register at some point might be worth thinking about a longer/more descriptive package name.

---

<div class="post-metadata">

### Author: ![ig\_hdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ig_hdez/32/7938_2.png) [@ig\_hdez](https://discourse.julialang.org/u/ig_hdez)
#### Post date: [July 28, 2025, 12:07pm UTC](https://discourse.julialang.org/t/mixed-logit-model-in-julia/24995/10 "2025-07-28T12:07:32Z")

</div>

Thanks, @nilshg ! This is relevant for me as I’m interested on registering this package.
