Skip to content

ENH/BUG: archimedean k_dim > 2, deriv inverse in generator transform - #8633

Merged
josef-pkt merged 5 commits into
statsmodels:mainfrom
josef-pkt:copula_archim_dim
Jan 29, 2023
Merged

josef-pkt merged 5 commits into
statsmodels:mainfrom
josef-pkt:copula_archim_dim

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Jan 25, 2023 •

Copy link
Copy Markdown
Member

see #8631
pr will close bug, but maybe not add full extension to k_dim > 3

I will not implement k_dim > 4 for Frank and Gumbel for 0.14.
Main open question is how to vectorize the special functions. We need our own functions for polylog and sterling numbers and those are not vectorized.

Also, I'm not fixing other methods, e.g. rvs raises if k_dim != 2. I don't know how to do those.

This includes, or will include

  • bugfixes in cdf for k_dim > 2 of Clayton, explicit formula
  • generic pdf for k_dim=2 also uses deriv2_inverse instead of inverting from deriv, deriv2
  • explicit 3rd and 4th derivative of generator inverse transforms, Clayton, Frank and Gumbel
  • analytical kth derivative of generator inverse transforms for Clayton
  • todo: pdf for k_dim > 2 will for now delegate to generic archimedean using generator derivatives

still todo:
make sure we raise on cases not covered by code
adjust unit tests for copula distribution with k_dim > 2 (not checked yet)

wishlist

  • conditional distribution of one component given other or preceding components. It should be possible to compute them using the generator derivatives, but I don't remember details, and don't find references for the details. Some time in the future.

@josef-pkt josef-pkt added this to the 0.14 milestone Jan 25, 2023
@josef-pkt josef-pkt added comp-distributions type-bug type-bug-wrong serious bugs that silently return incorrect numbers labels Jan 25, 2023
@josef-pkt

josef-pkt commented Jan 26, 2023 •

Copy link
Copy Markdown
Member Author

shape inconsistency across classes
I guess inconsistent use of np.asarray(u) and np.atleast_2d
I don't remember why specific archimedean class have u = np.atleast_2d(u) in the methods.
It doesn't seem to be needed as long as we use axis=-1 in reduction operations

cdf1 is from generic ArchimedeanCopula with generator
cdf3 is from explicit copula class

same behavior for CopulaDistribution with the two copula instances

-> assert cdf3.shape == ()
(Pdb) cdf1, cdf3
(0.47108051078522245, array([0.47108051]))

@josef-pkt

josef-pkt commented Jan 26, 2023 •

Copy link
Copy Markdown
Member Author

disadvantage of requiring k_dim in __init__ and checking that u in methods is consistent with it:

Using copulas with different k_dim requires that we recreate a copula instance.
A generic function would need to take different __init__ args or keywords into account. ArchimedeanCopula requires generator transform, specific copulas do not.

This happens in a unit test, where we want to create evaluate the copula cdf for k_dim + 1
at end of unit test test_copulas_distr

# check mv, check at marginal cdf
cdfmv = ca.cdf(list(u) + [1], args=args)

maybe add _init_keys similar to models.
We will also need it if we create marginal or conditional copulas or mv distributions.

"Standard" cloning, creating new model or CopulaDistribution will not be affected as long as k_dim is unchanged. In that case we can reuse the given copula instance.

@josef-pkt

Copy link
Copy Markdown
Member Author

this should be as far as I go here

I added _special functions without unit tests

@josef-pkt
josef-pkt merged commit bc32b6f into statsmodels:main Jan 29, 2023
@josef-pkt josef-pkt mentioned this pull request Feb 3, 2023
16 of 20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-distributions type-bug type-bug-wrong serious bugs that silently return incorrect numbers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants