tnagler / VineCopula

Statistical inference of vine copulas
87 stars 32 forks source link

Differences between CDVine and VineCopula? #73

Closed schrnstn closed 4 years ago

schrnstn commented 4 years ago

Dear developers of this package, first and foremost I want to thank all of you for the effort you put into the development of R copula packages.

Are there any functional differences in the copula implementations between the CDVine and VineCopula packages?

Our background is as follows:

Best wishes and thanks a lot for your time.

tnagler commented 4 years ago

VineCopula is pretty much a strict superset of CDVine. The latter is only designed for C- and D-vines, VineCopula can handle general R-vines (including C- and D-vines) and has a lot of additional convenience/functionality. For that reason, the CDVine package returned the following message on startup since around 4 yers:

The CDVine package is no longer developed actively.
Please consider using the more general VineCopula package
(see https://CRAN.R-project.org/package=VineCopula),
which extends and improves the functionality of CDVine.

It's usually quite easy to convert CDVine code into VineCopula code using VineCopula::D2RVine() and VineCopula::C2RVine(). In ESGtoolkit, I could only find CDVineSim to be used. Here's an implementation of that function that requiring only the VineCopula package:

CD2RVine <- function(family, par, par2, type) {
  # solve length(family) = d * (d - 1) / 2 for d
  d <- (1 + sqrt(1 + 8 * length(family))) / 2
  type <- c(CVine = "CVine", DVine = "DVine")[type]
  switch(type, 
         "CVine" = C2RVine(1:d, family, par, par2),
         "DVine" = D2RVine(1:d, family, par, par2),
         stop("Vine model not implemented."))
}

CDVineSim <- function(N, family, par, par2 = rep(0, length(family)), type) {
  RVineSim(N, CD2RVine(family, par, par2, type))
}

CD2RVine() can be reused all over the place.

ulf85 commented 4 years ago

The main functionality is written in C. In particular, the underlying bivariate copola functions. And the C code is the same in both packages. In VineCopula there are some new functions and of cause the functionality for the general vine. And as @tnagler already mentioned we have right from the beginning wrapper function for CDVine functions.

schrnstn commented 4 years ago

Thanks a lot for your quick reply and further explanations. This is very helpful for us.