Closed xiaoai11111 closed 2 years ago
RVineStructureSelect
does not have an argument use
. Did you read the documentation? Also, please provide an example I can reproduce.
sorry, I have read the documentation . But I do not know how to use the custom function that I specified to calculate the edge weights. I need to add code to the source code treecrit
, right?
else if (all(treecrit == "mi")) {
treecrit <- function(u1, u2, weights) {
complete.i <- which(!is.na(u1 + u2))
if (length(complete.i) < 10) {
mi <- 0
} else {
complete.freq <- mean(!is.na(u1 + u2))
mi <- function(mylist1,mylist2){
return(entropy(mylist1)+entropy(mylist2)-entropy(cbind(mylist1,mylist2)))
}
mi * sqrt(complete.freq)
}
}
}
No, you just write
RVineStructureSelect(daxreturns, treecrit = your_function)
As mentioned in the documentation, your_function
has to have the signature function(u1, u2, weights)
.
Thans for your help! I write like this
RVM1 = RVineStructureSelect(m1,family = c(1:6),progress = TRUE,se =
TRUE,treecrit=function(u1,u2,weights){
mutinformation(discretize(u1,numBins=4), discretize(u2,numBins=4), method="emp")
},rotations = TRUE)
but it do not become effective like tau
. Could you please tell me what should I do next step?
What do you mean it does not "become effective"?
if I write return(1) , the results are same as above code , it mains that it does not calculate the custom function: mutinformation
RVM1 = RVineStructureSelect(m1,family = c(1:6),progress = TRUE,se =
TRUE,treecrit=function(u1,u2,weights){
return(1)
},rotations = TRUE)
No it just means that the results are the same on your data set. Here is a reproducible example to see that it has an effect:
## load data set (part of VineCopula)
data(daxreturns)
daxreturns <- daxreturns[1:250, 1:4]
## this produces a C-vine
my_fun <- function(u1, u2, weights) {
message("computing my_fun()")
return(1)
}
RVineStructureSelect(daxreturns, family = 1:6, treecrit = my_fun)
## this produces a different C-vine
my_fun2 <- function(u1, u2, weights) {
message("computing my_fun2()")
return(u2[1])
}
RVineStructureSelect(daxreturns, family = 1:6, treecrit = my_fun2)
# this produces a D-vine
RVineStructureSelect(daxreturns, family = 1:6, treecrit = "tau")
If you think there is a bug or have other problems, please provide a reproducible example and clearly describe expected and observed behavior. Closing this issue for now...
How can I modify the code if i want to use mutual information to calculate the edge weights ? I tried it with your reminder, but it ran wrong mi<-function(mylist1,mylist2){ return(entropy(mylist1)+entropy(mylist2)-entropy(cbind(mylist1,mylist2))) } RVineStructureSelect(m1,family = c(1:6),progress = TRUE,se = TRUE,method ='itau',use='mi',rotations = TRUE) Error in RVineStructureSelect(m1, family = c(1:6), progress = TRUE, : unused argument (use = "mi")