# NaN from multinomial distribution at p=1

**URL:** <https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573>\
**Category:** Statistics\
**Created:** [October 19, 2017, 9:33pm UTC](https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573 "2017-10-19T21:33:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [October 19, 2017, 9:33pm UTC](https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573/1 "2017-10-19T21:33:06Z")

</div>

I’m getting `NaN` from a multinomial distribution, where I expected 1. Is this a bug or am I doing something wrong?

```julia
using Distributions
 
dist = Multinomial(2, [0.999,0.001])
pdf(dist,[2,0]) ## 0.998, ok

dist = Multinomial(2, [1.0,0.0])
pdf(dist,[2,0]) #NaN, not ok

```

The equivalent limit of the binomial has no problem:

```julia
pdf(Binomial(1,0.999),[0,0.5,1]) ## [0.001, 0.0, 0.999] 
pdf(Binomial(1,1.0),[0,0.5,1]) ## [0.0, 0.0, 1.0]

```

---

<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:** [October 20, 2017, 7:12am UTC](https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573/2 "2017-10-20T07:12:56Z")

</div>

~~You are getting a `NaN` from a 0^0, which is correct. See the [PMF of a multinomial](https://en.wikipedia.org/wiki/Multinomial_distribution#Probability_mass_function).~~

EDIT: correcting my mistake — in these contexts it is customary to interpret 0^0=1. See the famous “[Two notes on notation](https://arxiv.org/abs/math/9205211)” paper by Knuth for example.

---

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [October 20, 2017, 7:24am UTC](https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573/3 "2017-10-20T07:24:38Z")

</div>

The formula has a 0^0, I’m sure this is what’s causing the NaN.

But the limiting distribution puts all the mass on one point, and this limit is what I was hoping the function would return.

This works for the binomial case, where again the simple formula has an indefinite 0^0, but I guess someone has caught the special case.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [October 21, 2017, 9:47am UTC](https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573/4 "2017-10-21T09:47:22Z")

</div>

Maybe file a bug against Distributions.

---

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [October 21, 2017, 10:13pm UTC](https://discourse.julialang.org/t/nan-from-multinomial-distribution-at-p-1/6573/5 "2017-10-21T22:13:22Z")

</div>

OK, I made issue [675](https://github.com/JuliaStats/Distributions.jl/issues/675).

I also had a brief look at the code but am way out of my depth!
