Marginal Copula

class copulae.marginal.MarginalCopula(copula, margins)[source]

MarginalCopula enables users to specify different marginal distributions for a given dependency structure. For example, we could have a 2D Gaussian Copula but have the Student and exponential marginals.

Examples

>>> from copulae.datasets import load_marginal_data
>>> from copulae import GaussianCopula, MarginalCopula
>>> data = load_marginal_data()
>>> cop = MarginalCopula(GaussianCopula(3), [
...     {"type": "t"},
...     {"type": "norm"},
...     {"type": "exp"}
... ])
>>> cop.fit(data)
>>> cop.summary()
Marginal Copula Summary
================================================================================
Marginal Copula with 3 dimensions
Marginal Parameters
-------------------
Dist Type: t
    df: 15.457419183265923
    loc: -0.02197911363613804
    scale: 0.9875829850778358
Dist Type: norm
    loc: 3.0026994935016047
    scale: 0.40913830848310995
Dist Type: expon
    loc: 5.9475127982985763e-05
    scale: 0.4841057217117129
================================================================================
Inner Joint Copula Parameter
----------------------------
Gaussian Copula Summary
================================================================================
Gaussian Copula with 3 dimensions
Parameters
  • Matrix (Correlation) –

  • 0.259487 0.404228 (1.000000) –

  • 1.000000 0.178879 (0.259487) –

  • 0.178879 1.000000 (0.404228) – Fit Summary

Log. Likelihood : -379.64857752263424 Variance Estimate : Not Implemented Yet Method : Maximum pseudo-likelihood Data Points : 3000 Optimization Setup ——————————————————————————–

bounds : [(-1.000001, 1.000001), (-1.000001, 1.000001), (-1.000001, 1.000001)] options : {‘maxiter’: 20000, ‘ftol’: 1e-06, ‘iprint’: 1, ‘disp’: False, ‘eps’: 1.5e-08} method : SLSQP

x : [0.25948651 0.40422775 0.17887947] fun : -379.64857752263424 jac : [-0.00197815 -0.00209942 0.00335376] nit : 6 nfev : 32 njev : 6 status : 0 message : Optimization terminated successfully success : True

bounds()[source]

Bounds is not implemented for the MarginalCopula

property dim

Number of dimensions in copula

fit(data, x0=None, method='ml', verbose=1, optim_options=None, ties='average', **kwargs)[source]

Fit the copula with specified data

Parameters
  • data (ndarray) – Array of data used to fit copula. Usually, data should be the pseudo observations

  • x0 (ndarray) – Initial starting point. If value is None, best starting point will be estimated

  • method ({ 'ml', 'irho', 'itau' }, optional) – Method of fitting. Supported methods are: ‘ml’ - Maximum Likelihood, ‘irho’ - Inverse Spearman Rho, ‘itau’ - Inverse Kendall Tau

  • optim_options (dict, optional) – Keyword arguments to pass into scipy.optimize.minimize()

  • ties ({ 'average', 'min', 'max', 'dense', 'ordinal' }, optional) – Specifies how ranks should be computed if there are ties in any of the coordinate samples. This is effective only if the data has not been converted to its pseudo observations form

  • verbose (int, optional) – Log level for the estimator. The higher the number, the more verbose it is. 0 prints nothing.

  • kwargs – Other keyword arguments. See Notes for more details

Notes

Other valid keyword arguments and their purpose

scale

Amount to scale the objective function value of the numerical optimizer. This is helpful in achieving higher accuracy as it increases the sensitivity of the optimizer. The downside is that the optimizer could likely run longer as a result. Defaults to 1.

See also

scipy.optimize.minimize

the scipy minimize function use for optimization

log_lik(data, *, to_pobs=True, ties='average')

Returns the log likelihood (LL) of the copula given the data.

The greater the LL (closer to \(\infty\)) the better.

Parameters
  • data (ndarray) – Data set used to calculate the log likelihood

  • to_pobs – If True, converts the data input to pseudo observations.

  • ties (Literal[‘average’, ‘min’, ‘max’, ‘dense’, ‘ordinal’]) – Specifies how ranks should be computed if there are ties in any of the coordinate samples. This is effective only if to_pobs is True.

Returns

Log Likelihood

Return type

float

property params

The parameter set which describes the copula

static pobs(data, ties='average')

Compute the pseudo-observations for the given data matrix

Parameters
  • data ({ array_like, DataFrame }) – Random variates to be converted to pseudo-observations

  • ties ({ 'average', 'min', 'max', 'dense', 'ordinal' }, optional) – Specifies how ranks should be computed if there are ties in any of the coordinate samples

Returns

matrix or vector of the same dimension as data containing the pseudo observations

Return type

ndarray

See also

pseudo_obs()

The pseudo-observations function

summary()[source]

Constructs the summary information about the copula