Repository navigation
Description
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
[-]EMH/Design empirical copula, multivariate ECDF[/-][+]ENH/Design empirical copula, multivariate ECDF[/+]josef-pkt commentedon May 23, 2021
We need rvs for empirical Beta copula. That might be the easiest method to implement of empirical Beta copula.
statsmodels.distributions.bernstein.rvshas 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
josef-pkt commentedon May 24, 2021
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 / nobswhere nobs is of sample.This can be used for interpretation, e.g. I used
5 /nobsor other multiples of 1 / nobs.1 / nobsis 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 +1in first beta parameterjosef-pkt commentedon Jul 26, 2021
Part of this has been merged with copulas #7408
josef-pkt commentedon Jan 30, 2023
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)