Skip to content

Add automatic copula family selection - #436

Open
Santymax98 wants to merge 1 commit into
lrnv:mainfrom
Santymax98:automatic-copula-selection
Open

Add automatic copula family selection#436
Santymax98 wants to merge 1 commit into
lrnv:mainfrom
Santymax98:automatic-copula-selection

Conversation

@Santymax98

Copy link
Copy Markdown
Contributor

Hi Oskar,

This is the other independent part I mentioned in #435.

I originally developed the hypothesis-testing framework and automatic family selection together, but I think separating them makes the API much easier to review. This PR does not depend on #435, so either one can be merged first.

The idea here is to allow family selection directly through the existing fitting interface:

M = fit(CopulaModel, Copula, U; candidates=(ClaytonCopula, GumbelCopula, FrankCopula), criterion=:bic,)

Instead of introducing a separate model-selection object or fitting abstraction, Copula acts as the request to compare candidate families using the same CopulaModel machinery that is already available.

The supported criteria are:

  • BIC,
  • AIC,
  • AICc,
  • HQC.

The candidate fits are evaluated first without the additional inference cost, the best eligible family is selected according to the requested criterion, and the winning family is then fitted normally with the options requested by the user.

The returned object is still a regular CopulaModel, with the additional selection metadata stored in method_details.

The complete comparison can be inspected with:

selectiontable(M)

which keeps the candidate family, fitting method, convergence/status information, log-likelihood, number of parameters, and the information criteria for each candidate.

There are also two built-in candidate collections:

candidates=:default
candidates=:all

while an explicit tuple can be used when only a scientifically meaningful subset of families should be considered.

I think this is also a nice example of extending the existing fitting API without introducing another parallel interface: the result still behaves exactly like any other CopulaModel.

There is one particularly interesting connection with #435 that I intentionally left out of both PRs.

Once #435 and this PR are merged, a small follow-up could implement goodness-of-fit after model selection. We already had this case in the combined implementation, roughly:

M = fit(CopulaModel, Copula, U; candidates=(ClaytonCopula, GumbelCopula, FrankCopula), criterion=:bic,)

T = GOFCopulaTest(M)

The important point is that this is not the same as ordinary composite GOF. Under automatic model selection, each parametric-bootstrap replicate should reproduce the complete procedure:

simulate from fitted model
        ↓
run family selection again
        ↓
fit the selected family
        ↓
compute the GOF statistic

So that follow-up would be a concrete example of the two APIs composing naturally: this PR provides the model-selection procedure, while #435 provides the hypothesis/statistic/calibration framework.

I left that integration out intentionally so both APIs can be reviewed independently first. If both are merged, I can send the selection-aware GOF part as a much smaller follow-up PR.

And no rush with this one either — especially with #434 and #435 already on your plate :)

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.98%. Comparing base (ad60873) to head (74a559c).

Files with missing lines Patch % Lines
src/Fitting.jl 75.38% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #436      +/-   ##
==========================================
+ Coverage   86.07%   86.98%   +0.90%     
==========================================
  Files          91       91              
  Lines        7764     7852      +88     
==========================================
+ Hits         6683     6830     +147     
+ Misses       1081     1022      -59     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Santymax98

Copy link
Copy Markdown
Contributor Author

I think this PR should be revisited once #435 is resolved and merged.

Since the fitting/test infrastructure has changed on current main, and #435 introduces the GOF framework that will eventually interact with automatic model selection, it probably makes more sense to rebase and review this PR afterwards rather than update it twice.

I’ll back to it once #435 is settled.

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.

1 participant