-
Notifications
You must be signed in to change notification settings - Fork 20
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
Wrong get_pdf formula for Gaussian copula #11
Comments
Hi @shudabee, The function was corrected by @ioannisrpt, since using Here is a proof that @ioannisrpt's code is correct: Given a correlation coefficient where where where Given that and Thus, the Gaussian copula density can be expressed as follows: where import numpy as np
from scipy.special import erfinv
a = np.sqrt(2) * erfinv(2 * u - 1)
b = np.sqrt(2) * erfinv(2 * v - 1)
det_rho = 1 - rho**2
return det_rho**-0.5 * np.exp(-((a**2 + b**2) * rho**2 -2 * a * b * rho) / (2 * det_rho)) is correct. If you are not convince, I believe following this approach will give the same results: with the corresponding python code: from scipy.stats import norm, multivariate_normal
def get_pdf(u, v, param):
rho = param[0]
y1 = norm.ppf(u, 0, 1)
y2 = norm.ppf(v, 0, 1)
multivariate_normal.pdf((y1,y2), mean=None, cov=[[1,rho],[rho,1]])/(u*v) |
In the pdf computation for Gaussian copula, the formula in the last row is wrong.
def get_pdf(self, u, v, param):
"""
# Computes the PDF
it should be 1/(2 * np.pi * np.sqrt(det_rho)) * np.exp(-((a2 + b2) * rho**2 -2 * a * b * rho) / (2 * det_rho))
The text was updated successfully, but these errors were encountered: