Cdf for multinomial

Being a multivariate distribution, the CDF could be as giving the probability that the sampled outcome vector is (elementwise) smaller or equal to some given count vector. Unfortunately, I’m not aware of an efficient way to compute this. Here is a simple implementation just summing over all potential outcomes:

function mycdf(md::Multinomial, counts)
    reduce(+,
           pdf(md, collect(ns))
               for ns in Iterators.product((0:min(k, md.n) for k in counts)...);
           init = 0.0)
end

You might be able to speed it up a bit more by only summing over the ns vectors in the support of the distribution, i.e., where sum(ns) == md.n, but would need some clever way of only generating that set of vectors in the first place.

1 Like