Coder Social home page Coder Social logo

BiCopTau2Par for Frank about vinecopula HOT 10 CLOSED

tnagler avatar tnagler commented on June 20, 2024
BiCopTau2Par for Frank

from vinecopula.

Comments (10)

tnagler avatar tnagler commented on June 20, 2024

I think you're right. Could you submit a pull request with a fix?

from vinecopula.

oezgesahin avatar oezgesahin commented on June 20, 2024

Sure, but I am unsure from a theoretical point of view. For the bivariate Frank copula with parameter theta, it holds:
tau = 1 - 4/theta + 4/theta*D(theta), where D: debye function.
So, for theta=500, I am obtaining tau=0.99:

frankPar <- 500
tau <- 1 - 4/frankPar + 4/frankPar * copula::debye1(frankPar)
tau 
[1] 0.9920263

It implies that the maximum tau value with our upper bound (35) would be around 0.89.

frankPar <- 35
tau <- 1 - 4/frankPar + 4/frankPar * copula::debye1(frankPar)
tau 
[1] 0.8910855

How should we proceed?

from vinecopula.

tnagler avatar tnagler commented on June 20, 2024

Actually, the easiest should be to restrict the parameter range when root solving here. Right now, a parameter > 35 could result from calcPar(), but it would be truncated immediately after here. So truncating already in calcPar() wouldn't make things worse. In that case, we could also recompute the lookup table with a narrower range.

What do you think?

from vinecopula.

oezgesahin avatar oezgesahin commented on June 20, 2024

Thanks! I think that we could make the grid and its corresponding values wider so that it can compute the parameter-tau relationship until tau=0.99 with the theoretical formula. Accordingly, we should extend the parameter range in root solving to make sure that lower and upper bounds return opposite signs as required. For any tau value > 0.89, the returned parameter value will be 35 in this scenario. Does that make sense?

from vinecopula.

oezgesahin avatar oezgesahin commented on June 20, 2024

Also, do you know why these (1, 2) are commented and values are written one by one instead?

from vinecopula.

tnagler avatar tnagler commented on June 20, 2024

But what's the point in making the grid wider, if the result is 35 anyway? Can't we just restrict the root solving range then?

We store the values one by one, so VineCopula does not depend on the copula package (and as a result also gsl, which requires extra system libraries on linux and mac).

from vinecopula.

oezgesahin avatar oezgesahin commented on June 20, 2024

If I am not mistaken:
approx is interpolating given the grid values for par (x) and tau (y). Therefore, max tau value it can work is bounded by the upper limit of the tau grid. Thus, when we restrict root solving range without making the grid wider, uniroot function could still return positive (tau-interpolation) values for tau > 0.96 in the upper bound, which prevents it from finding a root. Making the grids wider up to tau = 0.99 and adjust the upper bound (app. 500) accordingly should approximate the theoretical relationship with one difference that any parameter > 35 will be truncated to 35.
Without adjusting the grid but changing uniroot range:

frankParGrid <- seq(-100, 100, l = 100)
frankTauVals <- 1 - 4/frankParGrid + 4/frankParGrid * copula::debye1(frankParGrid)
tau <- 0.99
v <- uniroot(function(x) tau - frankTau(x),
              lower = 0 + .Machine$double.eps^0.5, upper = 35,
              tol = .Machine$double.eps^0.5)$root
Error in uniroot(function(x) tau - frankTau(x), lower = 0 + .Machine$double.eps^0.5,  : 
  f() values at end points not of opposite sign

Suggestion:

frankParGrid <- seq(-500, 500, l = 100)
frankTauVals <- 1 - 4/frankParGrid + 4/frankParGrid * copula::debye1(frankParGrid)
tau <- 0.99
v <- uniroot(function(x) tau - frankTau(x),
             lower = 0 + .Machine$double.eps^0.5, upper = 500,
             tol = .Machine$double.eps^0.5)$root
# v will be truncated to 35
v
[1] 398.3634

from vinecopula.

tnagler avatar tnagler commented on June 20, 2024

Ah yeah, I get it. Then even better:

frankParGrid <- c(-10^(5:2), seq(-36, 36, l = 100), 10^(2:5))
frankTauVals <- 1 - 4/frankParGrid + 4/frankParGrid * copula::debye1(frankParGrid)
frankTau <- function (par) approx(x = frankParGrid, y = frankTauVals, xout = par)$y
tau <- 0.99
v <- uniroot(function(x) tau - frankTau(x),
             lower = 0 + .Machine$double.eps^0.5, upper = 1e5,
             tol = .Machine$double.eps^0.5)$root
# v will be truncated to 35
v

That way we don't lose accuracy in the [-35,35] range but can handle taus up to 0.9999.

from vinecopula.

oezgesahin avatar oezgesahin commented on June 20, 2024

Agreed, great!

from vinecopula.

tnagler avatar tnagler commented on June 20, 2024

solved by #79

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.