Vinecop class
A class for vine copula models.
A vine copula model is characterized by its structure (see RVineStructure objects) and the pair-copulas (see Bicop objects).
Public types
- struct PdfWithHfuncsResult
- The density together with the per-edge quantities computed on the way, as returned by
pdf_.full() - struct ScoresResult
- The scores together with the per-edge quantities computed on the way, as returned by
scores_.full()
Public static functions
Constructors, destructors, conversion operators
- Vinecop() defaulted
-
Vinecop(size_
t d) explicit - Instantiates a D-vine with all pair-copulas set to independence.
- Vinecop(const RVineStructure& structure, const std::vector<std::vector<Bicop>>& pair_copulas = {}, const std::vector<std::string>& var_types = {}) explicit
- Instantiates an arbitrary vine copula model.
-
Vinecop(const Eigen::Matrix<size_
t, Eigen::Dynamic, Eigen::Dynamic>& matrix, const std::vector<std::vector<Bicop>>& pair_copulas = {}, const std::vector<std::string>& var_types = {}) explicit - Instantiates an arbitrary vine copula model.
- Vinecop(const Eigen::MatrixXd& u, const RVineStructure& structure = RVineStructure(), const std::vector<std::string>& var_types = {}, const FitControlsVinecop& controls = FitControlsVinecop()) explicit
- Instantiates from data.
-
Vinecop(const Eigen::MatrixXd& u,
const Eigen::Matrix<size_
t, Eigen::Dynamic, Eigen::Dynamic>& matrix, const std::vector<std::string>& var_types = {}, const FitControlsVinecop& controls = FitControlsVinecop()) explicit - Instantiates from data.
- Vinecop(const std::string& filename, const bool check = true) explicit
- Instantiates from a JSON or CBOR file.
- Vinecop(const nlohmann::json& input, const bool check = true) explicit
- Instantiates from a nlohmann::json object.
Public functions
- auto to_json() const -> nlohmann::json
- Converts 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 select(const Eigen::MatrixXd& u, const FitControlsVinecop& controls = FitControlsVinecop()) -> void
- Automatically fits and selects a vine copula model.
-
auto fit(const Eigen::MatrixXd& u,
const FitControlsBicop& controls = FitControlsBicop(),
const size_
t num_threads = 1) -> void - Fits the parameters of a pre-specified vine copula model.
-
auto pdf(Eigen::MatrixXd u,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the copula density.
-
auto logpdf(Eigen::MatrixXd u,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the copula log-density.
-
auto pdf_full(Eigen::MatrixXd u,
const size_
t num_threads = 1, const bool keep_all = true) const -> PdfWithHfuncsResult - Evaluates the per-pair copula density and h-functions.
-
auto pdf(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the copula density with per-observation parameters.
-
auto logpdf(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> Eigen::VectorXd - Evaluates the copula log-density with per-observation parameters.
-
auto pdf_full(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1, const bool keep_all = true) const -> PdfWithHfuncsResult - Evaluates the copula density (and per-edge quantities) with per-observation parameters.
-
auto cdf(const Eigen::MatrixXd& u,
const size_
t N = 10000, const size_ t num_threads = 1, const std::vector<int>& seeds = std::vector<int>()) const -> Eigen::VectorXd - Evaluates the copula distribution.
-
auto simulate(const size_
t n, const bool qrng = false, const size_ t num_threads = 1, const std::vector<int>& seeds = std::vector<int>()) const -> Eigen::MatrixXd - Simulates from a vine copula model, see
inverse_.rosenblatt() -
auto simulate_conditional(const Eigen::MatrixXd& u_cond,
const bool qrng = false,
const size_
t num_threads = 1, const std::vector<int>& seeds = std::vector<int>()) const -> Eigen::MatrixXd - Simulates from the conditional distribution of a subset of variables given fixed values of the remaining variables.
-
auto simulate_conditional(const Eigen::MatrixXd& u_cond,
const std::vector<size_
t>& conditioning_set, const bool qrng = false, const size_ t num_threads = 1, const std::vector<int>& seeds = std::vector<int>()) const -> Eigen::MatrixXd - Simulates conditionally on a specified set of variables.
-
auto reorient(const std::vector<size_
t>& conditioning_set) -> void - Relabels the vine to an equivalent one whose order tail equals
conditioning_set. -
auto rosenblatt(Eigen::MatrixXd u,
const size_
t num_threads = 1, bool randomize_discrete = true, std::vector<int> seeds = {}) const -> Eigen::MatrixXd - Evaluates the Rosenblatt transform for a vine copula model.
-
auto rosenblatt(Eigen::MatrixXd u,
const std::vector<size_
t>& conditioning_set, const size_ t num_threads = 1, bool randomize_discrete = true, std::vector<int> seeds = {}) const -> Eigen::MatrixXd - Evaluates the Rosenblatt transform for a conditioning set.
-
auto inverse_rosenblatt(const Eigen::MatrixXd& u,
const size_
t num_threads = 1) const -> Eigen::MatrixXd - Evaluates the inverse Rosenblatt transform.
-
auto inverse_rosenblatt(const Eigen::MatrixXd& u,
const std::vector<size_
t>& conditioning_set, const size_ t num_threads = 1) const -> Eigen::MatrixXd - Evaluates the inverse Rosenblatt transform for a conditioning set.
- auto get_npars() const -> double
- Returns sum of the number of parameters for all pair copulas (see. Bicop::
get_npars()). -
auto loglik(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const size_
t num_threads = 1) const -> double - Evaluates the log-likelihood.
-
auto loglik(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_
t num_threads = 1) const -> double - Evaluates the log-likelihood with per-observation parameters.
-
auto aic(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const size_
t num_threads = 1) const -> double - Evaluates the Akaike information criterion (AIC).
-
auto bic(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const size_
t num_threads = 1) const -> double - Evaluates the Bayesian information criterion (BIC).
-
auto mbicv(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const double psi0 = 0.9,
const size_
t num_threads = 1) const -> double - Evaluates the modified Bayesian information criterion for vines (mBICV).
-
auto truncate(size_
t trunc_lvl) -> void - Truncates the vine copula model.
-
auto str(const std::vector<size_
t>& trees = {}) const -> std::string - Summarizes the model into a string (can be used for printing).
-
auto scores_full(Eigen::MatrixXd u,
bool step_wise = true,
const size_
t num_threads = 1, const bool keep_all = true) -> ScoresResult - Evaluates the score function together with the per-edge derivative caches.
-
auto scores(Eigen::MatrixXd u,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::MatrixXd - Evaluates the score function.
-
auto gradient(Eigen::MatrixXd u,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::VectorXd - Evaluates the gradient of the average log-likelihood.
-
auto hessian(Eigen::MatrixXd u,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::MatrixXd - Evaluates the averaged Hessian of the log-likelihood.
-
auto hessian_full(Eigen::MatrixXd u,
bool step_wise = true,
const size_
t num_threads = 1) -> TriangularArray<std::vector<Eigen::MatrixXd>> - Evaluates the hessian per observation.
-
auto scores_cov(Eigen::MatrixXd u,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::MatrixXd - Computes the covariance matrix of scores.
-
auto scores_full(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_
t num_threads = 1, const bool keep_all = true) -> ScoresResult - Evaluates the score function with per-observation parameters.
-
auto scores(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::MatrixXd - Evaluates the score function with per-observation parameters.
-
auto gradient(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::VectorXd - Evaluates the gradient of the average log-likelihood with per-observation parameters.
-
auto hessian(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::MatrixXd - Evaluates the averaged Hessian with per-observation parameters.
-
auto hessian_full(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_
t num_threads = 1) -> TriangularArray<std::vector<Eigen::MatrixXd>> - Evaluates the per-observation Hessians with per-observation parameters.
-
auto scores_cov(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_
t num_threads = 1) -> Eigen::MatrixXd - Computes the covariance matrix of scores with per-observation parameters.
Getters and setters
-
auto get_pair_copula(size_
t tree, size_ t edge) const -> Bicop - Gets a pair copula.
-
auto get_family(size_
t tree, size_ t edge) const -> BicopFamily - Gets the family of a pair copula.
-
auto get_rotation(size_
t tree, size_ t edge) const -> int - Gets the rotation of a pair copula.
-
auto get_parameters(size_
t tree, size_ t edge) const -> Eigen::MatrixXd - Gets the parameters of a pair copula.
-
auto get_tau(size_
t tree, size_ t edge) const -> double - Gets the Kendall's of a pair copula.
-
auto get_trunc_lvl() const -> size_
t - auto get_all_pair_copulas() const -> std::vector<std::vector<Bicop>>
- Gets all pair copulas.
- auto get_all_families() const -> std::vector<std::vector<BicopFamily>>
- Gets the families of all pair copulas.
- auto get_all_rotations() const -> std::vector<std::vector<int>>
- Gets the rotations of all pair copulas.
- auto get_all_parameters() const -> std::vector<std::vector<Eigen::MatrixXd>>
- Gets the parameters of all pair copulas.
- auto get_all_taus() const -> std::vector<std::vector<double>>
- Gets the Kendall's s of all pair copulas.
-
auto get_dim() const -> size_
t - Gets the dimension of the vine copula model.
-
auto get_order() const -> std::vector<size_
t> - Gets the order vector of the vine copula model.
- auto get_rvine_structure() const -> RVineStructure
- Gets the structure matrix of the vine copula model.
-
auto get_matrix() const -> Eigen::Matrix<size_
t, Eigen::Dynamic, Eigen::Dynamic> - Gets the structure matrix of the vine copula model.
-
auto get_struct_array(bool natural_order = false) const -> TriangularArray<size_
t> - Gets the above diagonal coefficients of the vine copula model.
- auto get_trees() const -> RVineTrees
- Gets the vine as a list-of-trees decomposition, each edge carrying its fitted pair-copula (stored with its first argument on the diagonal).
- auto get_threshold() const -> double
- Gets the threshold.
- auto get_loglik() const -> double
- Gets the log-likelihood (throws an error if model has not been. fitted to data).
-
auto get_nobs() const -> size_
t - Gets the number of observations used for the fit.
- auto get_aic() const -> double
- Gets the AIC.
- auto get_bic() const -> double
- Gets the BIC.
- auto get_mbicv(const double psi0 = 0.9) const -> double
- Gets the log-likelihood.
- auto set_all_pair_copulas(const std::vector<std::vector<Bicop>>& pair_copulas) -> void
- Sets all pair-copulas.
- auto set_var_types(const std::vector<std::string>& var_types) -> void
- Sets variable types.
- auto get_var_types() const -> std::vector<std::string>
- Gets the variable types.
Function documentation
static std::vector<std::vector<Bicop>> vinecopulib:: Vinecop:: make_pair_copula_store(const size_ t d,
const size_ t trunc_lvl = std::numeric_limits<size_ t>::max())
Initializes object for storing pair copulas.
| Parameters | |
|---|---|
| d | Dimension of the vine copula. |
| trunc_lvl | A truncation level (optional). |
| Returns | A nested list such that pc_store[t][e] contains a Bicop. object for the pair copula corresponding to tree t and edge e. |
vinecopulib:: Vinecop:: Vinecop(const RVineStructure& structure,
const std::vector<std::vector<Bicop>>& pair_copulas = {},
const std::vector<std::string>& var_types = {}) explicit
Instantiates an arbitrary vine copula model.
| Parameters | |
|---|---|
| structure | An RVineStructure object specifying the vine structure. |
| pair_copulas | Bicop objects specifying the pair-copulas, namely a nested list such that pc_store[t][e] contains a Bicop object for the pair copula corresponding to tree t and edge e. If empty, all pair-copulas are treated as independence. |
| var_types | Strings specifying the types of the variables, e.g., ("c", "d") means first variable continuous, second discrete. If empty, then all variables are set as continuous. |
vinecopulib:: Vinecop:: Vinecop(const Eigen::Matrix<size_ t, Eigen::Dynamic, Eigen::Dynamic>& matrix,
const std::vector<std::vector<Bicop>>& pair_copulas = {},
const std::vector<std::string>& var_types = {}) explicit
Instantiates an arbitrary vine copula model.
| Parameters | |
|---|---|
| matrix | An R-vine matrix specifying the vine structure. |
| pair_copulas | Bicop objects specifying the pair-copulas, namely a nested list such that pc_store[t][e] contains a Bicop object for the pair copula corresponding to tree t and edge e. If empty, all pair-copulas are treated as independence. |
| var_types | Strings specifying the types of the variables, e.g., ("c", "d") means first variable continuous, second discrete. If empty, then all variables are set as continuous. |
vinecopulib:: Vinecop:: Vinecop(const Eigen::MatrixXd& u,
const RVineStructure& structure = RVineStructure(),
const std::vector<std::string>& var_types = {},
const FitControlsVinecop& controls = FitControlsVinecop()) explicit
Instantiates from data.
| Parameters | |
|---|---|
| u | An matrix of observations. |
| structure | An RVineStructure object specifying the vine structure. If empty, then it is selected as part of the fit. |
| var_types | Strings specifying the types of the variables, e.g., ("c", "d") means first variable continuous, second discrete. If empty, then all variables are set as continuous. |
| controls | See FitControlsVinecop(). |
Equivalent to creating a default Vinecop() and then selecting the model using select().
vinecopulib:: Vinecop:: Vinecop(const Eigen::MatrixXd& u,
const Eigen::Matrix<size_ t, Eigen::Dynamic, Eigen::Dynamic>& matrix,
const std::vector<std::string>& var_types = {},
const FitControlsVinecop& controls = FitControlsVinecop()) explicit
Instantiates from data.
| Parameters | |
|---|---|
| u | An matrix of observations. |
| matrix | Either an R-vine structure matrix, see select(), or an empty matrix, in which case the structure is selected as part of the fit. To select the structure, prefer Vinecop(u) with no matrix. |
| var_types | Strings specifying the types of the variables, e.g., ("c", "d") means first variable continuous, second discrete. If empty, then all variables are set as continuous. |
| controls | See FitControlsVinecop(). |
Equivalent to creating a default Vinecop() and then selecting the model using select().
vinecopulib:: Vinecop:: Vinecop(const std::string& filename,
const bool check = true) explicit
Instantiates from a JSON or CBOR file.
| Parameters | |
|---|---|
| filename | The name of the file to read. |
| check | Whether to check if the "structure" node of the input represents a valid R-vine structure. |
Files ending in .cbor are read as CBOR. All other filenames are read as JSON for backwards compatibility. The input contains 2 attributes: "structure" for the vine structure, which itself contains attributes "array" for the structure triangular array and "order" for the order vector, and "pair copulas". "pair copulas" contains a list of attributes for the trees ("tree1", "tree2", etc), each containing a list of attributes for the edges ("pc1", "pc2", etc). See the corresponding method of Bicop objects for the encoding of pair-copulas.
vinecopulib:: Vinecop:: Vinecop(const nlohmann::json& input,
const bool check = true) explicit
Instantiates from a nlohmann::json object.
| Parameters | |
|---|---|
| input | The nlohmann::json object to convert from (see to_ for the structure of the input). |
| check | Whether to check if the "structure" node represents a valid R-vine structure. |
nlohmann::json vinecopulib:: Vinecop:: to_json() const
Converts the copula into a nlohmann::json object.
| Returns | the nlohmann::json object containing the copula. |
|---|
The nlohmann::json object contains two nodes : "structure" for the vine structure, which itself contains nodes "array" for the structure triangular array and "order" for the order vector, and "pair copulas". The former two encode the R-Vine structure and the latter is a list of child nodes for the trees ("tree1", "tree2", etc), each containing a list of child nodes for the edges ("pc1", "pc2", etc). See Bicop::
void vinecopulib:: Vinecop:: to_file(const std::string& filename) const
Writes the copula object into a JSON or CBOR file.
| Parameters | |
|---|---|
| filename | The name of the JSON file to write. |
Filenames ending in .cbor are written as CBOR. All other filenames are written as JSON for backwards compatibility. The output contains 2 attributes: "structure" for the vine structure, which itself contains attributes "array" for the structure triangular array and "order" for the order vector, and "pair copulas". "pair copulas" contains a list of attributes for the trees ("tree1", "tree2", etc), each containing a list of attributes for the edges ("pc1", "pc2", etc). See Bicop:: objects for the encoding of pair-copulas.
void vinecopulib:: Vinecop:: select(const Eigen::MatrixXd& u,
const FitControlsVinecop& controls = FitControlsVinecop())
Automatically fits and selects a vine copula 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 to the algorithm (see FitControlsVinecop()). |
This method can be used to select either the pair-copulas only, or the pair-copulas and the structure. The latter is done by specifying a truncation level in the controls. The method then selects the structure and fits the pair-copulas for all trees up to the truncation level. In other words, select() behaves differently depending on its current truncation level and the truncation level specified in the controls, respectively called trunc_lvl and controls.trunc_lvl in what follows. Essentially, controls.trunc_lvl defines the object's truncation level after calling select():
- If
controls.trunc_lvl <= trunc_lvl, the families and parameters for all pairs in trees smaller or equal tocontrols.trunc_lvlare selected, using the current structure. - If
controls.trunc_lvl > trunc_lvl,select()behaves as above for all trees that are smaller or equal totrunc_lvl, and then it selects the structure for higher trees along with the families and parameters. This includes the case wheretrunc_lvl = 0, namely where the structure is fully unspecified.
Selection of the structure is performed using the algorithm of Dissmann, J. F., E. C. Brechmann, C. Czado, and D. Kurowicka (2013). Selecting and estimating regular vine copulae and application to financial returns. Computational Statistics & Data Analysis, 59 (1), 52-69. The dependence measure used to select trees (default: Kendall's tau) is corrected for ties (see the wdm library). The dependence measure can be changed using controls.tree_criterion, which can be set to "tau", "rho", "hoeffd", "mcor", "cxi", "joe", or "custom". The last one uses the callable supplied through controls.tree_criterion_function, which is always called on the thread that starts the fit, so it need not be thread safe; the pair-copula fits still use controls.num_threads threads. Both Prim's (default: "mst_prim") and Kruskal's ("mst_kruskal") algorithms are available through controls.tree_algorithm for the maximum spanning tree selection. An alternative to the maximum spanning tree selection is to use random spanning trees, which can be selected using controls.tree_algorithm and come in two flavors, both using Wilson's algorithm loop erased random walks:
"random_weighted"generates a random spanning tree with probability proportional to the product of the weights (i.e., the dependence) of the edges in the tree."random_unweighted"generates a random spanning tree uniformly over all spanning trees satisfying the proximity condition.
If the controls object has been instantiated with select_families = false, then the method simply updates the parameters of the pair-copulas without selecting the families or the structure. In this case, this is equivalent to calling fit() for each pair-copula, albeit potentially in parallel if num_threads > 1.
When at least one variable is discrete, two types of "observations" are required: the first block contains realizations of ; 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. For, e.g., an integer-valued variable, it holds . Continuous variables in the second block can be omitted.
If there are missing data (i.e., NaN entries), incomplete observations are discarded before fitting a pair-copula. This is done on a pair-by-pair basis so that the maximal available information is used.
void vinecopulib:: Vinecop:: fit(const Eigen::MatrixXd& u,
const FitControlsBicop& controls = FitControlsBicop(),
const size_ t num_threads = 1)
Fits the parameters of a pre-specified vine copula 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 for each bivariate fit (see FitControlsBicop()). |
| num_threads | The number of threads to use for parallel computation. |
This method fits the pair-copulas of a vine copula model. It is assumed that the structure and pair-copula families are already set. The method is equivalent to calling fit() for each pair-copula in the model. The same can be achieved by calling select() with the same data and a FitControlsVinecop object instantiated with select_families = false.
Eigen::VectorXd vinecopulib:: Vinecop:: pdf(Eigen::MatrixXd u,
const size_ t num_threads = 1) const
Evaluates the copula density.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | A vector of length n containing the copula density values. |
The copula density is defined as joint density divided by marginal densities, irrespective of variable types.
When at least one variable is discrete, two types of "observations" are required in 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:: Vinecop:: logpdf(Eigen::MatrixXd u,
const size_ t num_threads = 1) const
Evaluates the copula log-density.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | A vector of length n containing the copula log-density values. |
The logarithm of pdf(), and the accurate way to obtain it: a vine density is a product of up to pair-copula densities, so for a high-dimensional or strongly dependent model pdf() underflows to 0, and log(pdf()) to , while the log-density is still perfectly representable. loglik() is the sum of these values.
PdfWithHfuncsResult vinecopulib:: Vinecop:: pdf_full(Eigen::MatrixXd u,
const size_ t num_threads = 1,
const bool keep_all = true) const
Evaluates the per-pair copula density and h-functions.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| keep_all | Whether to keep and return per-edge pdfs and h-functions. |
| Returns | A struct containing:
|
The copula density is defined as joint density divided by marginal densities, irrespective of variable types.
When at least one variable is discrete, two types of "observations" are required in 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:: Vinecop:: pdf(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
const size_ t num_threads = 1) const
Evaluates the copula density with per-observation parameters.
Per-observation counterpart of pdf(); see the per-observation pdf_ overload for the parameters layout and restrictions.
Eigen::VectorXd vinecopulib:: Vinecop:: logpdf(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
const size_ t num_threads = 1) const
Evaluates the copula log-density with per-observation parameters.
Per-observation counterpart of logpdf(); see the per-observation pdf_ overload for the parameters layout and restrictions.
PdfWithHfuncsResult vinecopulib:: Vinecop:: pdf_full(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
const size_ t num_threads = 1,
const bool keep_all = true) const
Evaluates the copula density (and per-edge quantities) with per-observation parameters.
Same as pdf_, but each observation uses its own full-vine parameter vector, supplied as an matrix parameters whose columns follow the (tree, edge, parameter) order of scores(). Continuous, all-parametric models only (discrete variables and nonparametric pair copulas are rejected).
Eigen::VectorXd vinecopulib:: Vinecop:: cdf(const Eigen::MatrixXd& u,
const size_ t N = 10000,
const size_ t num_threads = 1,
const std::vector<int>& seeds = std::vector<int>()) const
Evaluates the copula distribution.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| N | Integer for the number of quasi-random numbers to draw to evaluate the distribution (default: 1e4). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will generate n samples concurrently in num_threads batches. |
| seeds | Seeds to scramble the quasi-random numbers; if empty (default), the random number quasi-generator is seeded randomly. |
| Returns | A vector of length n containing the copula distribution values. |
Because no closed-form expression is available, the distribution is estimated numerically using Monte Carlo integration. The function uses quasi-random numbers from the vine model to do so.
When at least one variable is discrete, two types of "observations" are required in 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::MatrixXd vinecopulib:: Vinecop:: simulate(const size_ t n,
const bool qrng = false,
const size_ t num_threads = 1,
const std::vector<int>& seeds = std::vector<int>()) const
Simulates from a vine copula model, see inverse_.
| Parameters | |
|---|---|
| n | Number of observations. |
| qrng | Set to true for quasi-random numbers. |
| num_threads | The number of threads to use for computations; if greater than 1, the function will generate n samples concurrently in num_threads batches. |
| seeds | Seeds of the random number generator; if empty (default), the random number generator is seeded randomly. |
| Returns | An matrix of samples from the copula model. |
Simulated data is always a continuous matrix. Sampling from a vine copula model is done by first generating uniform random numbers and then applying the inverse Rosenblatt transformation.
Eigen::MatrixXd vinecopulib:: Vinecop:: simulate_conditional(const Eigen::MatrixXd& u_cond,
const bool qrng = false,
const size_ t num_threads = 1,
const std::vector<int>& seeds = std::vector<int>()) const
Simulates from the conditional distribution of a subset of variables given fixed values of the remaining variables.
| Parameters | |
|---|---|
| u_cond | An matrix of conditioning values when all conditioning variables are continuous. This overload infers k from the column count and therefore uses the compact layout: if k_d conditioning variables are discrete, append their left-limits to obtain an matrix. Use the overload with an explicit conditioning_set to supply the expanded layout. Row j is the conditioning point for output sample j (n is the number of rows of u_cond). The first k columns hold the values ; column i corresponds to the (d - k + i)-th variable of the vine order, i.e. the columns correspond, left to right, to the last k entries of the order. The next k_d columns hold the left-limits of the discrete conditioning variables, in the order those variables appear among the first k columns. For all-continuous conditioning this is simply an matrix. k is inferred from the column count; supplying only k columns when a conditioning variable is discrete may be silently reinterpreted as a different k. To draw many samples at a single conditioning point, pass that point repeated over n rows. The overload taking conditioning_set accepts both layouts; use it for the expanded layout because that shape can be ambiguous with a compact layout for a different number of conditioning variables. |
| qrng | Set to true for quasi-random numbers (over the conditioned variables). |
| num_threads | The number of threads to use for computations. |
| seeds | Seeds of the random number generator; if empty (default), the random number generator is seeded randomly. |
| Returns | An matrix; the remaining columns are draws from the conditional distribution. The conditioning columns reproduce u_cond exactly for continuous variables. A discrete conditioning variable is reproduced up to its atom (the column lands in ); with several discrete conditioning variables the later-drawn ones may land slightly outside their atom, but the draws of the remaining (conditioned) variables remain correct. |
The conditioning variables are the last k variables of the vine order (they are drawn first by the vine and form a self-contained sub-vine). Each row of u_cond is one conditioning point; the corresponding output row is drawn from the remaining variables' distribution conditional on that point.
Discrete conditioning variables are supported. As for the other data-taking methods, a discrete variable requires its left-limit CDF in addition to ; u_cond therefore carries one extra column per discrete conditioning variable (see the u_cond layout below). The conditioned variables are then drawn using the randomized transform of rosenblatt() (see its randomize_discrete note).
Eigen::MatrixXd vinecopulib:: Vinecop:: simulate_conditional(const Eigen::MatrixXd& u_cond,
const std::vector<size_ t>& conditioning_set,
const bool qrng = false,
const size_ t num_threads = 1,
const std::vector<int>& seeds = std::vector<int>()) const
Simulates conditionally on a specified set of variables.
| Parameters | |
|---|---|
| u_cond | An matrix of conditioning values when all conditioning variables are continuous, with one conditioning point per row. If any are discrete, use an matrix containing the values followed by all left-limits. Left-limit columns for continuous variables may be omitted to obtain the compact layout, where k_d is the number of discrete conditioning variables. The first k columns follow conditioning_set. |
| conditioning_set | The 1-based conditioning-variable indices. The first k columns of u_cond correspond to these variables in the given order. In the expanded layout, the next k columns contain their left-limits in the same order; in the compact layout, only left-limits of discrete variables follow. |
| qrng | Set to true for quasi-random numbers (over the conditioned variables). |
| num_threads | The number of threads to use for computations. |
| seeds | Seeds of the random number generator; if empty (default), the random number generator is seeded randomly. |
| Returns | An matrix of conditional samples. |
void vinecopulib:: Vinecop:: reorient(const std::vector<size_ t>& conditioning_set)
Relabels the vine to an equivalent one whose order tail equals conditioning_set.
| Parameters | |
|---|---|
| conditioning_set | 1-based variable indices to place at the tail of the variable order. |
A value-preserving re-orientation: the fitted model is unchanged (both the density pdf and the log-likelihood loglik are invariant), only its sampling-order representation changes, so that the variables in conditioning_set are drawn first and can be conditioned on with simulate_conditional. It chooses, per tree, which conditioned variable sits on the matrix diagonal, and flips each pair copula whose stored orientation no longer matches its new position. Truncated models are supported: only the trees they store take part, and the truncation level is preserved. Throws if the current structure admits no sampling order ending in conditioning_set (fit with a conditioning set via FitControlsVinecop to guarantee one exists).
Eigen::MatrixXd vinecopulib:: Vinecop:: rosenblatt(Eigen::MatrixXd u,
const size_ t num_threads = 1,
bool randomize_discrete = true,
std::vector<int> seeds = {}) const
Evaluates the Rosenblatt transform for a vine copula model.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| randomize_discrete | Whether to randomize the transform for discrete variables; see Details. |
| seeds | Seeds to scramble the quasi-random numbers; if empty (default), the random number quasi-generator is seeded randomly. Only relevant if there are discrete variables and randomize_discrete = TRUE. |
| Returns | An matrix of independent uniform variates. |
The Rosenblatt transform converts data from this model into independent uniform variates.
The Rosenblatt transform (Rosenblatt, 1952) of a random vector is defined as
where is the conditional distribution of given . The vector then contains independent standard uniform variables. The inverse operation
can be used to simulate from a distribution. For any copula , if is a vector of independent random variables, has distribution .
The formulas above assume a vine copula model with order . More generally, Vinecop:: returns the variables
where is the structure matrix. Similarly, Vinecop:: computes
If some variables have atoms, Brockwell (10.1016/j.spl.2007.02.008) proposed a simple randomization scheme to ensure that output is still independent uniform if the model is correct. The transformation reads
where is the left limit of the conditional cdf and are are independent standard uniform random variables. This is used by default. If you are interested in the conditional probabilities
set randomize_discrete = FALSE.
Eigen::MatrixXd vinecopulib:: Vinecop:: rosenblatt(Eigen::MatrixXd u,
const std::vector<size_ t>& conditioning_set,
const size_ t num_threads = 1,
bool randomize_discrete = true,
std::vector<int> seeds = {}) const
Evaluates the Rosenblatt transform for a conditioning set.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| conditioning_set | The 1-based indices of the conditioning variables. |
| num_threads | The number of threads to use for computations. |
| randomize_discrete | Whether to randomize the transform for discrete variables. |
| seeds | Seeds used for discrete randomization. |
| Returns | An matrix of independent uniform variates. |
The vine is evaluated in an admissible sampling order whose tail contains exactly conditioning_set. The model itself is not modified.
Eigen::MatrixXd vinecopulib:: Vinecop:: inverse_rosenblatt(const Eigen::MatrixXd& u,
const size_ t num_threads = 1) const
Evaluates the inverse Rosenblatt transform.
| Parameters | |
|---|---|
| u | An matrix of independent uniform variates. Only these first columns are used; the expanded and compact discrete-data layouts are also accepted for convenience, where is the number of discrete variables. |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | An matrix of evaluations. |
The inverse Rosenblatt transform can be used for simulation: the function applied to independent uniform variates resembles simulated data from the vine copula model.
If the problem is too large, it is split recursively into halves (w.r.t. , the number of observations). "Too large" means that the required memory will exceed 1 GB. An exemplary configuration requiring less than 1 GB is , .
The Rosenblatt transform (Rosenblatt, 1952) of a random vector is defined as
where is the conditional distribution of given . The vector then contains independent standard uniform variables. The inverse operation
can be used to simulate from a distribution. For any copula , if is a vector of independent random variables, has distribution .
The formulas above assume a vine copula model with order . More generally, Vinecop:: returns the variables
where is the structure matrix. Similarly, Vinecop:: computes
Eigen::MatrixXd vinecopulib:: Vinecop:: inverse_rosenblatt(const Eigen::MatrixXd& u,
const std::vector<size_ t>& conditioning_set,
const size_ t num_threads = 1) const
Evaluates the inverse Rosenblatt transform for a conditioning set.
| Parameters | |
|---|---|
| u | An matrix of independent uniform variates. Only these first columns are used; the expanded and compact discrete-data layouts are also accepted for convenience, where is the number of discrete variables. |
| conditioning_set | The 1-based indices of the conditioning variables. |
| num_threads | The number of threads to use for computations. |
| Returns | An matrix of transformed values. |
The vine is evaluated in an admissible sampling order whose tail contains exactly conditioning_set. The model itself is not modified.
double vinecopulib:: Vinecop:: get_npars() const
Returns sum of the number of parameters for all pair copulas (see. Bicop::
| Returns | the total number of parameters across all pair copulas. For nonparametric families, this is a conceptually similar effective-parameter count. |
|---|
double vinecopulib:: Vinecop:: loglik(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const size_ t num_threads = 1) const
Evaluates the log-likelihood.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | The log-likelihood as a double. |
The log-likelihood is defined as
where is the copula density, see Vinecop::. Summing the log-densities keeps the result finite wherever it is representable, which a product of pair-copula densities is not; see Vinecop::. An observation containing NaN has no likelihood and is left out of the sum, as it is for Bicop::; an empty u reports the value recorded by the fit.
double vinecopulib:: Vinecop:: loglik(const Eigen::MatrixXd& u,
const Eigen::MatrixXd& parameters,
const size_ t num_threads = 1) const
Evaluates the log-likelihood with per-observation parameters.
Log-likelihood with per-observation parameters (see the per-observation pdf() overload for the parameters layout and restrictions).
Per-observation counterpart of loglik(): the sum over observations of , where row i of parameters is . See the per-observation pdf_ overload for the parameters layout and restrictions.
double vinecopulib:: Vinecop:: aic(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const size_ t num_threads = 1) const
Evaluates the Akaike information criterion (AIC).
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | The AIC as a double. |
The AIC is defined as
where is the log-liklihood (see Vinecop::) and is the (effective) number of parameters of the model. The AIC is a consistent model selection criterion even for nonparametric models.
double vinecopulib:: Vinecop:: bic(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const size_ t num_threads = 1) const
Evaluates the Bayesian information criterion (BIC).
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | The BIC as a double. |
The BIC is defined as
where is the log-liklihood (see Vinecop::) and is the (effective) number of parameters of the model. The BIC is a consistent model selection criterion for nonparametric models.
double vinecopulib:: Vinecop:: mbicv(const Eigen::MatrixXd& u = Eigen::MatrixXd(),
const double psi0 = 0.9,
const size_ t num_threads = 1) const
Evaluates the modified Bayesian information criterion for vines (mBICV).
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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 | Baseline prior probability of a non-independence copula. |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| Returns | The mBICV as a double. |
The mBICV is defined as
where is the log-liklihood, is the (effective) number of parameters of the model, is the tree level, is the prior probability of having a non-independence copula in the first tree, and is the number of non-independence copulas in tree ; The vBIC is a consistent model selection criterion for parametric sparse vine copula models when .
void vinecopulib:: Vinecop:: truncate(size_ t trunc_lvl)
Truncates the vine copula model.
| Parameters | |
|---|---|
| trunc_lvl | The truncation level. |
While model for a d dimensional random vector contains at most d-1 nested trees, this function extracts a sub-model based on a given truncation level.
If the model is already truncated at a level less than trunc_lvl, the function does nothing.
ScoresResult vinecopulib:: Vinecop:: scores_full(Eigen::MatrixXd u,
bool step_wise = true,
const size_ t num_threads = 1,
const bool keep_all = true)
Evaluates the score function together with the per-edge derivative caches.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| step_wise | if false, full gradient of the log-likelihood; if true, score function of the step-wise MLE (gradients computed per pair-copula, treating the pseudo-observations as fixed). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
| keep_all | Whether to keep and return the per-edge derivative caches. |
| Returns | A struct containing:
|
The score function is defined as the gradient of the log-likelihood with respect to the parameters.
The scores are computed analytically from the pair copulas' derivatives (Bicop:: and, for the full gradient, the h-function derivatives propagated through the vine by the chain rule); models with discrete variables use central finite differences instead (in which case the caches below stay empty). Models with nonparametric pair copulas are rejected (differentiating w.r.t. the interpolation grid is meaningless).
Eigen::MatrixXd vinecopulib:: Vinecop:: scores(Eigen::MatrixXd u,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the score function.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| step_wise | if false, full gradient of the log-likelihood; if true, score function of the step-wise MLE (gradients computed per pair-copula, treating the pseudo-observations as fixed). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
The score function is defined as the gradient of the log-likelihood with respect to the parameters. This is a thin wrapper around scores_; see there for the computational details.
Eigen::VectorXd vinecopulib:: Vinecop:: gradient(Eigen::MatrixXd u,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the gradient of the average log-likelihood.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| step_wise | if false, full gradient of the log-likelihood; if true, score function of the step-wise MLE (gradients computed per pair-copula, treating the pseudo-observations as fixed). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
Returns the observation-average of scores() as a vector of length npars, mirroring how hessian() averages hessian_.
Eigen::MatrixXd vinecopulib:: Vinecop:: hessian(Eigen::MatrixXd u,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the averaged Hessian of the log-likelihood.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| step_wise | if false, full gradient of the log-likelihood; if true, score function of the step-wise MLE (gradients computed per pair-copula). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
Hessian is meant loosely as "gradients of each component of the score
function". The Hessian is averaged over all samples in u, yielding an matrix (use hessian_ for the per-observation decomposition).
TriangularArray<std::vector<Eigen::MatrixXd>> vinecopulib:: Vinecop:: hessian_full(Eigen::MatrixXd u,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the hessian per observation.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| step_wise | if false, full gradient of the log-likelihood; if true, score function of the step-wise MLE (gradients computed per pair-copula). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
Hessian is meant loosely as "gradients of each component of the score
function", i.e. hess(t, e)[p](i, a) = ∂² log-likelihood_i / (∂θ_{t,e,p} ∂θ_a). For a continuous model it is computed analytically from the pair copulas' first and second derivatives: the joint (non-step-wise) Hessian by a second-order cascade through the vine (the second derivative of the RVineGrad-style gradient cascade in scores()), and the step-wise Hessian by a first-order cascade of the step-wise score's argument derivatives. Models with discrete variables use central finite differences of scores() instead; models with nonparametric pair copulas are rejected.
Eigen::MatrixXd vinecopulib:: Vinecop:: scores_cov(Eigen::MatrixXd u,
bool step_wise = true,
const size_ t num_threads = 1)
Computes the covariance matrix of scores.
| Parameters | |
|---|---|
| u | An matrix of evaluation points 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). |
| step_wise | if false, full gradient of the log-likelihood; if true, score function of the step-wise MLE (gradients computed per pair-copula). |
| num_threads | The number of threads to use for computations; if greater than 1, the function will be applied concurrently to num_threads batches of u. |
Returns the (mean-centered, divided by n) covariance of the per-observation scores as an matrix. Together with hessian() this forms the sandwich estimator of the asymptotic covariance.
ScoresResult vinecopulib:: Vinecop:: scores_full(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_ t num_threads = 1,
const bool keep_all = true)
Evaluates the score function with per-observation parameters.
Same as scores_, but each observation uses its own full-vine parameter vector, supplied as an matrix parameters whose columns follow the (tree, edge, parameter) order of scores(). Continuous, all-parametric models only; discrete variables are rejected (they would require finite differences that mutate shared parameters).
Eigen::MatrixXd vinecopulib:: Vinecop:: scores(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the score function with per-observation parameters.
Per-observation counterpart of scores(); see the per-observation scores_ overload for the parameters layout and restrictions.
Eigen::VectorXd vinecopulib:: Vinecop:: gradient(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the gradient of the average log-likelihood with per-observation parameters.
Per-observation counterpart of gradient(); the return is the observation-average of the per-observation scores().
Eigen::MatrixXd vinecopulib:: Vinecop:: hessian(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the averaged Hessian with per-observation parameters.
Per-observation counterpart of hessian(); see the per-observation scores_ overload for the parameters layout and restrictions.
TriangularArray<std::vector<Eigen::MatrixXd>> vinecopulib:: Vinecop:: hessian_full(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_ t num_threads = 1)
Evaluates the per-observation Hessians with per-observation parameters.
Per-observation counterpart of hessian_; see the per-observation scores_ overload for the parameters layout and restrictions.
Eigen::MatrixXd vinecopulib:: Vinecop:: scores_cov(Eigen::MatrixXd u,
const Eigen::MatrixXd& parameters,
bool step_wise = true,
const size_ t num_threads = 1)
Computes the covariance matrix of scores with per-observation parameters.
Per-observation counterpart of scores_; see the per-observation scores_ overload for the parameters layout and restrictions.
Bicop vinecopulib:: Vinecop:: get_pair_copula(size_ t tree,
size_ t edge) const
Gets a pair copula.
| Parameters | |
|---|---|
| tree | Tree index (starting with 0). |
| edge | Edge index (starting with 0). |
| Returns | the pair copula at the given (tree, edge) position. |
BicopFamily vinecopulib:: Vinecop:: get_family(size_ t tree,
size_ t edge) const
Gets the family of a pair copula.
| Parameters | |
|---|---|
| tree | Tree index (starting with 0). |
| edge | Edge index (starting with 0). |
| Returns | the family of the pair copula at the given (tree, edge). |
int vinecopulib:: Vinecop:: get_rotation(size_ t tree,
size_ t edge) const
Gets the rotation of a pair copula.
| Parameters | |
|---|---|
| tree | Tree index (starting with 0). |
| edge | Edge index (starting with 0). |
| Returns | the rotation of the pair copula at the given (tree, edge), in degrees (one of 0, 90, 180, 270). |
Eigen::MatrixXd vinecopulib:: Vinecop:: get_parameters(size_ t tree,
size_ t edge) const
Gets the parameters of a pair copula.
| Parameters | |
|---|---|
| tree | Tree index (starting with 0). |
| edge | Edge index (starting with 0). |
| Returns | the parameter matrix of the pair copula at the given (tree, edge). |
size_ t vinecopulib:: Vinecop:: get_trunc_lvl() const
| Returns | the truncation level (number of fitted trees; pair copulas in trees above this level are forced to independence). |
|---|
std::vector<std::vector<Bicop>> vinecopulib:: Vinecop:: get_all_pair_copulas() const
Gets all pair copulas.
| Returns | all pair copulas, indexed as [tree][edge]. |
|---|
std::vector<std::vector<BicopFamily>> vinecopulib:: Vinecop:: get_all_families() const
Gets the families of all pair copulas.
| Returns | the families of all pair copulas, indexed as [tree][edge]. |
|---|
std::vector<std::vector<int>> vinecopulib:: Vinecop:: get_all_rotations() const
Gets the rotations of all pair copulas.
| Returns | the rotations of all pair copulas, indexed as [tree][edge]. |
|---|
std::vector<std::vector<Eigen::MatrixXd>> vinecopulib:: Vinecop:: get_all_parameters() const
Gets the parameters of all pair copulas.
| Returns | the parameter matrices of all pair copulas, indexed as [tree][edge]. |
|---|
std::vector<std::vector<double>> vinecopulib:: Vinecop:: get_all_taus() const
Gets the Kendall's s of all pair copulas.
| Returns | Kendall's tau for every pair copula, indexed as [tree][edge]. |
|---|
RVineStructure vinecopulib:: Vinecop:: get_rvine_structure() const
Gets the structure matrix of the vine copula model.
| Returns | the underlying R-vine structure. |
|---|
Eigen::Matrix<size_ t, Eigen::Dynamic, Eigen::Dynamic> vinecopulib:: Vinecop:: get_matrix() const
Gets the structure matrix of the vine copula model.
| Returns | the R-vine structure as a square matrix (cf. Joe, 2014, Section 6.13). |
|---|
TriangularArray<size_ t> vinecopulib:: Vinecop:: get_struct_array(bool natural_order = false) const
Gets the above diagonal coefficients of the vine copula model.
| Parameters | |
|---|---|
| natural_order | whether to return the array in natural order or original variable order. |
| Returns | the R-vine structure as a triangular array. |
RVineTrees vinecopulib:: Vinecop:: get_trees() const
Gets the vine as a list-of-trees decomposition, each edge carrying its fitted pair-copula (stored with its first argument on the diagonal).
| Returns | the vine as a list-of-trees decomposition, with each edge carrying its fitted pair-copula. |
|---|
double vinecopulib:: Vinecop:: get_threshold() const
Gets the threshold.
| Returns | the absolute-dependence threshold used during structure selection (0 if thresholding was disabled). |
|---|
Usually zero except select_threshold == TRUE in FitControlsVinecop()).
double vinecopulib:: Vinecop:: get_loglik() const
Gets the log-likelihood (throws an error if model has not been. fitted to data).
| Returns | the log-likelihood of the data the vine was fitted to. |
|---|
double vinecopulib:: Vinecop:: get_mbicv(const double psi0 = 0.9) const
Gets the log-likelihood.
| Returns | the modified Bayesian information criterion for vines at the fitted parameters; psi0 is the prior probability of a non-independence pair copula. |
|---|
The function throws an error if model has not been fitted to data.
void vinecopulib:: Vinecop:: set_all_pair_copulas(const std::vector<std::vector<Bicop>>& pair_copulas)
Sets all pair-copulas.
| Parameters | |
|---|---|
| pair_copulas | nested list of Bicop instances, shaped like [tree][edge] with dim - 1 - tree edges in tree tree. |
Sets every pair copula in one shot.
void vinecopulib:: Vinecop:: set_var_types(const std::vector<std::string>& var_types)
Sets variable types.
| Parameters | |
|---|---|
| var_types | a length-dim vector with each entry either "c" (continuous) or "d" (discrete). |
Sets the variable types.
std::vector<std::string> vinecopulib:: Vinecop:: get_var_types() const
Gets the variable types.
| Returns | the variable types of each variable (each "c" for continuous or "d" for discrete). |
|---|