Bug near CDF = 1 in BiCopPDF
cag472 opened this issue · comments
I was comparing BiCopPDF to dCopula and got nearly perfect agreement, but ~0.1% of the values would strongly disagree, with BiCopPDF getting something O(10^5) and dCopula getting 0. It turns out this is when the CDF value of the input is near the maximum. I made the following minimum working example:
library(VineCopula)
data <- matrix(data=runif(200), ncol=2)
copula <- BiCopSelect(data[,1], data[,2], familyset=1, selectioncrit="AIC", indeptest=F, rotations=FALSE)
print(BiCopPDF(0.99 , 0.9999, copula))
print(BiCopPDF(0.9999 , 0.9999, copula))
print(BiCopPDF(0.99999999 , 0.99999999, copula))
print(BiCopPDF(1 , 1, copula))
With this example, I get different values every time I run this, with the last number in the printout giving anything from 0.0001 to 8.
I am not sure what you see as a bug in your example code.
Note that the true value of the Gaussian copula pdf at (1,1) would be Inf
for rho > 0
and 0 for rho < 0
. To avoid numerical instability, VineCopula never evaluates the density at values smaller than 1e-10
or larger than 1 - 1e-10
. So:
> print(BiCopPDF(1 - 1e-10 , 1 - 1e-10, copula))
#> [1] 17.49833
> print(BiCopPDF(1 , 1, copula))
#> [1] 17.49833