Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitution of dducopula? #90

Closed
chienyutseng opened this issue Jan 15, 2024 · 10 comments
Closed

substitution of dducopula? #90

chienyutseng opened this issue Jan 15, 2024 · 10 comments

Comments

@chienyutseng
Copy link

Hi, I am trying to do the decomposition(pairwise) conditional sampling from vine distributions.
I did found the example from VC2copula:

H <- rnorm(100)
D <- rnorm(100)
I <- rnorm(100)
 
u_H <- pobs(H)
u_D <- pobs(D) 
u_I <- pobs(I)
 
C_HD <- BB1Copula()
C_HIgivenD <- BB1Copula()  
 
k <- ddvCopula(cbind(u_H, u_D), C_HD)
m <- dduCopula(cbind(u_D, u_I), C_DI)
cond_prob <- dduCopula(cbind(k, m), C_HIgivenD)

but I encountered a problem, if I change the pair-copula "BB1Copula()" to "BiCop(family = 1, par =0.36)", the ddvCopula function won't work.
so I tried to build the variables "k" and "m" by "BiCopHinv()", however, got stuck at the " dduCopula(cbind(k, m), C_HIgivenD)", when trying to derivative multiple variables.
I am wondering if I failed to find the substitution of dduCopula in VineCopula or if there's some issue with my current understanding.

@tnagler
Copy link
Owner

tnagler commented Jan 15, 2024

Hi! Your example doesn't run, C_DI is not defined. Please also provide code for the cases where an error occurs, so I don't have to guess what to replace.

@chienyutseng
Copy link
Author

chienyutseng commented Jan 15, 2024

Apologize for the typo, i did defined C_DI at my local side and the example can worked. What couldn't work is when i try to replace BB1Copula() to BiCop(), as code show below

H <- rnorm(100)
D <- rnorm(100)
I <- rnorm(100)
 
u_H <- pobs(H)
u_D <- pobs(D) 
u_I <- pobs(I)

C_HD <- BiCop(family = 1, par =0.36)
C_DI <- BiCop(family = 1, par =0.53)
C_HIgivenD <- BiCop(family = 1, par =0.54)
 
k <- ddvCopula(cbind(u_H, u_D), C_HD)
m <- dduCopula(cbind(u_D, u_I), C_DI)
cond_prob <- dduCopula(cbind(k, m), C_HIgivenD)

@tnagler
Copy link
Owner

tnagler commented Jan 15, 2024

OK, a few things:

  1. The code you're writing is not for conditional sampling, it computes a conditional probability. Conditional sampling is the inverse of the transformation you're computing.
  2. You cannot use copula::ddvCopula() with VineCopula::BiCop objects. You have to replace the BiCop() calls with BiCop2copula().
  3. Even then, the corresponding ddvCopula()and dduCopula() methods were not defined in the VC2copula package (my bad). This is fixed in the dev branch. You can update using remotes::install_github("tnagler/VC2copula@dev")

@chienyutseng
Copy link
Author

chienyutseng commented Jan 15, 2024

Thank you for your supplement.
According to what you mentioned first, what i trying to do is conditional sampling, as the formula below, which is what i am having trouble with.

x1 = w1, x2 = F^-1(w2|x1), x3 = F^-1(w3|x1, x2),
with F(x j |x1, . . . , x j−1) = ∂ C j, j−1|1,..., j−2 {F(x j |x1, . . . , x j−2), F(x j−1|x1, . . . , x j−2)} / ∂ F(x j−1|x1, . . . , x j−2)

if i wasn't wrong,i can get x2 from VineCopula::BiCopHinv, but is there any function for getting x3 from given x1 and x2?

@tnagler
Copy link
Owner

tnagler commented Jan 15, 2024

  • The formula is for unconditional sampling.
  • You can use VineCopula::RVineSim(N, RVM, U=W) where W is a matrix containing w1,w2,w3 from your example in the columns. You can also use this for conditional sampling, assuming the RVineMatrix is set up appropriately (variables you condition on have to be furthest up on the diagonal) and you use RVinePIT() before on the conditioning values. Do you have a reference for what you're trying to implement?
  • For manual computation, you have to chain inverse and regular h-functions, but getting this right is not easy.

@chienyutseng
Copy link
Author

chienyutseng commented Jan 15, 2024

The following snapshot(Kjersti et al., 2007), is what I trying to do.
i have gotten a fitted 3D CVine Copula(for variable X,Y,Z) from my observation:

** Tree: 0
2,1 <-> Gaussian, parameters = 0.485697
1,3 <-> Gaussian, parameters = 2.10785
** Tree: 1
2,3 | 1 <-> Joe 90°, parameters = -1.08

The algorithm I planned to build is getting X from another Copula and viewed as observation, then representing as conditional value for the 3D CVine copula, and getting Y & Z by the pair-copulae decomposed model.

image

@tnagler
Copy link
Owner

tnagler commented Jan 15, 2024

OK, the three dimensional example is fairly easy:

RVM <- C2RVine(1:3, family = c(1, 4, 6), par = c(0.3, 2.4, 1.5))
W <- cbind(w1 = 0.2, runif(100), runif(100))
RVineSim(100, RVM, U = W)

Here we're simulating x1, x2, x3 conditional on x2 = 0.2. You can adapt this to your liking.

@chienyutseng
Copy link
Author

thanks a alot! i think this is what i want. but please allow me to ask futher questions.

I am seeking clarification on the specific scenarios in which the pair-copula decomposition model is most appropriately applied. Many journals refer to this method in the context of vine-copula simulations, and I was under the impression that this methodology should be applied for my needs. Could you please provide some insight on this?

@tnagler
Copy link
Owner

tnagler commented Jan 15, 2024

I can't really answer this question without knowing much more about your application context. But if you want to simulate two variables conditional on one other variable, this is a viable method. Closing this now, since the software part seems to be solved.

@tnagler tnagler closed this as completed Jan 15, 2024
@chienyutseng
Copy link
Author

Really appreciate for the assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants