# CDF of a copula from Copulas.jl?

**URL:** <https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786>\
**Category:** Statistics\
**Tags:** question, package\
**Created:** [August 15, 2022, 4:22pm UTC](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786 "2022-08-15T16:22:18Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![HJW019](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hjw019/32/22102_2.png) [@HJW019](https://discourse.julialang.org/u/HJW019)\
**Post date:** [August 19, 2022, 2:22am UTC](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786/22 "2022-08-19T02:22:05Z")

</div>

The lower-bound problem may depend on how we define the copula function. The following is my understanding. Consider a bivariate joint distribution constructed by a copula function:

H\_\rho(x, y) = C\_\rho(\Phi\_x(x), \Phi\_y(y))

where H\_\rho() is the joint distribution function, C\_\rho() is the copula, \Phi\_x(.) is the CDF of the marginal distribution of x; similar for \Phi\_y(.).

In the case where both x and y have normal marginal distributions, we have x\in (-\infty, \infty) and y\in (-\infty, \infty) while both \Phi\_x(\cdot) and \Phi\_y(\cdot) are uniformally distributed in (0,1).

So, whether the lower bounds in the code should be -\infty or 0, may depend on whether the model is constructed on (x, y) or (\Phi\_x(x), \Phi\_y(y)).

Using the code example in my previous post, the joint distribution is constructed by `D1 = SklarDist(C1, (x,y))` which, I believe, would have x and y as inputs to `D1` (i.e., `D1` is akin to H\_\rho(x,y)). Therefore, when doing integration on `D1`, I think the lower bounds should be those of (x,y), i.e., -\infty.

Does it make sense?

ps. Now I think I understand your comment: You want the joint distribution to be represented by C\_\rho(\Phi\_x(x), \Phi\_y(y)) where the arguments are defined by (\Phi\_x(), \Phi\_y()). I am not sure whether this is a good idea for many empirical researchers. Many times our data is in the form of x (e.g., log of the class scores) but not \Phi\_x(). We want to input (x, y) and get the pdf, cdf, and the likelihood value of the distribution. This may be a case where good notations and practical uses are in conflict.

(edit to add the last paragraph)

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [August 19, 2022, 10:00am UTC](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786/23 "2022-08-19T10:00:25Z")

</div>

The problem is definitely not with the endpoints, but rather with my algorithm for computing the gaussian copula’s cdf, EDIT: which was completely wrong.

---

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [August 19, 2022, 12:49pm UTC](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786/24 "2022-08-19T12:49:25Z")

</div>

One more thing I found.  
`cdf` calculation can be very unstable for hcubature / pcubature when the covariance matrix is ill-conditioned.

You can check with this:

```julia
sigm = [0.0013865355202741095 -0.023165016749546796; -0.023165016749546796 0.7991000945648858]
ll= [-1.961458153653283, -0.5364265399377888]
ul=[1.3629503813703872, 0.9163988499775846]

```

and compare HCubature, MonteCarloIntegration, MvNormalCDF

```julia
julia> vegas(x->pdf(MvNormal([0.0013865355202741095 -0.023165016749546796; -0.023165016749546796 0.7991000945648858]), x), [-1.961458153653283, -0.5364265399377888], [1.3629503813703872, 0.9163988499775846])
nevals = 100000
(0.5757244529231219, 0.0026735571093816387, 1.1996526761564548)

julia> MvNormalCDF.mvnormcdf(MvNormal([0.0013865355202741095 -0.023165016749546796; -0.023165016749546796 0.7991000945648858]), [-1.961458153653283, -0.5364265399377888], [1.3629503813703872, 0.9163988499775846])
(0.5731256346884859, 0.0)

julia> hcubature(x->pdf(MvNormal([0.0013865355202741095 -0.023165016749546796; -0.023165016749546796 0.7991000945648858]), x), [-1.961458153653283, -0.5364265399377888], [1.3629503813703872, 0.9163988499775846])
(0.11536400241722981, 1.6726225814742802e-9)

```

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [August 19, 2022, 1:01pm UTC](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786/25 "2022-08-19T13:01:04Z")

</div>

I settled for the dependency on `MvNormalCDF` after reading the article from Alan Genz and understanding my previous mistakes…

@HJW019 : Should work on Copulas 0.1.6 (once registered), thanks again for the catch.

---

<div class="post-metadata">

**Author:** ![HJW019](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hjw019/32/22102_2.png) [@HJW019](https://discourse.julialang.org/u/HJW019)\
**Post date:** [August 19, 2022, 2:41pm UTC](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786/26 "2022-08-19T14:41:15Z")

</div>

Great! Thanks a lot.

[Previous page](https://discourse.julialang.org/t/cdf-of-a-copula-from-copulas-jl/85786.md?page=1)
