tnagler / VineCopula

Statistical inference of vine copulas
87 stars 32 forks source link

RVineCDF #95

Closed weiqianxi1314 closed 1 week ago

weiqianxi1314 commented 2 months ago

I want to know why there is an RVinePDF function, but not an RVineCDF function. Many times, it is necessary to calculate the cumulative probability without a corresponding method function.

tvatter commented 2 months ago

While a vine's PDF admits a closed-form expression, its CDF does not.

Note that the rvinecopulib package provides a pvinecop method which computes the vine's CDF via quasi Monte Carlo integration.

kingatua commented 1 week ago

Could someone give me a clue on how to calculate the VineCDF, i have hit a dead end here.

tvatter commented 1 week ago

What exactly did you try? As mentioned, there is no RVineCDF in VineCopula, but you are welcome to use rvinecopulib, or implementing a Monte Carlo version... A quick example:

RVineCDF <- function(u, N, RVM, seed=42) {
  # Set random seed
  set.seed(seed)

  # Simulate N quasi-random numbers from the vine model
  u_sim <- RVineSim(N, RVM)

  # Initialize output vector
  n <- nrow(u)
  vine_distribution <- numeric(n)

  # Compute the cumulative distribution
  for (i in seq_len(n)) {
    temp <- u[i, ]

    # Calculate the maximum difference row-wise between u_sim and temp
    x <- apply(u_sim, 1, function(row) max(row - temp))

    # Count occurrences where all differences are <= 0
    vine_distribution[i] <- sum(x <= 0)
  }

  # Return normalized cumulative distribution
  return(vine_distribution / N)
}
tnagler commented 1 week ago

Solved by #97.