Cdf of a multivariate normal in Julia


#1

I’m trying to use the cdf of a multivariate normal distribution in Julia using Distributions.jl.
While

d = Normal(0,1)
d2 = MvNormal([0.;0.], [1. 0.;0. 1.])
x = [1. ; 2.]
e1 = cdf(d,x[1])
e2 = cdf(d,x[2])

works (as long as the mean vector and the var-cov matrix for the multivariate normal are Floats ), I get an error whenever I write
e3 = cdf(d2,x)
Here is the error message:

ERROR: MethodError: no method matching cdf(::Distributions.MvNormal{Float64,PDMats.PDMat{Float64,Array{Float64,2}},Array{Float64,1}}, ::Array{Float64,1})
Closest candidates are:
  cdf(::Distributions.Distribution{Distributions.Univariate,S<:Distributions.ValueSupport}, ::AbstractArray{T,N}) at /Applications/JuliaPro-0.5.1.1.app/Contents/Resources/pkgs-0.5.1.1/v0.5/Distributions/src/univariates.jl:205

It seems like the cdf function does not support multivariate distributions. I couldn’t find anything on this in the documentation of Distributions.jl. Is there any other way to find a cdf of a multivariate normal in Julia?


#2

Yes, it seems that evaluating the multivariate normal cdf is not supported yet. I didn’t realize that.

There’s some info on the algorithm here, if you’re willing to code it up:

Or perhaps you could combine PyCall and SciPy…?


#3

For reference there is an open issue https://github.com/JuliaStats/Distributions.jl/issues/260

Though it doesn’t look there has been much traction…


#4

Now that I look into PyCall and SciPy, it turns out that scipy.stats have multivariate_normal but doesn’t have cdf defined as a method. Same issue with Julia.

The only suggested solution I’ve found so far is this: https://stackoverflow.com/questions/30560176/multivariate-normal-cdf-in-python-using-scipy but for some reason I can’t find the scipy.stats.mvn that they’re talking about.


#5

Hmm. That’s disappointing. At a pinch you could use Monte Carlo, replacing the probability of your random vector X being less than a fixed vector x with the empirical probability. If speed is not vital it will give you reasonable results.


#6

The latest version of SciPy — version 1.0 — has a cdf method for the multivariate normal. See here.


#7

That’s great, thanks!