Why Correlations Need a Parameterization
In a GLMM with correlated random intercepts and slopes, the random effects for one group are often modeled as a multivariate normal vector. Their covariance matrix must be positive definite, and its correlations must be mutually compatible. HMC, however, updates variables in an unconstrained Euclidean space. Directly proposing each correlation independently does not guarantee a valid matrix: even if every proposed entry lies between \(-1\) and \(1\), the resulting matrix may fail to be positive definite.
The solution is to represent the correlation matrix through unconstrained coordinates and a smooth transformation. HMC then evolves those coordinates, while the transformation produces valid correlations at every finite point in the sampler's parameter space. The choice of coordinates also determines how a prior density must be expressed and which geometric difficulties may remain.
This tutorial concerns the parameterization of \(\Omega\), separately from the positive scale parameters in \(D\). The construction assumes a nonsingular correlation matrix in the interior of the valid space. Boundary cases, such as correlations exactly equal to \(1\) or \(-1\), are not attained at finite unconstrained coordinates. In Bayesian HMC, the log posterior in the unconstrained coordinates must be differentiable wherever the sampler explores it. As in other HMC applications, a transformation does not by itself guarantee good mixing.
A Two-Effect Transformation
For two random effects, there is only one correlation, \(\rho\), with \(-1<\rho<1\). A simple unconstrained coordinate is \(\eta\in\mathbb{R}\), transformed by the hyperbolic tangent:
Every finite \(\eta\) gives a valid correlation, and every interior correlation corresponds to \(\eta=\operatorname{atanh}(\rho)\). The derivative is positive, so the absolute Jacobian is
When the prior is specified as a density \(p_\rho(\rho)\) with respect to \(d\rho\), the density for \(\eta\) with respect to \(d\eta\) is \(p_\eta(\eta)=p_\rho(\tanh(\eta))\,|d\rho/d\eta|\). Equivalently, the log density used by HMC includes the log absolute Jacobian. This correction is required because a density changes when its coordinate scale changes.
Worked Example: Transforming a Uniform Correlation Prior
Suppose a hypothetical two-random-effect model assigns \(\rho\sim\operatorname{Uniform}(-1,1)\). Its density is \(p_\rho(\rho)=1/2\) on that interval. At the unconstrained coordinate \(\eta=0.40\), calculate the transformed correlation, Jacobian, and density for \(\eta\).
The transformed correlation is \(\rho=\tanh(0.40)\approx0.379949\). Using the unrounded value in the derivative gives
Therefore the density on the unconstrained scale is
The density is not constant in \(\eta\), even though the prior is uniform in \(\rho\). The Jacobian makes values of \(\eta\) near zero receive more density per unit of \(\eta\) than values far from zero. Omitting the Jacobian would instead define a different prior, proportional to a constant on the \(\eta\) scale.
Building a Higher-Dimensional Matrix from Partial Correlations
For more than two effects, a useful construction is based on sequential partial correlations. For \(q\) effects, define \(z_{ij}\in(-1,1)\), for \(i=2,\ldots,q\) and \(j=1,\ldots,i-1\). These coordinates are often called partial correlations in the Cholesky or hyperspherical construction. Transform each with \(z_{ij}=\tanh(\eta_{ij})\), where every \(\eta_{ij}\) is unconstrained.
Construct a lower-triangular matrix \(L\) row by row. For row \(i\), set
An empty product is 1, so \(L_{11}=1\). Each row has squared length 1: the terms are successive fractions of the remaining squared length, and the final diagonal term is the remainder. Consequently, \(\Omega=LL^\mathsf{T}\) has diagonal entries 1. Since \(L\) has positive diagonal entries for finite coordinates, it is nonsingular, so \(LL^\mathsf{T}\) is positive definite. Thus this construction produces a valid correlation matrix without constraints on the \(\eta_{ij}\).
Worked Example: Constructing a Three-Effect Correlation Matrix
Consider three hypothetical random effects and choose \(z_{21}=0.30\), \(z_{31}=-0.20\), and \(z_{32}=0.40\). These values lie strictly between \(-1\) and \(1\). The corresponding Cholesky rows are
Multiplying \(LL^\mathsf{T}\) gives \(\Omega\). Its off-diagonal entries are \(\rho_{12}=0.30\), \(\rho_{13}=-0.20\), and
Thus
A positive-definiteness check is available directly from the factorization: \(\det(\Omega)=(\det L)^2\). Here
The positive diagonal of \(L\) and this positive determinant are consistent with a nonsingular positive-definite matrix. The parameterization also explains why the three correlations cannot be chosen independently: \(\rho_{23}\) is determined jointly by the chosen coordinates and the other entries.
Jacobian Corrections and Prior Densities
HMC evaluates a target density in the variables it updates. If the prior is defined on the correlation matrix, the density in unconstrained coordinates must include the Jacobian of the map. For the row-wise partial-correlation coordinates above, use the distinct off-diagonal entries of \(\Omega\) as coordinates on the correlation-matrix space. The absolute Jacobian from the \(z_{ij}\) coordinates to those entries is
This determinant can be obtained by ordering the correlation entries consistently with the sequential construction: each new partial correlation changes a new correlation by a remaining-length factor, giving a triangular derivative structure. For three effects, write \(a=z_{21}\), \(b=z_{31}\), and \(c=z_{32}\). Then \(\rho_{12}=a\), \(\rho_{13}=b\), and \(\rho_{23}=ab+\sqrt{1-a^2}\sqrt{1-b^2}c\). The determinant of the map \((a,b,c)\mapsto(\rho_{12},\rho_{13},\rho_{23})\) is \(\sqrt{1-a^2}\sqrt{1-b^2}\), matching the formula.
The further transformation \(z_{ij}=\tanh(\eta_{ij})\) contributes a factor \(1-z_{ij}^2\) for each coordinate. Therefore the complete Jacobian from \(\eta\) to the distinct correlations is
The log of this positive quantity is added to the log prior density when the prior is expressed with respect to correlation-matrix coordinates. If instead a prior is deliberately defined directly on the \(\eta_{ij}\), its density is already on the HMC scale and this change-of-variables correction is not added. Those are different prior specifications, not interchangeable computational choices.
Worked Example: The Three-Effect Jacobian
For the three-effect coordinates in the preceding construction, \(a=0.30\), \(b=-0.20\), and \(c=0.40\). The Jacobian from \((a,b,c)\) to the three distinct correlations is
To convert from unconstrained \((\eta_{21},\eta_{31},\eta_{32})\), multiply by the three derivatives \(1-a^2\), \(1-b^2\), and \(1-c^2\):
Equivalently, the general formula gives \((1-a^2)^{3/2}(1-b^2)^{3/2}(1-c^2)\), which has the same value. A prior density stated on the three correlations must be multiplied by approximately \(0.6859\) at this point to obtain its density with respect to the three unconstrained coordinates.
Prior Choice, Diagnostics, and Alternatives
A common prior for a correlation matrix is the LKJ family, whose density with respect to the distinct correlations is proportional to \(|\Omega|^{\xi-1}\), where \(\xi>0\). The determinant is a measure of how far the matrix is from singularity. When \(\xi=1\), the density is uniform over the valid correlation-matrix space; it does not mean that each pairwise correlation is independently uniform. In unconstrained coordinates, the LKJ log density and the transformation log Jacobian must both be included if the prior was specified on \(\Omega\).
For this construction, \(|\Omega|=\prod_{i>j}(1-z_{ij}^2)\). Combining this determinant with the Jacobian shows how an LKJ prior induces marginal structure on the partial-correlation coordinates. In particular, a simple prior on each \(\eta_{ij}\) is generally not equivalent to an LKJ prior. Prior interpretation therefore requires stating the scale on which the prior is defined.
Practical checks should include verifying that the transformed matrix is symmetric with unit diagonal, that its Cholesky diagonal is positive, and that the log Jacobian is included exactly once when required. Extreme values of \(|\eta_{ij}|\) make \(\tanh(\eta_{ij})\) very close to a boundary, where derivatives become small and floating-point calculations can lose precision. Evaluate expressions such as \(\log(1-z_{ij}^2)\) with numerically stable routines when available, and inspect the resulting matrices and posterior draws for near-singularity.
A frequent mistake is to say, “Each correlation is between \(-1\) and \(1\), so the full matrix is valid.” That condition is necessary but not sufficient: a collection of individually admissible correlations can yield a non-positive-definite matrix. The correction is to construct the matrix through a parameterization that guarantees positive definiteness, or explicitly constrain the full matrix as a valid correlation matrix.
Directly sampling constrained correlation entries can be conceptually simple, but boundaries and positive-definiteness constraints are awkward for unconstrained HMC. A Cholesky-based construction gives smooth unconstrained coordinates and a straightforward validity guarantee, but can have geometry that is difficult for HMC, especially near singular matrices. Other valid constructions are possible; whichever is chosen, the model's prior must be transformed consistently. No parameterization removes the need to assess posterior computation, and transformation alone does not resolve weak information about correlations or dependence between correlations and the random-effect scales.
Check Your Understanding
Answer each question, then compare with the brief solutions.
- For a two-effect model with \(\eta=0\), what is \(\rho\), and what is \(|d\rho/d\eta|\)?
- Why do individually valid pairwise correlations not necessarily define a valid correlation matrix?
- For \(q=3\), use \(z_{21}=0\), \(z_{31}=0\), and \(z_{32}=0.50\) to find \(\rho_{23}\).
- If the prior is specified directly as a density on \(\eta\), should the correlation-scale Jacobian be added?
- What does an LKJ prior with \(\xi=1\) mean, and what does it not mean?
Solutions. (1) \(\rho=\tanh(0)=0\), and the derivative is \(1-\rho^2=1\). (2) Positive definiteness imposes joint constraints on the entries, beyond the pairwise bounds. (3) The construction gives \(\rho_{23}=z_{21}z_{31}+\sqrt{1-z_{21}^2}\sqrt{1-z_{31}^2}z_{32}=0.50\). (4) No; that prior is already defined on the unconstrained scale. (5) It is uniform over the valid correlation-matrix space with respect to its correlation-entry coordinates; it does not make all pairwise correlations independent and uniform.