-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbiv_clayton.jl
More file actions
74 lines (62 loc) · 2 KB
/
Copy pathbiv_clayton.jl
File metadata and controls
74 lines (62 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@testitem "constructor" begin
@test_broken isa(ClaytonCopula(2,0), Independence)
@test_broken isa(ClaytonCopula(2,-0.7),WCopula) # should work in any dimenisons if theta is smaller than the bound.
@test_broken isa(ClaytonCopula(2,Inf),MCopula)
end
@testitem "generators" begin
#### This test could be done for many more archimedeans.
θ = [-0.5, 2, 10]
u = [0:0.1:1;]
for ϑ in θ
c = ClaytonCopula(2,ϑ)
for x in u
@test Copulas.ϕ⁻¹(c,Copulas.ϕ(c,x)) ≈ x
end
end
end
@testitem "τ" begin
@test Copulas.τ(ClaytonCopula(2,-0.5)) == -1 / 3
@test Copulas.τ(ClaytonCopula(2,2)) == 0.5
@test Copulas.τ(ClaytonCopula(2,10)) == 10 / 12
end
@testitem "sample" begin
using StatsBase, Random
n = 10^6
θ = [-0.5, 2, 10]
for ϑ in θ
c = ClaytonCopula(2,ϑ)
if ϑ < 0
@test_broken rand(c,n)
else
u = rand(c, n)
@test corkendall(u') ≈ [1.0 Copulas.τ(c); Copulas.τ(c) 1.0] atol = 0.01
end
end
end
@testitem "cdf" begin
using Distributions
x = [0:0.25:1;]
y = x
v1 = [0.0, 0.1796053020267749, 0.37796447300922725, 0.6255432421712244, 1.0]
v2 = [1.0, 0.0, 0.17157287525381, 0.5358983848622453, 1.0]
for i in 1:5
@test cdf(ClaytonCopula(2,2),[x[i],y[i]]) ≈ v1[i]
@test cdf(ClaytonCopula(2,-0.5),[x[i],y[i]]) ≈ v2[i]
end
end
@testitem "density" begin
using Distributions
using Random
n = 10^6
θ = [-0.5, 2, 10]
x = [0:0.25:1;]
y = x
v1 = [2.2965556205046926, 1.481003649342278, 1.614508582188617, 3.0]
v2 = [Inf, 2.0, 1.0, 2 / 3, 0.5]
@test isnan(pdf(ClaytonCopula(2,2), [x[1], y[1]]))
@test pdf(ClaytonCopula(2,-0.5),[x[1],y[1]]) == v2[1]
for i in 2:5
@test pdf(ClaytonCopula(2,2),[x[i],y[i]]) ≈ v1[i-1]
@test pdf(ClaytonCopula(2,-0.5),[x[i],y[i]]) ≈ v2[i]
end
end