I’m running into domain issues when trying to compute the convolution of two random variables where their joint distribution is defined by a copula. By convolution I mean:
Here is how I’m constructing the copula using Copula.jl and Distributions.jl:
X1 = Gumbel(15.,5.)
X2 = MixtureModel([Normal(-6.,0.1),X1],[0.95,0.05])
ρ = 0.4
C = GaussianCopula([1. ρ; ρ 1.])
D1 = SklarDist(C1,(X1,X2))
My first thought was to loop through various ‘z’ values as in:
N = 100
Zs = collect(range(-10.,60.,N))
ConvD = similar(Zs)
for k=1:N
ConvD[k] = quadgk(x->pdf(D1,[x,Zs[k]-x]),-80.,80.,rtol=1e-6)[1]
end
which errors:
DomainError with 0.0:
integrand produced NaN in the interval (-80.0, 80.0)
Stacktrace:
[1] evalrule(f::var"#15#16"{Int64}, a::Float64, b::Float64, x::Vector{Float64}, w::Vector{Float64}, wg::Vector{Float64}, nrm::typeof(norm))
@ QuadGK C:\Users\Monali\.julia\packages\QuadGK\BjmU0\src\evalrule.jl:39
[2] #8
@ C:\Users\Monali\.julia\packages\QuadGK\BjmU0\src\adapt.jl:54 [inlined]
[3] ntuple
@ .\ntuple.jl:48 [inlined]
[4] do_quadgk(f::var"#15#16"{Int64}, s::Tuple{Float64, Float64}, n::Int64, atol::Nothing, rtol::Float64, maxevals::Int64, nrm::typeof(norm), _segbuf::Nothing, eval_segbuf::Nothing)
@ QuadGK C:\Users\Monali\.julia\packages\QuadGK\BjmU0\src\adapt.jl:52
[5] #50
@ C:\Users\Monali\.julia\packages\QuadGK\BjmU0\src\api.jl:83 [inlined]
[6] handle_infinities(workfunc::QuadGK.var"#50#51"{Nothing, Float64, Int64, Int64, typeof(norm), Nothing, Nothing}, f::var"#15#16"{Int64}, s::Tuple{Float64, Float64})
@ QuadGK C:\Users\Monali\.julia\packages\QuadGK\BjmU0\src\adapt.jl:189
[7] quadgk(::var"#15#16"{Int64}, ::Float64, ::Vararg{Float64}; atol::Nothing, rtol::Float64, maxevals::Int64, order::Int64, norm::Function, segbuf::Nothing, eval_segbuf::Nothing)
@ QuadGK C:\Users\Monali\.julia\packages\QuadGK\BjmU0\src\api.jl:82
[8] top-level scope
@ In[59]:5
Initially, I’d used a Gamma distribution instead of the Gumbel and ran into this error, which made since given that the code was attempting to evaluate the Gamma outside its support. I switched to the Gumbel since it and the Normal distribution have support across all Reals and didn’t expect to see the same error.
I’m wondering if this issue stems from the pdf of the copula returning NaN, when it should actually be returning 0?
For example,
pdf(D1,[-30., 0.])
#returns NaN
Any insight would be greatly appreciated!