Skip to contents

Summarises the posterior of the marginal correlation matrix \(\rho_{jj'}\) implied by a ZI_MLN() fit. For each retained draw the marginal correlation is computed from the covariance \(\Omega = \Lambda\Lambda' + (\sigma^2 + u_s^2) I\) as cov2cor(tcrossprod(Lambda) + diag(vs2 + sig2, J)), and the draws are then summarised element-wise.

Usage

posterior_correlation(fit, ci = FALSE, prob = c(0.025, 0.975))

Arguments

fit

A list returned by ZI_MLN() (one element per posterior draw).

ci

Logical; if TRUE also return element-wise credible bounds. This builds a J x J x ndraw array and can use substantial memory for large J. Default FALSE (posterior mean only).

prob

Length-2 vector of lower/upper probabilities for the credible interval when ci = TRUE. Default c(0.025, 0.975).

Value

If ci = FALSE, the J x J posterior-mean correlation matrix. If ci = TRUE, a list with mean, lower and upper J x J matrices.

Examples

# \donttest{
sim <- simulate_zimln(n = 20, J = 20, K = 2, seed = 1)
fit <- ZI_MLN(sim$Y, m = sim$m, M = sim$M, niter = 400, burnin = 200)
rho <- posterior_correlation(fit)
# }