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.

Support

Upper triangular matrix with values in [-1, 1]

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)

    corr = pm.LKJCorr("corr", eta=4, n=10)

    # Define a new MvNormal with the given correlation matrix
    vals = sds * pm.MvNormal("vals", mu=np.zeros(10), cov=corr, shape=10)

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

Methods

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

Create a tensor variable corresponding to the cls distribution.