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

Add Frank copula #16

Merged
merged 13 commits into from
Dec 20, 2023
Merged

Add Frank copula #16

merged 13 commits into from
Dec 20, 2023

Conversation

FriesischScott
Copy link
Contributor

@FriesischScott FriesischScott commented Jan 24, 2023

This PR will add the Frank copula in line with the previously defined interface for archimedean copulas. It also fixes some issues there were with the Clayton copula. I changed the naming conventions for the derivatives to make them easier to read and write.

I removed the extension of the Clayton copula to negative parameters. According to Dependence modeling with copulas (Harry Joe) the extension to negative dependence is not supported in all of [0,1]^d and therefore not useful for statistical modeling. While sampling would work as is, the cdf and density functions aren't well defined for negative dependence. Thoughts?

Also adds tests for groundedness, uniform margins and 2-increasingness as well as a few tests for generator limits.

New dependencies are GSL for the debye function and Roots. Since there is no closed form solution for the inverse rosenblatt for archimedean copulas other than Clayton I am using root finding to invert the transformation. This can be quite slow for large sample sizes.

According to Dependence modeling with copulas (Harry Joe) the extension
to negative dependence is not supported in all of [0,1]^d and therefore
not useful for statistical modeling.

Also adds tests for groundedness, uniform margins and 2-increasingness.
@AnderGray
Copy link
Owner

AnderGray commented Jan 30, 2023

This looks great. Nice trick using Roots for the inverse.

When d>2, care has to be taken with parameter inputs (e.g. thinking semi positive definite with correlation mats). But we're not supporting any copulas beyond d = 2, so shouldn't be a problem for now. Unsure why cdf and density are tricky with negative dependence. Is it to do with the generators? In the previous implementation with the explicit formal for the cdfs, they were working. Could it be that the parameters to the generator are different to the copula? i.e. offset by 1?

One small comment is that the grid search test for 2-increasing could be slightly denser than 10 x 10. Perhaps 100 x 100? Otherwise happy to merge.

@FriesischScott
Copy link
Contributor Author

I'll finish this in October once I'm done with the thesis 🤞 .

A heads up though: There seems to be an issue with the frank copula in the main branch. When I tried to use it for a plot the samples did not look like they should.

@FriesischScott
Copy link
Contributor Author

For negative dependence the generator of the Clayton copulas is not strict anymore. To adapt to this, we can set the cdf to 0 for u1^(-ϑ) + u2^(-ϑ) - 1 < 0. This keeps groundedness etc. intact.

I also added a few more tests for (inverse)generators in Clayton and Frank.

This correctly returns 0.0 for the density of one of the inputs is zero
and also fixes the issue with negative dependence for the clayton
copula.

The tests were refactored and updated. I extracted the tests that work
for all copulas like grounded, 2-increasing etc..
@FriesischScott
Copy link
Contributor Author

FriesischScott commented Dec 20, 2023

@AnderGray I think this should be ready to merge now.

One thing I was thinking: Currently the derivatives of the (inverse) generators are only used for the density. We could just implement a density function for each archimedean copula instead. Which I think would be cleaner and easier to test. Not sure if we will need to derivatives for anything else later on. Thoughts?

@AnderGray AnderGray merged commit 6f5ab9a into AnderGray:main Dec 20, 2023
2 checks passed
@AnderGray
Copy link
Owner

Thanks for the PR!

I like how you've implemented it with the generators. Seems general. To add a new copula, all you would need to is add a valid generator (and it's inverse). The rest could probably be derived automatically with AD.

But yes, since we know the DFs for Clayton and Frank in closed form, it could be beneficial to just add these. It would also be good to test the generated cdf and pdf against the closed form equations.

Merged as it is for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants