Bicop class
A class for bivariate copula models.
The model is fully characterized by the family, rotation (one of 0, 90, 180, 270), a matrix of parameters, and variable types (two strings, one for each variable, either "c" for continuous or "d" for discrete).
Implemented families (see BicopFamily):
| type | full name | string identifier | |---------------|-----------------------|-----------------------| | - | Independence | "indep" | | Elliptical | Gaussian | "gaussian" | | | Student t | "student" | | Archimedean | Clayton | "clayton" | | | Gumbel | "gumbel" | | | Frank | "frank" | | | Joe | "joe" | | | Clayton-Gumbel (BB1) | "bb1" | | | Joe-Gumbel (BB6) | "bb6" | | | Joe-Clayton (BB7) | "bb7" | | | Joe-Frank (BB8) | "bb8" | | Extreme-Value | Tawn | "tawn" | | Nonparametric | Transformation kernel | "tll" |
Public types
- struct ScoresResult
- Bundles the per-observation scores.
Constructors, destructors, conversion operators
-
Bicop(const BicopFamily family = BicopFamily::
indep, const int rotation = 0, const Eigen::MatrixXd& parameters = Eigen::MatrixXd(), const std::vector<std::string>& var_types = { "c", "c" }) - Instantiates a specific bivariate copula model.
- Bicop(const Eigen::MatrixXd& u, const FitControlsBicop& controls = FitControlsBicop(), const std::vector<std::string>& var_types = { "c", "c" }) explicit
- Instantiates from data.
- Bicop(const Bicop& other)
- Copy constructor (deep copy)
- Bicop(Bicop&& other) defaulted
- Bicop(const std::string& filename) explicit
- Instantiates from a JSON or CBOR file.
- Bicop(const nlohmann::json& input) explicit
- Instantiates from a
nlohmann::jsonobject.
Public functions
- auto operator=(Bicop other) -> Bicop&
- Copy assignment operator (deep copy)
- auto to_json() const -> nlohmann::json
- Convert the copula into a nlohmann::json object.
- auto to_file(const std::string& filename) const -> void
- Writes the copula object into a JSON or CBOR file.
- auto get_npars() const -> double
- The number of parameters of the copula model.
-
auto simulate(const size_
t& n, const bool qrng = false, const std::vector<int>& seeds = std::vector<int>()) const -> Eigen::MatrixXd - Simulates from a bivariate copula.
-
auto simulate(const Eigen::MatrixXd& parameters,
const bool qrng = false,
const std::vector<int>& seeds = std::vector<int>(),
const size_
t num_threads = 1) const -> Eigen::MatrixXd - Simulates from a bivariate copula with per-row parameters.
- auto fit(const Eigen::MatrixXd& u, const FitControlsBicop& controls = FitControlsBicop()) -> void
- Fits a bivariate copula (with fixed family) to data.
- auto select(const Eigen::MatrixXd& u, FitControlsBicop controls = FitControlsBicop()) -> void
- Selects the best fitting model.
- auto loglik(const Eigen::MatrixXd& u = Eigen::MatrixXd()) const -> double
- Evaluates the log-likelihood.
- auto aic(const Eigen::MatrixXd& u = Eigen::MatrixXd()) const -> double
- Evaluates the Akaike information criterion (AIC).
- auto bic(const Eigen::MatrixXd& u = Eigen::MatrixXd()) const -> double
- Evaluates the Bayesian information criterion (BIC).
- auto mbic(const Eigen::MatrixXd& u = Eigen::MatrixXd(), const double psi0 = 0.9) const -> double
- Evaluates the modified Bayesian information criterion (mBIC).
- auto parameters_to_tau(const Eigen::MatrixXd& parameters) const -> double
- Converts the copula parameters to Kendall's .
- auto parameters_to_taildep(const Eigen::MatrixXd& parameters) const -> Eigen::MatrixXd
- Converts the copula parameters to the tail dependence coefficients.
- auto parameters_to_beta(const Eigen::MatrixXd& parameters) const -> double
- Converts the copula parameters to Blomqvist's .
- auto tau_to_parameters(const double& tau) const -> Eigen::MatrixXd
- Converts a Kendall's into copula parameters for one-parameter families.
- auto with_var_types(const std::vector<std::string>& var_types = { "c", "c" }) const -> Bicop
- The same copula under different variable types.
Getters and setters
- auto get_family() const -> BicopFamily
- Gets the copula family.
- auto get_family_name() const -> std::string
- Gets the copula family as a string.
- auto get_rotation() const -> int
- Gets the rotation.
- auto get_parameters() const -> Eigen::MatrixXd
- Gets the parameters.
- auto get_tau() const -> double
- Gets the Kendall's tau.
- auto get_taildep() const -> Eigen::MatrixXd
- Gets the tail dependence coefficients.
- auto get_beta() const -> double
- Gets Blomqvist's beta.
- auto get_loglik() const -> double
- Gets the log-likelihood (only for fitted objects).
-
auto get_nobs() const -> size_
t - Gets the number of observations (only for fitted objects).
- auto get_aic() const -> double
- Gets the aic (only for fitted objects).
- auto get_bic() const -> double
- Gets the bic (only for fitted objects).
- auto get_mbic(const double psi0 = 0.9) const -> double
- Gets the modified bic (only for fitted objects).
- auto set_rotation(const int rotation) -> void
- Sets the rotation.
- auto set_parameters(const Eigen::MatrixXd& parameters) -> void
- auto set_var_types(const std::vector<std::string>& var_types = { "c", "c" }) -> void
- Sets variable types.
- auto get_var_types() const -> std::vector<std::string>
- Gets variable types.
Stats methods
These evaluate the copula at the object's stored parameters. See below for the overloads taking one parameter set per row.
- auto pdf(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the copula density.
- auto cdf(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the copula distribution.
- auto hfunc1(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the first h-function.
- auto hfunc2(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the second h-function.
- auto hinv1(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the inverse of the first h-function.
- auto hinv2(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the inverse of the second h-function.
Stats methods with per-row parameters
These overloads evaluate the copula at a different parameter set per row of u, in a single call, without mutating the object's stored parameters. The family, rotation, and variable types are taken from the object; only the parameter values vary by row. They are available for parametric families only (nonparametric families store an interpolation grid rather than a per-observation parameter vector).
Common arguments:
u: an matrix for a continuous model. For a model withkdiscrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables).parameters: an matrix, wherepis the number of family parameters (get_) and rowparameters().size() iholds the parameter set used for rowiofu. Parameters are given in the family's natural (unrotated) parameterization, as forget_.parameters() num_threads: the number of threads to parallelize over rows.
-
auto pdf(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the copula density with per-row parameters.
-
auto cdf(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the copula distribution with per-row parameters.
-
auto hfunc1(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the first h-function with per-row parameters.
-
auto hfunc2(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the second h-function with per-row parameters.
-
auto hinv1(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the inverse of the first h-function with per-row parameters.
-
auto hinv2(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the inverse of the second h-function with per-row parameters.
-
auto loglik(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> double - Evaluates the log-likelihood contributions with per-row parameters and returns their sum (NaNs are ignored).
Derivatives of the density and h-functions
These methods evaluate partial derivatives of the copula density , its logarithm, and the h-functions with respect to the parameters and/or the arguments. The derivative is chosen by the selector deriv, a concatenation of the components "par1", "par2", ... (the k-th parameter, in the family's natural parameterization as returned by get_), "u1", and "u2". First-order methods take one component ("par" is short for "par1"); second-order methods take two in any order (a single component means differentiating twice, so "par" is short for "par1par1").
Rotations are handled internally via the chain rule, so derivatives are always w.r.t. the arguments and (positive, natural) parameters of the rotated copula. Closed-form expressions are used for the families in bicop_families::; other parametric families fall back to central finite differences of the corresponding function. Derivatives require continuous variable types; nonparametric families throw.
The per-row-parameter overloads evaluate the derivative at a different parameter set per row of u (see the corresponding pdf() overload for the layout and validation rules).
Common arguments: u is an matrix of observations in and deriv selects the derivative; each method returns a length-n vector evaluated at u.
- auto pdf_deriv(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a first derivative of the copula density.
- auto pdf_deriv2(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a second derivative of the copula density.
- auto hfunc1_deriv(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a first derivative of the first h-function .
- auto hfunc1_deriv2(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a second derivative of the first h-function.
- auto hfunc2_deriv(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a first derivative of the second h-function .
- auto hfunc2_deriv2(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a second derivative of the second h-function.
- auto logpdf_deriv(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a first derivative of the log-density .
- auto logpdf_deriv2(const Eigen::MatrixXd& u, const std::string& deriv) const -> Eigen::VectorXd
- Evaluates a second derivative of the log-density.
-
auto pdf_deriv(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a first derivative of the copula density with per-row parameters.
-
auto pdf_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a second derivative of the copula density with per-row parameters.
-
auto hfunc1_deriv(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a first derivative of the first h-function with per-row parameters.
-
auto hfunc1_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a second derivative of the first h-function with per-row parameters.
-
auto hfunc2_deriv(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a first derivative of the second h-function with per-row parameters.
-
auto hfunc2_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a second derivative of the second h-function with per-row parameters.
-
auto logpdf_deriv(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a first derivative of the log-density with per-row parameters.
-
auto logpdf_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates a second derivative of the log-density with per-row parameters.
Scores, gradient, and Hessian of the log-likelihood
These methods aggregate the log-density parameter derivatives into the score (the gradient of each observation's log-density contribution), its observation-average (gradient), and the Hessian. They are thin wrappers around logpdf_ / logpdf_: with p = get_ parameters, the score of observation i w.r.t. parameter k is , and the (per-obs and averaged) Hessians collect the second log-density derivatives. Like the derivatives they build on, they require parametric families and continuous variable types; nonparametric or discrete models throw.
The per-row-parameter overloads evaluate at a different parameter set per row of u (see the corresponding pdf() overload for the layout and validation rules).
In every method here, u is an matrix of observations in .
- auto scores(const Eigen::MatrixXd& u) const -> Eigen::MatrixXd
- Evaluates the per-observation scores.
- auto gradient(const Eigen::MatrixXd& u) const -> Eigen::VectorXd
- Evaluates the gradient of the average log-likelihood.
- auto hessian(const Eigen::MatrixXd& u) const -> Eigen::MatrixXd
- Evaluates the Hessian of the average log-likelihood.
- auto hessian_full(const Eigen::MatrixXd& u) const -> std::vector<Eigen::MatrixXd>
- Evaluates the per-observation Hessians.
- auto scores_cov(const Eigen::MatrixXd& u) const -> Eigen::MatrixXd
- Computes the covariance matrix of the scores.
- auto scores_full(const Eigen::MatrixXd& u) const -> ScoresResult
- Evaluates the scores, bundled in a
ScoresResult. -
auto scores(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::MatrixXd - Evaluates the per-observation scores with per-row parameters.
-
auto gradient(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the gradient of the average log-likelihood with per-row parameters.
-
auto hessian(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::MatrixXd - Evaluates the Hessian of the average log-likelihood with per-row parameters.
-
auto hessian_full(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> std::vector<Eigen::MatrixXd> - Evaluates the per-observation Hessians with per-row parameters.
-
auto scores_cov(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::MatrixXd - Computes the covariance matrix of the scores with per-row parameters.
-
auto scores_full(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> ScoresResult - Evaluates the scores with per-row parameters, bundled in a
ScoresResult.
Utilities
useful functions for bivariate copulas
- auto str() const -> std::string
- Summarizes the model into a string (can be used for printing).
- auto flip() -> void
- Adjusts the copula model to a change in the variable order.
- auto get_parameters_lower_bounds() const -> Eigen::MatrixXd
- Gets lower bounds for copula parameters.
- auto get_parameters_upper_bounds() const -> Eigen::MatrixXd
- Gets upper bounds for copula parameters.
Function documentation
vinecopulib:: Bicop:: Bicop(const BicopFamily family = BicopFamily:: indep,
const int rotation = 0,
const Eigen::MatrixXd& parameters = Eigen::MatrixXd(),
const std::vector<std::string>& var_types = { "c", "c" })
Instantiates a specific bivariate copula model.
| Parameters | |
|---|---|
| family | The copula family. |
| rotation | The rotation of the copula; one of 0, 90, 180, or 270 (for Independence, Gaussian, Student, Frank, and nonparametric families, only 0 is allowed). |
| parameters | The copula parameters. |
| var_types | Two strings specifying the types of the variables, e.g., ("c", "d") means first variable continuous, second discrete. |
vinecopulib:: Bicop:: Bicop(const Eigen::MatrixXd& u,
const FitControlsBicop& controls = FitControlsBicop(),
const std::vector<std::string>& var_types = { "c", "c" }) explicit
Instantiates from data.
| Parameters | |
|---|---|
| u | See Bicop::. |
| controls | See Bicop::. |
| var_types | Two strings specifying the types of the variables, e.g., ("c", "d") means first variable continuous, second discrete. |
Equivalent to creating a default Bicop() and then selecting the model using Bicop::.
vinecopulib:: Bicop:: Bicop(const std::string& filename) explicit
Instantiates from a JSON or CBOR file.
| Parameters | |
|---|---|
| filename | The name of the file to read. |
Files ending in .cbor are read as CBOR. All other filenames are read as JSON for backwards compatibility. The input contains four attributes: "fam", "rot", "par", "vt" respectively a string for the family name, an integer for the rotation, and a numeric matrix for the parameters, and a list of two strings for the variable types.
nlohmann::json vinecopulib:: Bicop:: to_json() const
Convert the copula into a nlohmann::json object.
| Returns | The nlohmann::json object containing the copula. |
|---|
The nlohmann::json is contains of three values named "fam", "rot", "par", "vt", respectively a string for the family name, an integer for the rotation, a numeric matrix for the parameters and a list of two strings for the variables types.
void vinecopulib:: Bicop:: to_file(const std::string& filename) const
Writes the copula object into a JSON or CBOR file.
| Parameters | |
|---|---|
| filename | The name of the file to write. |
Filenames ending in .cbor are written as CBOR. All other filenames are written as JSON for backwards compatibility. The written representation contains four attributes: "fam", "rot", "par", "vt", "nobs", "ll", "npars" respectively a string for the family name, an integer for the rotation, and a numeric matrix for the parameters, a list of two strings for the variable types, an integer for the number of observations (if fitted), a double for the log-likelihood (if fitted), and a double for the number of parameters (can be non-integer in nonparametric models).
double vinecopulib:: Bicop:: get_npars() const
The number of parameters of the copula model.
| Returns | the number of parameters in the copula model. For nonparametric families, this is a conceptually similar effective-parameter count. |
|---|
Returns the actual number of parameters for parametric families. For nonparametric families, there is a conceptually similar definition in the sense that it can be used in the calculation of fit statistics.
Eigen::MatrixXd vinecopulib:: Bicop:: simulate(const size_ t& n,
const bool qrng = false,
const std::vector<int>& seeds = std::vector<int>()) const
Simulates from a bivariate copula.
| Parameters | |
|---|---|
| n | Number of observations. |
| qrng | Set to true for quasi-random numbers. |
| seeds | Seeds of the (quasi-)random number generator; if empty (default), the (quasi-)random number generator is seeded randomly. |
| Returns | An matrix of samples from the copula model. |
If qrng = TRUE, generalized Halton sequences are used. For more information on Generalized Halton sequences, see Faure, H., Lemieux, C. (2009). Generalized Halton Sequences in 2008: A Comparative Study. ACM-TOMACS 19(4), Article 15.
Eigen::MatrixXd vinecopulib:: Bicop:: simulate(const Eigen::MatrixXd& parameters,
const bool qrng = false,
const std::vector<int>& seeds = std::vector<int>(),
const size_ t num_threads = 1) const
Simulates from a bivariate copula with per-row parameters.
| Parameters | |
|---|---|
| parameters | An matrix of parameters, where n is the number of observations to simulate, p is the number of family parameters (get_), and row i holds the parameter set used for observation i. Parameters are given in the family's natural (unrotated) parameterization, as for get_. |
| qrng | Set to true for quasi-random numbers. |
| seeds | Seeds of the (quasi-)random number generator; if empty (default), the (quasi-)random number generator is seeded randomly. |
| num_threads | The number of threads to parallelize the simulation over observations. |
| Returns | An matrix of samples from the copula model. |
Observation i is drawn from the copula carrying row i of parameters, without mutating the object's stored parameters. The family, rotation, and variable types are taken from the object; only the parameter values vary by observation. Available for parametric families only.
void vinecopulib:: Bicop:: fit(const Eigen::MatrixXd& u,
const FitControlsBicop& controls = FitControlsBicop())
Fits a bivariate copula (with fixed family) to data.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| controls | The controls (see FitControlsBicop). |
For parametric models, two different methods are available. "mle" fits the parameters by maximum-likelihood. "itau" uses inversion of Kendall's , but is only available for one-parameter families and the Student t copula. For the latter, there is a one-to-one transformation for the first parameter, the second is found by profile likelihood optimization (with accuracy of at least 0.5). Nonparametric families have specialized methods, no specification is required.
When at least one variable is discrete, two types of "observations" are required: the first block contains realizations of . Let denote the number of discrete variables (either one or two). The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For continuous variables the left limit and the cdf itself coincide, and their columns can be omitted from the second block. For, e.g., an integer-valued variable, it holds .
Incomplete observations (i.e., ones with a NaN value) are discarded.
void vinecopulib:: Bicop:: select(const Eigen::MatrixXd& u,
FitControlsBicop controls = FitControlsBicop())
Selects the best fitting model.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| controls | The controls (see FitControlsBicop). |
The function calls Bicop:: for all families in family_set and selecting the best fitting model by either BIC or AIC, see Bicop:: and Bicop::.
When at least one variable is discrete, two types of "observations" are required: the first block contains realizations of . Let denote the number of discrete variables (either one or two). The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For continuous variables the left limit and the cdf itself coincide, and their columns can be omitted from the second block. For, e.g., an integer-valued variable, it holds .
Incomplete observations (i.e., ones with a NaN value) are discarded.
double vinecopulib:: Bicop:: loglik(const Eigen::MatrixXd& u = Eigen::MatrixXd()) const
Evaluates the log-likelihood.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | The log-likelihood evaluated at u. |
The log-likelihood is defined as
where is the copula density, see Bicop::.
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
double vinecopulib:: Bicop:: aic(const Eigen::MatrixXd& u = Eigen::MatrixXd()) const
Evaluates the Akaike information criterion (AIC).
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | The AIC evaluated at u. |
The AIC is defined as
where is the log-liklihood (see Bicop::) and is the (effective) number of parameters of the model. The AIC is a consistent model selection criterion even for nonparametric models.
double vinecopulib:: Bicop:: bic(const Eigen::MatrixXd& u = Eigen::MatrixXd()) const
Evaluates the Bayesian information criterion (BIC).
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | The BIC evaluated at u. |
The BIC is defined as
where is the log-liklihood (see Bicop::) and is the (effective) number of parameters of the model. The BIC is a consistent model selection criterion for parametric models.
double vinecopulib:: Bicop:: mbic(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const double psi0 = 0.9) const
Evaluates the modified Bayesian information criterion (mBIC).
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| psi0 | Prior probability of a non-independence copula. |
| Returns | The mBIC evaluated at u. |
The mBIC is defined as
where is the log-likelihood (see Bicop::), is the (effective) number of parameters of the model, and is the prior probability of having a non-independence copula and is an indicator for the family being non-independence.
double vinecopulib:: Bicop:: parameters_to_tau(const Eigen::MatrixXd& parameters) const
Converts the copula parameters to Kendall's .
| Parameters | |
|---|---|
| parameters | The parameters (must be a valid parametrization of the current family). |
Available for every family. For the families whose has no closed form (bb6, bb7, bb8, tawn) it is computed by quadrature. The sign is flipped for the 90 and 270 degree rotations.
Eigen::MatrixXd vinecopulib:: Bicop:: parameters_to_taildep(const Eigen::MatrixXd& parameters) const
Converts the copula parameters to the tail dependence coefficients.
| Parameters | |
|---|---|
| parameters | The parameters (must be a valid parametrization of the current family). |
The result is a matrix collecting the tail dependence coefficients in the four corners of the unit square: is the coefficient as and , with (0 = lower, 1 = upper). Thus is the classical lower and the classical upper tail dependence coefficient.
For the unrotated family, the lower and upper coefficients are:
| Family | Lower | Upper |
|---|---|---|
| Independence, Gaussian, Frank | ||
| Student t | (see below) | |
| Clayton | ||
| Gumbel | ||
| Joe | ||
| BB1 | ||
| BB6 | ||
| BB7 | ||
| BB8 | if , else 0 | |
| Tawn (extreme-value) | ||
| TLL (nonparametric) | NaN | NaN |
Here (and for two-parameter families) denote the copula parameters and the Pickands dependence function. For the Student t copula, with correlation , degrees of freedom , and the Student t cdf, ; it additionally has equal dependence in the two off-diagonal (discordant) corners, obtained by replacing with . All other parametric families have zero off-diagonal coefficients. Rotations permute the corners: 180 degrees swaps lower/upper, while 90/270 degrees move dependence to the off-diagonal corners.
double vinecopulib:: Bicop:: parameters_to_beta(const Eigen::MatrixXd& parameters) const
Converts the copula parameters to Blomqvist's .
| Parameters | |
|---|---|
| parameters | The parameters (must be a valid parametrization of the current family). |
Blomqvist's beta is computed from the copula cdf as , using the same formula for every family (including the nonparametric tll).
Eigen::MatrixXd vinecopulib:: Bicop:: tau_to_parameters(const double& tau) const
Converts a Kendall's into copula parameters for one-parameter families.
| Parameters | |
|---|---|
| tau | A value in . |
| Exceptions | |
| std::runtime_error | if the family is not one of those listed above. |
Only available where determines the parameters completely: the one-parameter families in bicop_families::, i.e. indep, gaussian, clayton, gumbel, frank and joe. Note that student belongs to bicop_families:: — it can be fitted by inverting — but is not invertible here, because pins its correlation and leaves the degrees of freedom free.
Bicop vinecopulib:: Bicop:: with_var_types(const std::vector<std::string>& var_types = { "c", "c" }) const
The same copula under different variable types.
| Parameters | |
|---|---|
| var_types | A vector specifying the types of the variables, e.g., {"c", "d"} means first variable continuous, second discrete. Defaults to both continuous. |
| Returns | A copy with the given variable types. |
| Exceptions | |
| std::runtime_error | if var_types is not two entries, each "c" or "d". |
The model is unchanged: only the variable types change, so a fitted copula can be evaluated on a continuous, discrete or mixed edge without being refitted. The types decide which layout pdf(), cdf() and the h-functions expect and what they return (see Discrete variables).
BicopFamily vinecopulib:: Bicop:: get_family() const
Gets the copula family.
| Returns | the copula family. |
|---|
std::string vinecopulib:: Bicop:: get_family_name() const
Gets the copula family as a string.
| Returns | the human-readable name of the copula family. |
|---|
int vinecopulib:: Bicop:: get_rotation() const
Gets the rotation.
| Returns | the copula rotation in degrees (one of 0, 90, 180, 270). |
|---|
Eigen::MatrixXd vinecopulib:: Bicop:: get_parameters() const
Gets the parameters.
| Returns | the copula parameter(s) as a matrix (shape depends on the family). |
|---|
Eigen::MatrixXd vinecopulib:: Bicop:: get_taildep() const
Gets the tail dependence coefficients.
| Returns | the tail dependence coefficients implied by the current parameters, as a 2x2 matrix; see parameters_ |
|---|
See Bicop::
double vinecopulib:: Bicop:: get_loglik() const
Gets the log-likelihood (only for fitted objects).
| Returns | the log-likelihood of the data the copula was fitted to. |
|---|
void vinecopulib:: Bicop:: set_rotation(const int rotation)
Sets the rotation.
| Parameters | |
|---|---|
| rotation | one of 0, 90, 180, 270. |
Sets the copula rotation.
void vinecopulib:: Bicop:: set_parameters(const Eigen::MatrixXd& parameters)
| Parameters | |
|---|---|
| parameters | parameter matrix; shape must match the family's expected parameter layout. |
Sets the copula parameters.
void vinecopulib:: Bicop:: set_var_types(const std::vector<std::string>& var_types = { "c", "c" })
Sets variable types.
| Parameters | |
|---|---|
| var_types | a length-2 vector with each entry either "c" (continuous, default) or "d" (discrete). |
Sets the variable types.
std::vector<std::string> vinecopulib:: Bicop:: get_var_types() const
Gets variable types.
| Returns | the variable types of the two variables (each "c" for continuous or "d" for discrete). |
|---|
Eigen::VectorXd vinecopulib:: Bicop:: pdf(const Eigen::MatrixXd& u) const
Evaluates the copula density.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | A length n vector of copula densities evaluated at u. |
The copula density is defined as joint density divided by marginal densities, irrespective of variable types.
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
Eigen::VectorXd vinecopulib:: Bicop:: cdf(const Eigen::MatrixXd& u) const
Evaluates the copula distribution.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | A length n vector of copula probabilities evaluated at u. |
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
Eigen::VectorXd vinecopulib:: Bicop:: hfunc1(const Eigen::MatrixXd& u) const
Evaluates the first h-function.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | A length n vector of the first h-function evaluated at u. |
The first h-function is .
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
Eigen::VectorXd vinecopulib:: Bicop:: hfunc2(const Eigen::MatrixXd& u) const
Evaluates the second h-function.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | A length n vector of the second h-function evaluated at u. |
The second h-function is .
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
Eigen::VectorXd vinecopulib:: Bicop:: hinv1(const Eigen::MatrixXd& u) const
Evaluates the inverse of the first h-function.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | A length n vector of the inverse of the first h-function evaluated at u. |
The first h-function is . The inverse is calculated w.r.t. the second argument.
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
Eigen::VectorXd vinecopulib:: Bicop:: hinv2(const Eigen::MatrixXd& u) const
Evaluates the inverse of the second h-function.
| Parameters | |
|---|---|
| u | An matrix of observations for a continuous model. For a model with discrete variables, use an matrix containing the values and their left-limits; left-limit columns for continuous variables may be omitted to obtain the compact layout (see Discrete variables). |
| Returns | A length n vector of the inverse of the second h-function evaluated at u. |
The second h-function is . The inverse is calculated w.r.t. the first argument.
When at least one variable is discrete, more than two columns are required for u: the first block contains realizations of . The second block contains realizations of . The minus indicates a left-sided limit of the cdf. For, e.g., an integer-valued variable, it holds . For continuous variables the left limit and the cdf itself coincide. Respective columns can be omitted in the second block.
Eigen::VectorXd vinecopulib:: Bicop:: pdf_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a second derivative of the copula density.
deriv combines two first-order components, e.g. "par1par1", "par1u1", "u1u2"; a single component means differentiating twice.
Eigen::VectorXd vinecopulib:: Bicop:: hfunc1_deriv(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a first derivative of the first h-function .
deriv is one of "par1", "par2", ... (short form "par"), "u1" (the conditioning argument), or "u2" (which equals the copula density).
Eigen::VectorXd vinecopulib:: Bicop:: hfunc1_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a second derivative of the first h-function.
deriv combines two first-order components; any selector containing "u2" reduces to a density derivative (e.g. "par1u2" equals pdf_deriv(u, "par1")).
Eigen::VectorXd vinecopulib:: Bicop:: hfunc2_deriv(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a first derivative of the second h-function .
deriv is one of "par1", "par2", ... (short form "par"), "u2" (the conditioning argument), or "u1" (which equals the copula density).
Eigen::VectorXd vinecopulib:: Bicop:: hfunc2_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a second derivative of the second h-function.
deriv combines two first-order components; any selector containing "u1" reduces to a density derivative (e.g. "par1u1" equals pdf_deriv(u, "par1")).
Eigen::VectorXd vinecopulib:: Bicop:: logpdf_deriv(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a first derivative of the log-density .
For parameter selectors, dedicated closed forms are used where available (numerically stabler than pdf_ when the density is small); argument selectors are composed by the quotient rule.
Eigen::VectorXd vinecopulib:: Bicop:: logpdf_deriv2(const Eigen::MatrixXd& u,
const std::string& deriv) const
Evaluates a second derivative of the log-density.
See logpdf_; selectors involving the arguments are composed from density derivatives by the quotient rule.
std::vector<Eigen::MatrixXd> vinecopulib:: Bicop:: hessian_full(const Eigen::MatrixXd& u) const
Evaluates the per-observation Hessians.
| Returns | A vector of n symmetric matrices; entry i's element is . |
|---|
Eigen::MatrixXd vinecopulib:: Bicop:: scores_cov(const Eigen::MatrixXd& u) const
Computes the covariance matrix of the scores.
| Returns | The mean-centered, divided-by-n covariance of scores(), a matrix. |
|---|
ScoresResult vinecopulib:: Bicop:: scores_full(const Eigen::MatrixXd& u) const
Evaluates the scores, bundled in a ScoresResult.
Provided for parity with Vinecop::; a single pair copula has no cascade caches, so the result only carries the score matrix.