Coder Social home page Coder Social logo

Comments (10)

tnagler avatar tnagler commented on June 20, 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.

from vinecopula.

chienyutseng avatar chienyutseng commented on June 20, 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)

from vinecopula.

tnagler avatar tnagler commented on June 20, 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")

from vinecopula.

chienyutseng avatar chienyutseng commented on June 20, 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?

from vinecopula.

tnagler avatar tnagler commented on June 20, 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.

from vinecopula.

chienyutseng avatar chienyutseng commented on June 20, 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

from vinecopula.

tnagler avatar tnagler commented on June 20, 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.

from vinecopula.

chienyutseng avatar chienyutseng commented on June 20, 2024

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?

from vinecopula.

tnagler avatar tnagler commented on June 20, 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.

from vinecopula.

chienyutseng avatar chienyutseng commented on June 20, 2024

Really appreciate for the assistance!

from vinecopula.

Related Issues (20)

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.