Multivariate lognormal distribution in Stan

We don’t have a multivariate lognormal built in, but it’s easy to code by inverse transforming a multivariate normal.

data {
  cov_matrix[3] Sigma;
}
transformed data {
  cholesky_factor_cov[3] L_Sigma = cholesky_decompose(Sigma);
}
parameters {
  vector[3] log_beta;  
}
transformed parameters {
  vector[3] beta = exp(log_beta);
}
model {
  log_beta ~ multi_normal_cholesky(mu, L_Sigma);
}

This implies that beta has a multi_lognormal(mu, Sigma) distribution, where Sigma = L_Sigma * L_Sigma'. With this code, you can use beta just as you would had it been given a multivariate lognormal directly.

Multivariate logistic normal works the same way, only with inv_logit() in place of exp().

[edit: added he covariance matrix as data and its cholesky factor as a transform—you could also take this to be a parameter, for which you might consider the LKJ prior on a cholesky factor of correlation matrices scaled by a vector of scales with their own independent prior]

5 Likes