Helpful Stan Functions
|
Functions | |
real | normal_copula_lpdf (real u, real v, real rho) |
real | normal_copula_vector_lpdf (vector u, vector v, real rho) |
real | bivariate_normal_copula_cdf (real u, real v, real rho) |
real | multi_normal_cholesky_copula_lpdf (matrix U, matrix L) |
The normal copula is an elliptical copula over the unit cube \([0,\,1]^d \).
real bivariate_normal_copula_cdf | ( | real | u, |
real | v, | ||
real | rho | ||
) |
Bivariate Normal Copula cdf
Meyer, Christian. "The Bivariate Normal Copula."
arXiv preprint arXiv:0912.2816 (2009). Eqn 3.11.
accessed Feb. 6, 2021.
u | Vector size 2 |
rho | Real on (-1, 1) |
real multi_normal_cholesky_copula_lpdf | ( | matrix | U, |
matrix | L | ||
) |
Multivariate Normal Copula log density (Cholesky parameterisation)
\begin{aligned} c(\mathbf{u}) &= \frac{\partial^d C}{\partial \mathbf{\Phi_1}\cdots \partial \mathbf{\Phi_d}} \\ &= \prod_{i=1}^{n} \lvert \Sigma \rvert^{-1/2} \exp \left\{-\frac{1}{2} \begin{pmatrix} \mathbf{\Phi}^{-1}(u_1) \\ \vdots \\ \mathbf{\Phi}^{-1}(u_d) \end{pmatrix}^T (\Sigma^{-1} - I) \begin{pmatrix} \mathbf{\Phi}^{-1}(u_1) \\ \vdots \\ \mathbf{\Phi}^{-1}(u_d) \end{pmatrix} \right\} \\ &= \lvert \Sigma \rvert^{-n/2} \exp\left\{ -\frac{1}{2} \text{tr}\left( \left[ \Sigma^{-1} - I \right] \sum_{i=1}^n \Phi^{-1}(u_i) \Phi^{-1}(u_i)' \right) \right\} \hspace{0.5cm} \\ &= \lvert L \rvert^{-n} \exp\left\{ -\frac{1}{2} \text{tr}\left( \left[ L^{-T}L^{-1}- I \right] Q'Q \right) \right\} \\ &= \lvert L \rvert^{-n} \exp\left\{ -\frac{1}{2} \sum_{j=1}^{d}\sum_{i=1}^{n} \left( \left[ L^{-T}L^{-1}- I \right] \odot Q'Q \right) \right\} \\ \end{aligned}
where
\[ Q_{n \times d} = \begin{pmatrix} \mathbf{\Phi}^{-1}(u_1) \\ \vdots \\ \mathbf{\Phi}^{-1}(u_d) \end{pmatrix} \]
and \( \odot \) is the elementwise multiplication operator.
Note that \(\det \Sigma = |LL^T| = |L |^2 = \big(\prod_{i=1}^d L_{i,i}\big)^2\) so \(\sqrt{\det \Sigma} = \prod_{i=1}^d L_{i,i}\).
U | Matrix of outcomes from marginal calculations |
L | Cholesky factor of the correlation/covariance matrix |
real normal_copula_lpdf | ( | real | u, |
real | v, | ||
real | rho | ||
) |
Normal copula log density
\[ c(u,\,v;\, \rho) = \frac{1}{\sqrt{1 - \rho^2}} \exp \bigg( \frac{2\rho \Phi^{-1}(u) \Phi^{-1}(v) - \rho^2 (\Phi^{-1}(u)^2 + \Phi^{-1}(v)^2)}{2 (1 - \rho^2)}\bigg) \]
Meyer, Christian. "The Bivariate Normal Copula."
arXiv preprint arXiv:0912.2816 (2009). Eqn 3.3.
accessed Feb. 6, 2021.
u | Real number on (0,1], not checked but function will return NaN |
v | Real number on (0,1], not checked but function will return NaN |
rho | Real number (-1, 1) |
real normal_copula_vector_lpdf | ( | vector | u, |
vector | v, | ||
real | rho | ||
) |
Normal copula log density vectorized
Meyer, Christian. "The Bivariate Normal Copula."
arXiv preprint arXiv:0912.2816 (2009). Eqn 3.3.
accessed Feb. 6, 2021.
u | Real number on (0,1], not checked but function will return NaN |
v | Real number on (0,1], not checked but function will return NaN |
rho | Real number (-1, 1) |