copula_fit
copula_fit(family, x, y, method='mpl', margin_x=None, margin_y=None)Fit a bivariate copula to data.
Estimate a copula’s dependence parameter(s) – and, when a marginal names a family without parameters, that marginal’s own parameters – from a paired sample. Mirrors the C# BivariateCopulaEstimation methods of the Numerics library.
x and y are the raw paired observations for every method. method="mpl" maximizes the pseudo-likelihood, which is defined on the plotting positions rank / (n + 1) rather than on the data scale; that transform happens inside the shared C++ core, so R and Python fit the same numbers from the same input.
margin_x and margin_y accept EITHER a family-name string or a :class:Distribution, and the two are handled differently:
- a name (e.g.
margin_x="Normal") is fitted by maximum likelihood tox(ory) before the copula is estimated. This is what Inference From Margins (method="ifm") requires, and it is accepted for"ifm"and"mle"only:"mpl"and"tau"ignore the marginals entirely, so a name there would be reported back unfitted – passing one raises. - a :class:
Distribution(e.g.margin_x=Distribution("Normal", [0, 1])) is accepted for all four methods."mpl"and"tau"attach it untouched (so :meth:Copula.randomcan draw on the data scale),"ifm"takes it as the given margin, and"mle"re-estimates it jointly with theta.
method="tau" inverts Kendall’s tau into theta directly and is only implemented upstream for Clayton, Gumbel, and AliMikhailHaq (SetThetaFromTau); it raises for every other family.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| family | str | One of :func:copula_names. |
required |
| x | array-like of float | Raw paired observations, the same length. | required |
| y | array-like of float | Raw paired observations, the same length. | required |
| method | ('mpl', 'ifm', 'mle', 'tau') | "mpl" (maximum pseudo-likelihood), "ifm" (inference from margins), "mle" (full maximum likelihood), or "tau" (Kendall’s tau inversion; Clayton, Gumbel, and AliMikhailHaq only). |
"mpl" |
| margin_x | str or Distribution | Optional marginals; see Notes above. | None |
| margin_y | str or Distribution | Optional marginals; see Notes above. | None |
Returns
| Name | Type | Description |
|---|---|---|
| Copula | The fitted copula. |
Examples
>>> x = [135.9, 104.1, 108.7, 99.3, 134.7, 91.0, 77.3, 115.4, 109.0, 79.0]
>>> y = [1.9, 1.3, 1.4, 1.2, 1.8, 1.1, 0.9, 1.5, 1.4, 1.0]
>>> copula_fit("Clayton", x, y, method="mpl").theta > 0
True