CurrentModule = Copulas
This section summarizes how to fit copulas (and Sklar distributions) in Copulas.jl, without going into the details of each family.
- We work with pseudo-observations
U ∈ (0,1)^{d×n}(rows = dimension, columns = observations). You can use thepseudo()function to get such normalized ranks. - The rank routines (τ/ρ/β/γ) assume pseudo-observations.
- The
StatsBasefunctions for pairwise correlations use then×dconvention; when called internally, they are transposed (U) as appropriate.
using Copulas, Random, StatsBase, Distributions
Random.seed!(123) # hide
Ctrue = GumbelCopula(2, 3.0)
U = rand(Ctrue, 2000)
Ĉ = fit(GumbelCopula, U; method=:mle)
Ĉ
Returns only the fitted copula Ĉ::CT. This is a high-level shortcut.
using Plots
plot(Ĉ)
M = fit(CopulaModel, GumbelCopula, U; method=:default)
M
Returns a CopulaModel with:
result(the fitted copula),n,ll(log-likelihood),method,converged,iterations,elapsed_sec,vcov(if available),method_details(a named tuple with method metadata).
-
fit operates on types, not on pre-constructed parameterized instances. Always pass a Copula or SklarDist type to
fit, e.g.fit(GumbelCopula, U)orfit(CopulaModel, SklarDist{ClaytonCopula,Tuple{Normal,LogNormal}}, X). If you already have a constructed instanceC0, re-estimate its parameters by callingfit(typeof(C0), U). -
Default method selection: each family exposes the list of available fitting strategies via
_available_fitting_methods(CT, d). Whenmethod = :defaultthe first element of that tuple is used. Example:Copulas._available_fitting_methods(MyCopula, d). -
CopulaModelis the full result object returned by the fits performed viaDistributions.fit(::Type{CopulaModel}, ...). The light-weight shortcutfit(MyCopula, U)returns only a copula instance; usefit(CopulaModel, ...)to get diagnostics and metadata.
The CopulaModel{CT} <: StatsBase.StatisticalModel type stores the result and supports the standard StatsBase interface:
| Function | Description |
|---|---|
nobs(M) |
Number of observations |
loglikelihood(M) |
Log-likelihood at the optimum |
deviance(M) |
Deviance (= −2 loglikelihood) |
coef(M) |
Estimated parameters |
coefnames(M) |
Parameter names |
vcov(M) |
Var–cov matrix |
stderror(M) |
Standard errors |
confint(M) |
Confidence intervals |
aic(M) |
Akaike Information Criterion |
bic(M) |
Bayesian Information Criterion |
aicc(M) |
Corrected AIC (small-sample) |
hqc(M) |
Hannan–Quinn criterion |
By default, the returned CopulaModel contains a lot of extra statistics, that you can see by printing the model in the REPL.
- The
CopulaModelfieldvcov(exposed asStatsBase.vcov(M)) contains the estimated covariance matrix of the fitted copula parameters when available. Many families supply:vcovvia themetaNamedTuple returned by_fit(for examplemeta.vcov). Ifvcov === nothingthe package cannot computestderrororconfintand those helpers will throw.
TODO: add an example here.
Consider adding a small bootstrap wrapper for robust CIs when the Hessian is unreliable.
:ifm: fits parametric margins and projects to pseudo-data with their CDFs.:ecdf: uses pseudo-empirical observations (ranks).
Notes:
-
sklar_method=:ifmfits parametric margins first and converts observations to pseudo-scale via the fitted marginal CDFs.sklar_method=:ecdfuses empirical pseudo-observations (ranks). Choose:ifmwhen margins are believed parametric and you want a model-based projection; choose:ecdfto avoid margin misspecification. -
margins_kwargsis currently a singleNamedTupleapplied to every marginal fit. If you need different options per margin, fit margins manually (callDistributions.fitfor each marginal type) and then call the copula fit on the pseudo-data yourself. -
The model's
null_llfield (used in LR tests) is computed as the sum of the marginal logpdfs under the fitted margins; LR tests compare the fitted copula vs independence while keeping the same margins.
S = SklarDist(ClaytonCopula(2, 5), (Normal(), LogNormal(0, 0.5)))
X = rand(S, 1000)
Ŝ = fit(CopulaModel, SklarDist{ClaytonCopula,Tuple{Normal,LogNormal}}, X;
sklar_method=:ifm, # or :ecdf
copula_method=:default, # see next section.
margins_kwargs=NamedTuple(), copula_kwargs=NamedTuple()) # options will be passed down to fitting functions.
Ŝ
plot(Ŝ.result)
The names and availiability of fitting methods depends on the model. You can check what is available with the following internal call :
Copulas._available_fitting_methods(ClaytonCopula, 3)
The first method in the list is the one used by default.
:mle— Maximum likelihood overU. Recommended when there is a stable density and good reparameterization.:itau— Kendall's inverse: matches the theoreticalτ(C)with the empiricalτ(U). Ideal for single-parameter families or when a reliable monotone inverse exists.:irho— Spearman's inverse: analogous toρ; can operate with scalar or matrix objectives (e.g., multivariate Gaussians).:ibeta— Blomqvist's inverse: scalar; only works if the family has ≤ 1 free parameter.
Note: Rank-based methods require that the number of free parameters not exceed the information of the coefficient(s) used; in the case of
:ibeta, this is explicitly enforced.
In extreme value copulas, the :mle/:iupper variants can rely on the Pickands function (A(t)) and its derivatives (A, dA, d²A) with Brent-type numerical inversion.
When you add a new copula family, implement the following so the generic fit flow works seamlessly:
_example(CT, d)— return a representative instance (used to obtain default params and initial values)._unbound_params(CT, d, params)— transform the familyNamedTupleparameters to an unconstrainedVector{Float64}used by optimizers._rebound_params(CT, d, α)— invert_unbound_params, returning aNamedTuplesuitable forCT(d, ...)construction._available_fitting_methods(::Type{<:YourCopula}, d::Int)— declare supported methods (examples::mle, :itau, :irho, :ibeta, ...)._fit(::Type{<:YourCopula}, U, ::Val{:mle})(and otherVal{}methods) — implement the method and return(fitted_copula, meta::NamedTuple); include keys such as:θ̂,:optimizer,:converged,:iterationsand optionally:vcov.
Place this checklist and a minimal _fit skeleton in docs/src/manual/developer_fitting.md where contributors can copy/paste and adapt.