Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Kendall's tau for TCopula & non-archimedeans more generally #80

Closed
Tracked by #114
Santymax98 opened this issue Nov 21, 2023 · 9 comments · Fixed by #133
Closed
Tracked by #114

[Bug] Kendall's tau for TCopula & non-archimedeans more generally #80

Santymax98 opened this issue Nov 21, 2023 · 9 comments · Fixed by #133
Assignees
Labels
bug Something isn't working

Comments

@Santymax98
Copy link
Contributor

Santymax98 commented Nov 21, 2023

Hello, when I try to calculate the kendal tau of any copula, it appears that it is not defined
`julia> Σ = [1.0 0.8; 0.8 1.0]
2×2 Matrix{Float64}:
1.0 0.8
0.8 1.0

julia> Cop = GaussianCopula(Σ)
GaussianCopula{2, Matrix{Float64}}(
Σ: [1.0 0.8; 0.8 1.0]
)

julia> τ(Cop)
ERROR: UndefVarError: τ not defined
Stacktrace:
[1] top-level scope
@ REPL[7]:1`

@lrnv
Copy link
Owner

lrnv commented Nov 21, 2023

Indeed it is not. There is no default implementation, the archimedean copulas have their implementation but the elliptical ones have none.

Do you want to provide a default implementation ? As $\tau(C) = 4 * Expectation (C(U)) - 1$ for $U \sim C$ ? You may use Distributions.expectation() as is done at several other places in the package.

PS : For the gaussian and elliptical copula, there are some known formulas right ? Maybe implementing those would be better.

@lrnv lrnv added the enhancement New feature or request label Nov 21, 2023
@Santymax98
Copy link
Contributor Author

Does it mean that I can't calculate Kendall's tau for an Archimedean copula either?

`julia> C = ClaytonCopula(2,1.5)
ClaytonCopula{2, Float64}(θ=1.5)

julia> τ(C)
ERROR: UndefVarError: τ not defined
Stacktrace:
[1] top-level scope
@ REPL[10]:1

julia> `

@lrnv
Copy link
Owner

lrnv commented Nov 21, 2023

The function exists but is not exported yet :

julia> using Copulas

julia> C = ClaytonCopula(2,10)
ClaytonCopula{2, Int64}(
G: Copulas.ClaytonGenerator{Int64}(10)
)


julia> Copulas.τ(C)
0.8333333333333334

julia> τ(C)
ERROR: UndefVarError: `τ` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

julia> 

Btw you might want to upgrade to 0.1.19 since we fixed a lot of bugs recently.

We could make this public API by exporting the function, but since it is not implemented for all copulas I am not sure it is a good idea yet. If we have an implementation for ALL copulas, then yes we might export it :)

@lrnv
Copy link
Owner

lrnv commented Nov 21, 2023

Btw in fact it already works for the gaussian :

julia> C = GaussianCopula([1 0.5; 0.5 1])
GaussianCopula{2, Matrix{Float64}}(
Σ: [1.0 0.5; 0.5 1.0]
)


julia> Copulas.τ(C)
0.16834795498215338

julia> 

@Santymax98
Copy link
Contributor Author

Santymax98 commented Nov 21, 2023

Now I got it, however, what copulas is it missing for? It would be good to implement it together with Sperman's Rho

@lrnv
Copy link
Owner

lrnv commented Nov 21, 2023

The implementation is there :

Copulas.jl/src/Copula.jl

Lines 24 to 35 in d7cf205

function ρ(C::Copula{d}) where d
F(x) = Distributions.cdf(C,x)
z = zeros(d)
i = ones(d)
r = Cubature.pcubature(F,z,i,reltop=sqrt(eps()))[1]
return 12*r-3
end
function τ(C::Copula)
F(x) = Distributions.cdf(C,x)
r = Distributions.expectation(F,C)
return 4*r-1
end

But it is not well tested for the moment. What we could do is add some tests.

@Santymax98
Copy link
Contributor Author

Santymax98 commented Nov 21, 2023

I understand, that function is general. At least for now it can be used. You could try the copula T, I think it is giving some Nan values

`julia> Copa=TCopula(4,Σ)
TCopula{2, 4, Matrix{Float64}}(
Σ: [1.0 0.8; 0.8 1.0]
)

julia> Copulas.τ(Copa)
NaN`

@lrnv
Copy link
Owner

lrnv commented Nov 21, 2023

Yes, and also spearman's rho does not work on this one too. THis is indeed something that should be fixed if we want to export these functions and make them public API.

@lrnv lrnv added bug Something isn't working and removed enhancement New feature or request labels Nov 21, 2023
@Santymax98
Copy link
Contributor Author

Understood, thank you very much for the suggestion and for answering the Issue.

@lrnv lrnv changed the title Kendall's tau [Bug] Kendall's tau for TCopula & non-archimedeans more generally Feb 7, 2024
@lrnv lrnv mentioned this issue Feb 7, 2024
27 tasks
@lrnv lrnv self-assigned this Feb 9, 2024
@lrnv lrnv closed this as completed in #133 Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants