pymc.LKJCorr#

class pymc.LKJCorr(name, *args, rng=None, dims=None, initval=None, observed=None, total_size=None, transform=UNSET, default_transform=UNSET, **kwargs)[source]#

The LKJ (Lewandowski, Kurowicka and Joe) distribution.

The LKJ distribution is a prior distribution for correlation matrices. If eta = 1 this corresponds to the uniform distribution over correlation matrices. For eta \(\to \infty\) the LKJ prior approaches the identity matrix.

This implementation returns a lower triangular Cholesky factor L, where R = L @ L.T follows the LKJ distribution.

Support

Lower triangular matrices with positive diagonals and unit row norms

Parameters:
ntensor_like of int

Dimension of the covariance matrix (n > 1).

etatensor_like of float

The shape parameter (eta > 0) of the LKJ distribution. eta = 1 implies a uniform distribution of the correlation matrices; larger values put more weight on matrices with few correlations.

Notes

This is mainly useful if you want the standard deviations to be fixed, as LKJCholsekyCov is optimized for the case where they come from a distribution.

References

[LKJ2009]

Lewandowski, D., Kurowicka, D. and Joe, H. (2009). “Generating random correlation matrices based on vines and extended onion method.” Journal of multivariate analysis, 100(9), pp.1989-2001.

Examples

with pm.Model() as model:
    # Define the vector of fixed standard deviations
    sds = 3 * np.ones(10)

    chol_corr = pm.LKJCorr("chol_corr", eta=4, n=10)
    # Optionally save the correlation matrix in the trace
    corr = pm.Deterministic("corr", chol_corr @ chol_corr.T)

    # Define a new MvNormal with the given Cholesky factor
    mv_vals_raw = pm.MvNormal("mv_vals_raw", mu=np.zeros(10), chol=chol_corr, shape=10)
    vals = sds * mv_vals_raw

    # Or transform an uncorrelated normal distribution:
    vals_raw = pm.Normal("vals_raw", shape=10)
    vals = sds * pt.dot(chol_corr, vals_raw)

Methods

LKJCorr.dist(n, eta, **kwargs)

Create a tensor variable corresponding to the cls distribution.