Coder Social home page Coder Social logo

vinecopula's People

Contributors

bengraeler avatar etobi88 avatar oezgesahin avatar slayoo avatar tnagler avatar tvatter avatar ulf85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vinecopula's Issues

about choosing the variables of vine copula

Dear Nagler

I would like to ask about how we could choose the variables to construct the vine copula? is there a specific order for the variables? or on what does it depend?

Regards

Parametr type in RVineStructureSelect and output message

I have passed the parametr type='CVine' into the RVineStructureSelect() function and seen in the console R-vine copula...

RVineStructureSelect(data=empCop, family=1, type='CVine')
R-vine copula with the following pair-copulas:

then I have changed the parametr on type='RVine' and the output message is D-vine copula...

RVineStructureSelect(data=empCop, family=1, type='RVine')
D-vine copula with the following pair-copulas:

I hope the issue is in the text of output message only.

Unexpected C-Vine Simulation Results

I would like to simulate a dependence structure w/ 4 variables with a C-Vine, where C(1,2) = Clayton(Theta:2), C(1,3) = Clayton(Theta:3), C(1,4) = Clayton(Theta:4), and C(2,3|1) = Indep, C(2,4|1) = Indep, and C(3,4|1,2) = Indep. I use the following R-code to do so:

>> library("VineCopula")
>> d = 4
>> dd = 6
>> fam = c(3,3,3,0,0,0)
>> par1 = c(2,3,4,0,0,0)
>> order = 1:d
>> RVM <- C2RVine(order, fam, par1)
>> U <- RVineSim(300, RVM)

However, when I plot the pairwise associations using

>> pairs(U)

I am surprised to find that C(2,3) for example is showing some association. The pair-wise plot looks as follows:
https://imgur.com/IJWXXAV

I'm unsure why the Vine specified above is showing some association between C(2,3) and C(2,4). The RVM variable prints out the following description:

> RVM
C-vine copula with the following pair-copulas:
Tree 1:
1,4  Clayton (par = 4, tau = 0.67) 
1,3  Clayton (par = 3, tau = 0.6) 
1,2  Clayton (par = 2, tau = 0.5) 

Tree 2:
2,4;1  Independence 
2,3;1  Independence 

Tree 3:
3,4;2,1  Independence 

which seems to be what I want. Can you please advise how to simulate what I'm trying to achieve? Essentially, I want pairwise dependence between node 1 and 2,3,4 and independence everywhere else.

Parallel computing in RVineStructureSelect slower than one core

Selecting a R-vine structure with several cores takes much longer than using just one. I used:
rvine <- RVineStructureSelect(data=U, familyset=c(1),type=0, selectioncrit = "AIC",
indeptest = FALSE,treecrit = "tau",
trunclevel = NA,cores=4)
and U has 200+ dimensions.
The same holds if I truncate some trees. Is there an explanation for that?

Extend BiCop- and RVineMatrix objects

BiCop- and RVineMatrix-objects will be extended to automatically include various dependence measures and (possibly) estimated standard errors from estimation.

Error with function BiCopSelect()

I used BiCopSelect() to select a copula, the code is:

fit <- BiCopSelect(px[ , 1], py[ , 1], familyset = 3:5, rotations = FALSE)

And the function reported an error like:

Error in if (c11 - c00 > 0.3) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In cor(x[(x[, 1] < 0) & (x[, 2] < 0), ]) : 标准差为零

Is there any problem with the data I use? Thanks a lot.

Suggestion: Add a function that fits all copulas

Hello. This is a suggestion/question about the package VineCopula. I have been working with the package and noticed that there is no way to fit and return all copulas. Is that right? I only see a method BiCopSelect that fits all copulas, but only returns the best fit based on AIC. What about returning all copulas, sorted on AIC? Or any chosen criterion for that matter.

I wrote a function myself called BiCopFitAll and added in it R/BiCopSelect.R. It is a simple modification of the BiCopSelect function. I believe that the code is correct, but I haven't tested it very thoroughly yet.

If there is a method to achieve such a thing, without having to extend the package, please let me know. I tried doing something similar using VineCopula:::, but it did not work. I see no other option other than modifying the package.

Linking "src/include" to "inst/include"

It would be nice to make a soft link to src/include in inst/include (You don't have that directory yet). This will install the headers and allow other packages using VineCopula's headers via the LinkingTo option in other packages' DESCRIPTION file.

Revise all manual pages

All manual pages should be revised:

  • improve readability in roxygen2 format,
  • check if the text still fits the current functionality,
  • add additional explanations,
  • improve examples (e.g., using the new BiCop objects and plotting generics),
  • update references.

Documentation with roxygen2

To switch our documentation system to roxygen2, most of the work can be done by the Rd2roxygen package. Minor manual corrections will be required.

BiCopSelect selects the wrong copula

I have a set of u and v (copula data). Clayton is supposed to be the best option based on AIC. But the following two codes (both including Gumbel and Clayton as candidates) give totally different results - the Gumbel one is wrong.

It happens again when I use RVineStructureSelect. It is a big issue, as the truly optimal choice is not picked up at times, in an unknown way.

fit<-BiCopSelect(u,v,familyset=c(1,2,3,4,5,6),selectioncrit="AIC",rotations=FALSE)
summary(fit)
Family


No: 4
Name: Gumbel

Parameter(s)

par: 1.07

Dependence measures

Kendall's tau: 0.07 (empirical = 0.09, p value = 0.17)
Upper TD: 0.09
Lower TD: 0

Fit statistics

logLik: 1.01
AIC: -0.02
BIC: 2.63

fit<-BiCopSelect(u,v,familyset=c(3,4),selectioncrit="AIC",rotations=FALSE)
summary(fit)
Family


No: 3
Name: Clayton

Parameter(s)

par: 0.25

Dependence measures

Kendall's tau: 0.11 (empirical = 0.09, p value = 0.17)
Upper TD: 0
Lower TD: 0.06

Fit statistics

logLik: 2.39
AIC: -2.78
BIC: -0.13

Book1.txt

Parameter - error given for rotated Gumbel and Clayton copulas

The following code produces the errors

"
Error:
In VineCopula::BiCopDeriv: The parameter of the rotated Clayton copula has to be be in the interval [-28,0)
"
and,
"
Error:
In VineCopula::BiCopDeriv: The parameter of the rotated Gumbel copula has to be in the interval [-17,-1].
"

u <- cbind(runif(100), runif(100))

VineCopula::BiCopDeriv(
u[, 1], u[, 2], "33",
par = -1)

VineCopula::BiCopDeriv(
u[, 1], u[, 2], "23",
par = -1)

VineCopula::BiCopDeriv(
u[, 1], u[, 2], "34",
par = -5)

VineCopula::BiCopDeriv(
u[, 1], u[, 2], "24",
par = -5)

Bug in RVineCopSelect

Following error occurs in RVineCopSelect (example from the manual used)

library(VineCopula)
# define 5-dimensional R-vine tree structure matrix
Matrix <- c(5, 2, 3, 1, 4,
            0, 2, 3, 4, 1,
            0, 0, 3, 4, 1,
            0, 0, 0, 4, 1,
            0, 0, 0, 0, 1)
# define R-vine pair-copula family matrix
Matrix <- matrix(Matrix, 5, 5)
# define R-vine pair-copula family matrix
family <- c(0, 1, 3, 4, 4,
            0, 0, 3, 4, 1,
            0, 0, 0, 4, 1,
            0, 0, 0, 0, 3,
            0, 0, 0, 0, 0)
family <- matrix(family, 5, 5)
# define R-vine pair-copula parameter matrix
par <- c(0, 0.2, 0.9, 1.5, 3.9,
         0, 0, 1.1, 1.6, 0.9,
         0, 0, 0, 1.9, 0.5,
         0, 0, 0, 0, 4.8,
         0, 0, 0, 0, 0)
par <- matrix(par, 5, 5)
# define second R-vine pair-copula parameter matrix
par2 <- matrix(0, 5, 5)

## define RVineMatrix object
RVM <- RVineMatrix(Matrix = Matrix, family = family,
                   par = par, par2 = par2,
                   names = c("V1", "V2", "V3", "V4", "V5"))
## simulate a sample of size 500 from the R-vine copula model
set.seed(123)
simdata <- RVineSim(500, RVM)

## determine the pair-copula families and parameters
RVM1 <- RVineCopSelect(simdata, familyset <- c(0,1,2,3,4,5,6,13:16,23:26,33:36), Matrix)

## see the object's content or a summary
str(RVM1)
summary(RVM1)

## inspect the fitted model using plots
plot(RVM1)  # tree structure

contour(RVM1)  # contour plots of all pair-copulas>
## simulate a sample of size 500 from the R-vine copula model
set.seed(123)
simdata <- RVineSim(500, RVM)

## determine the pair-copula families and parameters
RVM1 <- RVineCopSelect(simdata, familyset <- c(0,1,2,3,4,5,6,13:16,23:26,33:36), Matrix)
#> Error in FUN(X[[i]], ...) : object 'out' not found

The error does not occur if only the the families from the example (c(1, 3, 4, 5 ,6)) are used.

How to set up vine copula model with different margins in vine_dist() and a possible bug in rvinecoplib

Hi prof. Thomas,

I just wonder how could we set up a vine copula model with different margins in vine_dist() function. I found the following example in rvinecoplib (pdf),

set up vine copula model with Gaussian margins
vc <- vine_dist(list(distr = "norm"), pcs, mat)

however, how about different margins types. For example, suppose that I have 4 variables, with four different margins! how could we specify them in vine_dist() function?

I tried this:

VC1 <- vine_dist(list(list(distr = "norm"), list(distr="beta")),pcs, mat)
but got an error:
Error in vine_dist(list(list(distr = "norm"), list(distr = "beta")), pcs, mat, :
marg should have length 1 or dim(structure)[1]

I set up a vine copula model with Gaussian margins, however, I face the following:

VC1$copula
7-dimensional vine copula model ('vinecop_dist')
VC1$loglik
[1] NA

VC1$npars
numeric(0)

I really do not know if this is a possible bug or it is fine.

Thank you.

about the RVineMLE$message

When I use RvineMLE(){VineCopula}, I get the following system feedback.

$message
[1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"

It reports an error when importing into rvinematrix(), showing.
In RVineMatrix: The parameter of the Frank copula has to be unequal to 0.
I'm not sure why the parameter of the Frank copula is 0 and whether it's related to the message above.Code is as follows

RVM<-RVineStructureSelect(copula_data1,c(1:6),progress = TRUE,rotations = FALSE)
RVM1<-RVineCopSelect(copula_data1,familyset=c(1:6),RVM$Matrix,rotations = FALSE)
RVM2<-RVineSeqEst(copula_data1,RVM1) 
mle<-RVineMLE(copula_data1,RVM1)
vine_matrix<-RVineMatrix(mle$RVM$Matrix,family =mle$RVM$family,names=mle$RVM$names,par2 =mle$RVM$par2 )]

Bug in RVineMLE?

Line 501 in RVineMLE.R seems to be wrong:

newpar2[posParams] <- out1$par[(nParams + 1):(nParams + nParams2)]

I think the subsetting should be on posParams2 rather than posParams.

I ran some code in which posParams was of length 3 but posParams2 only of length 2, which led to a warning.

EDIT: Vaguely related: line 513 is dangerous as there's no test that nParams2 > 0 here. I'd suggest replacing

(nParams + 1):(nParams + nParams2)

with

nParams1 + seq_len(nParams2)

throughout the function, as it prevents these problems.

P.S. The package is very useful, thanks for making it!

Error in RVineMatrixCheck

RVineMatrixCheck does not function properly if the matrix entered is not upper or lower triangular:

RVM
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 0 0 0 0 0 0 0 0 0
[2,] 0 9 0 0 0 0 0 5 0 0
[3,] 0 0 10 0 0 0 6 6 0 0
[4,] 0 0 0 6 0 8 7 3 0 0
[5,] 0 0 0 0 2 6 10 9 0 0
[6,] 0 0 0 3 8 8 8 8 0 0
[7,] 0 0 4 4 4 7 7 4 0 0
[8,] 0 3 7 8 3 5 3 5 0 0
[9,] 4 4 3 7 7 2 4 10 4 0
[10,] 3 5 5 5 2 4 2 2 3 3

RVineMatrixCheck(RVM)
Error in A2[i, j] <- iorder[A[i, j]] : replacement has length zero

I think a single check if an upper/lower triangular matrix is entered should fix the problem. Nevertheless, a sufficiently intelligent user would know that this matrix can not be an R-vine matrix.

Parameter restrictions for Archimedean copulas

Most functions for Archimedean copulas run into numerical problems when the absolute value of Kendall's tau is close to 1. The critical value varies between families and functions. We should:

  • find critical values for each family
  • prevent selection algorithms from selecting a family when the corresponding critical value is exceeded
  • throw warnings or errors when infeasible parameter values were specified manually.

Update/correct GOF tests for vines

The GOF tests for vine copulas implemented in the package return so far only a correct test statistics. Some also do return a p-value. But these p-values are highly experimental and its calculation not yet checked.
Asymptotic p-values should be treated with high causious.
Further, some tests have bootstarpped p-values, but I never had the time to check if the C-code is working corretly.

Bug near CDF = 1 in BiCopPDF

I was comparing BiCopPDF to dCopula and got nearly perfect agreement, but ~0.1% of the values would strongly disagree, with BiCopPDF getting something O(10^5) and dCopula getting 0. It turns out this is when the CDF value of the input is near the maximum. I made the following minimum working example:

library(VineCopula)
data <- matrix(data=runif(200), ncol=2)
copula <- BiCopSelect(data[,1], data[,2], familyset=1, selectioncrit="AIC", indeptest=F, rotations=FALSE)
print(BiCopPDF(0.99 , 0.9999, copula))
print(BiCopPDF(0.9999 , 0.9999, copula))
print(BiCopPDF(0.99999999 , 0.99999999, copula))
print(BiCopPDF(1 , 1, copula))

With this example, I get different values every time I run this, with the last number in the printout giving anything from 0.0001 to 8.

Error in strsplit

I ran RVineStructureSelect. I have 13 variables and got several bivariates combinations as NA. finally i got an error such as below. I am able to get a summary, Matrix, trees and Plot too. But it does not have some of the variables. What could be the interpretation of the following error. Please help.

Error in strsplit(g$V$names[con[1]], split = " *[,;] *") :
non-character argument

Thanks and Regards

Sudhanshu

fitCopula unused argument error

Hi,

I'm having the following issue with the fitCopula function, the error is reproducible with the sample code.
R version: 3.3.3 (2017-03-06)
The issue occurs both with the CRAN version and with freshly cloned github version

t.cop <- r90TawnT2Copula()
u <- pobs(rnorm(1:1e3))
v <- pobs(rnorm(1:1e3))
fit <- fitCopula(copula = t.cop, data = matrix(c(u,v), byrow = TRUE, ncol = 2), method='ml')

error msg : Error in .local(u, copula, log, ...) : unused argument (checkPar = FALSE)

The problem is also visible in stack overflow threads:
https://stackoverflow.com/questions/43690221/fitcopula-yielding-checkpar-error
https://stackoverflow.com/questions/41807482/fitcopula-for-bivariate-data-in-r

Do you know any solution to the problem?

BR,
Szilard

Reduce number of dependencies

Hi,

I would like to reduce the number of packages we rely on. Do we realy need them all?
Can we transfer some of them to "Suggest"?
For which function do we need "methods" or "grDevices"?

Best
Ulf

BiCopEst for boundary case

Hi,

theta <- BiCopTau2Par(family, tau)
fails explicitly if empirical tau is outside of valid range (e.g. tau = -epsilon for Clayton). At least for MLE, parameters should be moved to closest boundary (e.g. 1e-4 for tau = -epsilon for Clayton) in those cases imo.

KR, Andreas

familyset not working in RVineStructureSelect

Hi, I am using VineCopula version 2.3.0. This issue can be produced with the example code related to RVineStructureSelect:

# load data set
data(daxreturns)
daxreturns <- daxreturns[1:250, 1:4]
RVM <- RVineStructureSelect(daxreturns, c(1:6), progress = TRUE)
summary(RVM)

And the following result is given from the summary:

tree     edge | family  cop   par  par2 |  tau   utd   ltd 
---------------------------------------------------------- 
   1      2,3 |      2    t  0.65  2.48 | 0.45  0.44  0.44
          1,2 |      2    t  0.61  3.55 | 0.42  0.35  0.35
          4,1 |     14   SG  1.62  0.00 | 0.38     -  0.46
   2    1,3;2 |      5    F  1.11  0.00 | 0.12     -     -
        4,2;1 |      4    G  1.22  0.00 | 0.18  0.24     -
   3  4,3;1,2 |      5    F  1.18  0.00 | 0.13     -     -
---
type: D-vine    logLik: 187.94    AIC: -359.87    BIC: -331.7    
---
1 <-> ALV.DE,   2 <-> BAS.DE,   3 <-> BAYN.DE,   4 <-> BMW.DE

Although the familyset is set as c(1:6), the selected families in the Rvine trees may contain others like 14.

Flexible edge weights for the tree structure selection

It may be a good idea to be more flexible in the egde weights for the tree structure stelection in the RVineStructureSelection function.
One sugestion by Harry Joe is to use log(sqrt(1-rho^2)) (I hope I get it right; he will send some code and comments on that).
There can be alot of other possible weights.
Another idea is to allow the user to hand over a function for the calculation of the weights.
So the idea is to add a new argument to RVineStructureSelect
RVineStructureSelect(data, weights="tau")
RVineStructureSelect(data, weights="logtau")
RVineStructureSelect(data, weights=function(u1, u2){doSomeThing(u1,u2)})

Fix for get_family

There seems to be a bug in the family edge label names that appear in plot.RVineMatrix when using edge.labels='family'.

Apologies I haven't made a simple reproducible example, but if the get_family function is edited as below, then it seems to be fixed.

get_family<-function (j, tree, RVM) {
    d <- nrow(RVM$family)
    #M <- RVM$Matrix
    #paste(RVM$family[M[d - tree + 1, j]])
    paste(RVM$family[d - tree + 1, j])
}

Error for GoF test when par/par2 are too close to boundaries

BiCopGofTest throws errors when the parameters are too close to the boundaries. There are two separate issues:

  1. When Kendall's tau is positive (but close to zero) some of the bootstrap samples may have negative Kendall's tau. Many of the implemented families do not allow for positive and negative tau and, thus, the function throws an error.
  2. For the t copula, the gradient is approximated numerically by comparing the derivatives at par2 +- 1e3. When par2 is close to 2, this causes an error.

A reproducible example:

library("VineCopula")
set.seed(1)

## some bivariate copulas
cop1 <- BiCop(3, tau = 0.05)  # tau close to 0
cop2 <- BiCop(4, tau = 0.05)  # tau close to 0
cop3 <- BiCop(2, tau = 0.1, par2 = 2.01)   # df close to 2

## simualte data
sim1 <- BiCopSim(100, cop1)
sim2 <- BiCopSim(100, cop2)
sim3 <- BiCopSim(100, cop3)

## GoF test
BiCopGofTest(sim1[, 1], sim1[, 2], 3)
#> Error: 
#>  In BiCopCheckTaus: Clayton copula cannot be used for tau<=0. 
BiCopGofTest(sim2[, 1], sim2[, 2], 4)
#> Error: 
#>  In BiCopCheckTaus: Gumbel copula cannot be used for tau<0.  
BiCopGofTest(sim3[, 1], sim3[, 2], 2)
#> Error: 
#>  In BiCopDeriv: The degrees of freedom parameter of the t-copula 
#>  has to be larger than 2.

@ulf85: I don't want to mess with your functions. Could you look into that? For the Kendall's tau issue, the solution may require changing something globally in the preprocessors. If so, please check with me before committing.

Parallelize estimation in RVineCopSelect and RVineStructureSelect

The routines RVineCopSelect and RVineStructureSelect should be able to estimate all pair-copulas in a tree in parallel (e.g., using foreach). The functions should get an additional argument cores that specifies how many cores will be used. If cores = 1, the estimation is done without parallelization.

Make GoF C code ISO compatible

My C compiler now gives the following warning:

gof.c: In function ‘Bj’:
gof.c:267:33: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
    qsort(u[j],*d,sizeof(double),(void *)comp_nums);
                                 ^
gof.c:267:4: warning: ISO C forbids passing argument 4 of ‘qsort’ between function pointer and ‘void *’ [-Wpedantic]
    qsort(u[j],*d,sizeof(double),(void *)comp_nums);
    ^
In file included from /usr/lib/R/lib/R/include/R.h:45:0,
                 from include/vine.h:22,
                 from gof.c:1:
/usr/include/stdlib.h:765:13: note: expected ‘__compar_fn_t’ but argument is of type ‘void *’
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
             ^
gof.c: In function ‘SimulateBj’:
gof.c:330:31: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
   qsort(tmp,*d,sizeof(double),(void *)comp_nums);
                               ^
gof.c:330:3: warning: ISO C forbids passing argument 4 of ‘qsort’ between function pointer and ‘void *’ [-Wpedantic]
   qsort(tmp,*d,sizeof(double),(void *)comp_nums);
   ^
In file included from /usr/lib/R/lib/R/include/R.h:45:0,
                 from include/vine.h:22,
                 from gof.c:1:
/usr/include/stdlib.h:765:13: note: expected ‘__compar_fn_t’ but argument is of type ‘void *’
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
             ^

Could you look into that Ulf? It does not cause a WARNING or NOTE in CRAN checks, so it's not urgent.

Differences between CDVine and VineCopula?

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:

  • We are afraid to unintentionally corrupt/ruin our simulation results due to a switch from CDVine to VineCopula in our package dependencies.
  • In particular, ESGtoolkit substituted their dependencies on CDVine with VineCopula methods in their latest release.
  • Due to the recent archivation of CDVine and, hence, packages with a dependency on CDVine, we need to rearrange our package dependencies in the long run. As a shortterm solution we keep the old versions anyhow. See also this issue in the ESGtoolkit repo.

Best wishes and thanks a lot for your time.

Error in uniroot...?

This minimal example, gives me the error below

library(VineCopula)

A1 <- c(0.156862745098039, 0.254901960784314, 0.96078431372549, 0.529411764705882, 0.274509803921569, 0.666666666666667, 0.784313725490196, 0.568627450980392, 0.882352941176471, 0.607843137254902, 0.803921568627451, 0.196078431372549, 0.509803921568627, 0.490196078431373, 0.980392156862745, 0.647058823529412, 0.0588235294117647, 0.176470588235294, 0.235294117647059, 0.294117647058824, 0.431372549019608, 0.470588235294118, 0.941176470588235, 0.627450980392157, 0.313725490196078, 0.92156862745098, 0.725490196078431, 0.450980392156863, 0.686274509803922, 0.901960784313726, 0.0784313725490196, 0.333333333333333, 0.705882352941177, 0.549019607843137, 0.862745098039216, 0.823529411764706, 0.764705882352941, 0.843137254901961, 0.352941176470588, 0.372549019607843, 0.0980392156862745, 0.117647058823529, 0.215686274509804, 0.137254901960784, 0.411764705882353, 0.0196078431372549, 0.0392156862745098, 0.745098039215686, 0.588235294117647, 0.392156862745098)
A2<- c(0.156862745098039, 0.254901960784314, 0.941176470588235, 0.529411764705882, 0.274509803921569, 0.745098039215686, 0.784313725490196, 0.568627450980392, 0.882352941176471, 0.607843137254902, 0.803921568627451, 0.196078431372549, 0.509803921568627, 0.470588235294118, 0.980392156862745, 0.647058823529412, 0.0588235294117647, 0.176470588235294, 0.215686274509804, 0.294117647058824, 0.450980392156863, 0.490196078431373, 0.92156862745098, 0.627450980392157, 0.313725490196078, 0.96078431372549, 0.705882352941177, 0.372549019607843, 0.666666666666667, 0.901960784313726, 0.0784313725490196, 0.352941176470588, 0.686274509803922, 0.549019607843137, 0.843137254901961, 0.823529411764706, 0.764705882352941, 0.862745098039216, 0.392156862745098, 0.333333333333333, 0.0980392156862745, 0.117647058823529, 0.235294117647059, 0.137254901960784, 0.431372549019608, 0.0196078431372549, 0.0392156862745098, 0.725490196078431, 0.588235294117647, 0.411764705882353)

C1 <- BiCopSelect(A1, A2, selectioncrit = "AIC")

Error:

Error in uniroot(function(x) tau - frankTau(x), lower = 0 + .Machine$double.eps^0.5,  : 
  f() values at end points not of opposite sign

Any idea what is happening and how to fix it?

Vectorize parameters

Hi! I'm working with vine copulas where the parameters are not constant. So, for instance, I would like to get a random sample where each sample corresponds to different parameters (like rnorm(10, mean=1:10)), or the likelihood where each observation corresponds to different parameters (like dnorm(1:10, mean=1:10)). As a proof of concept I took the code of RVineSim and rewrote the C part in R (straight forward without optimization). Then I adjusted the code to use 3d arrays in family, par and par2 and it worked. Are there any good reasons why this is not implemented?

NA handling

So far the estimation algorithms simply throw an error whenever NAs appear in the data. This is a reasonable solution implying that users should think of handling NAs themselves reasonably before fitting a vine.

For fitting vines, there are cases when this is problematic. For example when you have time series of different length and want to use as much information as possible for each pair.

My suggestion: Throw a warning, that there are NAs, but use pairwise complete data for each pair. We could also add an option that allows to switch this type of NA handling on and of.

vignette

Is there any chance this package will have a proper vignette with a couple of examples?

Copula diagnostics before vine selection

Some suggestions by Harry Joe: one can do some simple copula diagnostics before one selects the vine or the copula family. For example, as we already do, one estimates Kendall's tau to shrink the families to the positive or negative correlated ones. Similar with tail dependence. In particular asymmetries. Further ideas are given in a short tech report.

Planned, if at all, for version > 2.1

Weird results for the loglikelihood

Hi,

I'm trying to use RVineLogLik function to compute the log likelihoods of a given R-vine RVM_target from datasets created from different R-vines RVM.

If I'm not wrong, the log likelihood should be maximum for a dataset generated from RVM_target. But this is not what I'm observing.

Below is an example in dimension 2 with the following figures showing the variation of the log likelihood for different parameter values and the squared gradient loglikelihood (which is null at the true dependence parameter).

Thanks for your help!

Nazih.

library(VineCopula)
library(ggplot2)

dim <- 2
Matrix <- c(2, 1,
            0, 1)
Matrix <- matrix(Matrix, dim, dim)

family <- c(0, 3,
            0, 0)
family <- matrix(family, dim, dim)

par <- c(0, 0.5,
         0, 0)
par <- matrix(par, dim, dim)
par2 <- matrix(0, dim, dim)

RVM_target <- VineCopula::RVineMatrix(Matrix = Matrix, family = family, par = par, par2 = par2)

n_theta <- 20
n <- 1000
loglik <- rep(NA, n_theta)
grads <- rep(NA, n_theta)
thetas <- seq(0.01, 0.99,length=n_theta)
par_new <- par
for (i in 1:n_theta){
    par_new[2, 1] <- thetas[i]
    RVM_new <- VineCopula::RVineMatrix(Matrix = Matrix, family = family, par = par_new, par2 = par2)
    data <- VineCopula::RVineSim(n, RVM_new)
    res <- VineCopula::RVineLogLik(data, RVM_target, separate = FALSE, calculate.V = FALSE)
    loglik[i] <- res$loglik
    grads[i] <- VineCopula::RVineGrad(data, RVM_target)$gradient
}
df <- data.frame(thetas, loglik, grads)


ggplot(data=df, aes(x=thetas, y=loglik)) +
    geom_point(color="red") +
    geom_smooth(color="grey40") +
    theme_bw()

ggplot(data=df, aes(x=thetas, y=grads**2)) +
    geom_point(color="red") +
    geom_smooth(color="grey40") +
    theme_bw()

plt_likelihood
plt_sq_grad_likelihood

RVineStructureSelect tree problem (RStudio Version 1.3.1073)

with 4 variables, when we choose type= "C-Vine", the tree showed by RVineStructureSelect it not right
tree edge | family cop par par2 | tau utd ltd

1 1,2 | 5 F 29.66 0.00 | 0.87 - -
1,3 | 5 F 27.41 0.00 | 0.86 - -
4,1 | 20 SBB8 6.00 0.86 | 0.64 - -
2 3,2;1 | 3 C 0.18 0.00 | 0.08 - 0.02
4,3;1 | 19 SBB7 1.04 0.34 | 0.16 0.13 0.05
3 4,2;3,1 | 2 t 0.07 20.94 | 0.05 0.00 0.00

type: C-vine logLik: 1097.97 AIC: -2177.94 BIC: -2149.45

Theorical : it must be as follow: 12;13;41 (tree 1); 42|1; 43|1 (tree 2); 23|14 (tree 3)

New vine selection heuristic

There is another (new) heuristic by Harry Joe and Eike Brechmann to select a vine copula structure.
The Main idea is the following:
Estimate all partial correlations and use them as edge weights
The selection of the vine structure is under the assumption of normality. Thus no copula families have to be selected in the first place.
Further, no pseudo observations for the higher order trees have to be calculated since the partial correlations are given.
A Further expansion stage may be the next ideas of Joe and Brechmann:
Instead of using just the one maximum spanning tree, use the Best 10 spanning trees.
Thereby the search area is bigger. But also it growths exponantially. To avoid that there is a heuristic described in the paper.

These heuristics may be options for RVineStructureSelect available by an additional argument.

There is code available by Eike.

BiCopTau2Par for Frank

Hello,
In the estimation of the bivariate Frank copula parameter via Kendall's tau inversion, tau values being larger than 0.96 is causing an error, e.g.,:

BiCopTau2Par(5, 0.966)
Error in uniroot(function(x) tau - frankTau(x), lower = 0 + .Machine$double.eps^0.5,:f() values at end points not of opposite sign

The problem seems to result from the values frankParGrid and frankTauVals in BiCopPar2Tau that should be edited according to #74?

RVineStructureSelect() returns C-Vine even when specified otherwise

Hello,

I'am trying to fit an R-Vine model to my data using RVineStructureSelect(). I specify type=0 so an R-vine structure is selected, however it keeps returning a C-Vine. Could you please tell me what can be the reason for this and how to solve it? I am using R Studio on Windows and the latest Vine Copula package (2.4.1)

RVineStructureSelect example

Issue while running RVineMLE

I get the following error while using the package running the RVineMLE . I am unable to understand the error. Is it a bug or some issue with my usage. Pls help.

mle = RVineMLE(data=dataAsk, RVM, start=0, start2=0, maxit=200, grad=TRUE, hessian=TRUE, se=TRUE)
Error in if (Copula.Types[i] == 5) { :
missing value where TRUE/FALSE needed

Export C function to use in another package

I am trying to export function Hfunc2 to use in my package.
It compiles correctly but can not link the dynamic library,
I make a reproducible package in my github
https://github.com/hoanguc3m/TestVine
When using function Hfunc2 in
https://github.com/hoanguc3m/TestVine/blob/master/src/vinetest.cpp
It turns an error when building the package

installing to /home/hoanguc3m/R/x86_64-pc-linux-gnu-library/3.4/TestVine/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘TestVine’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/hoanguc3m/R/x86_64-pc-linux-gnu-library/3.4/TestVine/libs/TestVine.so':
  /home/hoanguc3m/R/x86_64-pc-linux-gnu-library/3.4/TestVine/libs/TestVine.so: undefined symbol: _Z6Hfunc2PiS_PdS0_S0_S0_S0_
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/hoanguc3m/R/x86_64-pc-linux-gnu-library/3.4/TestVine’
* restoring previous ‘/home/hoanguc3m/R/x86_64-pc-linux-gnu-library/3.4/TestVine’

Exited with status 1.

you have any ideas to fix this. Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.