Skip to content

ENH/Design empirical copula, multivariate ECDF #7454

Open

Description

@josef-pkt

similar to #7445 histogram copula

What should be the design for an empirical multivariate distribution or empirical copula.

Currently, WIP in #7408, I have written a ECDF function with some speedup in the bivariate case.
In unit tests, I use bin probabilities instead of densities, similarly to what I needed for Bernstein.

Currently, I have Bernstein smoothed empirical copula based on grid probabilites. This could be complemented by empirical Beta copulas, i.e. bi- or multivariate version of Beta KDE (PR #7364 merged).

Looking at docs for R package copBasic (AFAIU, and a few simple examples with it):
EMPIRcop evaluates empirical copula (ECDF) at new point u, v (returns float/numeric)
EMPIRcopdf (read EMPIRcop_df ) creates data frame for copula cdf of sample points (similar to what I have as ECDF)
EMPIRgrid creates a grid of cdf values, based on empirical copula, I guess, using EMPIRcop, mainly used for plotting

AFAICS, there is no sharing of intermediate results, i.e. all functions compute directly from data.
plotting positions (rank - 0.5) / nobs or rank / (nobs + 1) seems to be only partially included in functions.
focus seems to be on density, not bin probabilities (at least for plotting)

EMPIRcop has an empirical Bernstein copula option, but not sure how that is defined.

Note on usage:

  • minimal distance estimation of copula parameters is not as good as MLE. at least without outliers.
  • currently I have unit test based on chisquare test with binned probabilities, and contour plot based of bin probabilities (unscaled but same shape as pdf on regular grid with constant grid size delta u.)
  • overlapping code with setup of Bernstein distribution ? and histogram copuls/distribution
  • simulation:
    • empirical distribution on support of observations
    • histogram distribution, local linear pdf within bins / grid intervals/ hyper cubes
    • smoothed: Bernstein or Beta KDE (on fixed grid or observations respectively)

aside: working on grid does not give a copula and uniform margins if nobs is not a multiple of the number of bins.
We could drop observation to have even bin counts on regular grid, or use new helper function to find a close distribution that has uniform margins.

Activity

  1. changed the title [-]EMH/Design empirical copula, multivariate ECDF[/-] [+]ENH/Design empirical copula, multivariate ECDF[/+] on May 19, 2021
  2. josef-pkt commented on May 23, 2021

    @josef-pkt
    MemberAuthor

    We need rvs for empirical Beta copula. That might be the easiest method to implement of empirical Beta copula.

    statsmodels.distributions.bernstein.rvs has the pattern for it, That method is a bit stingy in comments explaining what the code does. also no reference in docstring. I don't see a reference in any of the docstrings for Bernstein.

    For empirical copula/distribution we don't use the (mesh) grid. I guess we just work with the observations (nobs, k_vars), i.e. unsorted flat representation.
    (computationally, I'm not sure using multinomial counts will help us much in large samples, because there will not be a large number of repeat cells. maybe simple vectorizing, uniform bin cells draws plus beta draws, might be faster.)

    aside: rvs for univariate asymmetric kernels has not been merged yet #7375, available only in notebook?
    we should get at least the working cases merged, e.g. Beta kernel in analogy to beta copula

  3. josef-pkt commented on May 24, 2021

    @josef-pkt
    MemberAuthor

    just an observations: beta and bernstein kde (over)smooth peaks, this extends to multivariate case.

    In the bivariate case this can be a ridge instead of a peak, e.g. if there is high correlation between variables, then observations will be around diagonal. Kde smooths weight away from the diagonal, Conditional on observations we use product kernel, i.e. locally independent sampling.

    Note on bandwidth: KST don't have explicit bandwidth. It is set to bw = 1 / nobs where nobs is of sample.
    This can be used for interpretation, e.g. I used 5 /nobs or other multiples of 1 / nobs. 1 / nobs is the average distance between observations and equal to marginal distance in ranks (slightly modified by plotting positions)

    my current draft version, KST don't have a +1 in first beta parameter

    # from notebook adjusted for beta
    def rvs_kernel(sample, bw, size):
        n = sample.shape[0]
        nobs = size
        kfunc = kernel_rvs_beta
        krvs = []
        for _ in range(nobs):
            xi = sample[np.random.randint(0, n)]
            krvs.append(np.asarray([kfunc(xii, bw) for xii in xi]))
    
        return np.asarray(krvs)
    
    
    def kernel_rvs_beta(x, bw):
        # Beta kernel for density, pdf, estimation
        return stats.beta.rvs(x / bw + 1, (1 - x) / bw + 1)
    
    def kernel_rvs_beta1(x, bw):
        # Beta kernel for density, pdf, estimation
        # Kiriliouk, Segers, Tsukuhara 2020 arxiv, using bandwith 1/nobs sample
        return stats.beta.rvs(x / bw, (1 - x) / bw + 1)
    
  4. josef-pkt commented on Jul 26, 2021

    @josef-pkt
    MemberAuthor

    Part of this has been merged with copulas #7408

  5. josef-pkt commented on Jan 30, 2023

    @josef-pkt
    MemberAuthor

    I don't remember whether I put this somewhere (maybe for bernstein or histogram copula)

    Prob in a hypercube (a_1 < b1, ..., a_d < b_d) of a multivariate cdf or copula
    joe 2014 copula book p. 27 equ (2.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions