Working out an SEM-style alternative to the multivariate normal

Writing out a vine copula would be interesting to test. For this simulation you create a 3 variable latent marginal model with 3 bivariate gaussian copulas. I’m not sure of anyone writing vine copulas in Stan so there are no examples.

There’s a post about vine copulas at

and the bivariate normal copula is

 /**
   * Normal copula log density vectorized
   *
   * @copyright Sean Pinkney, 2021
   *
   * Meyer, Christian. "The Bivariate Normal Copula." \n
   * arXiv preprint arXiv:0912.2816 (2009). Eqn 3.3. \n
   * accessed Feb. 6, 2021.
   *
   * @param u Real number on (0,1], not checked but function will return NaN
   * @param v Real number on (0,1], not checked but function will return NaN
   * @param rho Real number (-1, 1)
   * @return log density
   */
real normal_copula_vector_lpdf(vector u, vector v, real rho){
   int N = num_elements(u);
   real rho_sq = square(rho);
   
   real a1 = 0.5 * rho;
   real a2 = rho_sq - 1;
   real a3 = 0.5 * log1m(rho_sq);
   real x = -2 * u' * v + rho * (dot_self(u) + dot_self(v));
  
  return a1 * x / a2 - N * a3;
}
1 Like