Tutorials › Generalized Linear Mixed Models (GLMM) › Tensor-Product Quadrature for Multiple Random Effects

Laplace Approximation and Adaptive Quadrature · Tutorial 185 of 698

Tensor-Product Quadrature for Multiple Random Effects

Learn to build and calculate tensor-product Gauss–Hermite approximations for integrals over two independent random effects.

Advanced 10 min read

What You'll Learn

  • Convert one-dimensional Gauss–Hermite nodes and weights into a standard-normal expectation rule.
  • Form the Cartesian product of two node sets and multiply their weights.
  • Approximate a marginal likelihood involving two independent random effects.
  • Calculate a tensor rule with unequal weights and check its normalization.
  • Diagnose indexing, scaling, and convergence errors in a bivariate calculation.

Why a Tensor Product Is Needed

A GLMM with two random effects requires integrating a conditional likelihood over both effects. Even if each one-dimensional integral is familiar, the integrand generally depends jointly on the two effects, so evaluating two separate one-dimensional approximations is not enough. A tensor-product rule supplies a grid of paired evaluation points, with one coordinate from each one-dimensional rule.

The construction below uses independent standard-normal coordinates. This covers models in which the two random effects are independent after standardization. A correlated pair requires a suitable transformation to independent coordinates before applying this rule; the formulas here do not themselves perform that transformation.

Definition: Suppose \(U\) and \(V\) are independent standard normal random variables, and let a one-dimensional quadrature rule approximate \(E\{g(U)\}\) by \(\sum_{j=1}^{m} a_j g(z_j)\). Its bivariate tensor-product rule approximates \(E\{h(U,V)\}\) by \(\sum_{j=1}^{m}\sum_{k=1}^{m} a_j a_k h(z_j,z_k)\). Each grid point is a pair of one-dimensional nodes, and its weight is the product of the two corresponding weights.

From a One-Dimensional Rule to a Bivariate Rule

A common starting point is the physicists’ Gauss–Hermite rule, which approximates integrals weighted by \(e^{-x^2}\). If its nodes and weights are \(x_j\) and \(w_j\), then the standard-normal expectation rule has nodes \(z_j=\sqrt{2}x_j\) and normalized weights \(a_j=w_j/\sqrt{\pi}\). Thus \(\sum_j a_j g(z_j)\) approximates \(E\{g(U)\}\) for \(U\sim N(0,1)\), and the weights satisfy \(\sum_j a_j=1\).

For two independent standard normals, the joint density factors into the product of the two standard-normal densities. Consequently, the expectation is a two-dimensional integral with a product density. Replacing each coordinate’s integral by the same one-dimensional rule gives the tensor formula.

$$ E\{h(U,V)\} =\int_{\mathbb R}\int_{\mathbb R}h(u,v)\phi(u)\phi(v)\,du\,dv \ \approx\ \sum_{j=1}^{m}\sum_{k=1}^{m}a_j a_k h(z_j,z_k), \qquad \phi(t)=\frac{1}{\sqrt{2\pi}}e^{-t^2/2}. $$

The product weight \(a_j a_k\) is essential: it is the probability weight assigned by the product rule to that node pair. The weights across the entire grid sum to one, since \(\sum_j\sum_k a_j a_k=(\sum_j a_j)(\sum_k a_k)=1\). If the original random effects are independent but not standard normal, write them as \(B_1=\mu_1+\sigma_1U\) and \(B_2=\mu_2+\sigma_2V\), and evaluate the conditional integrand at those transformed values. The quadrature weights remain the standard-normal weights.

Worked Example: Building a Two-by-Two Grid

For the two-node standard-normal Gauss–Hermite rule, the nodes are \(z_1=-1,z_2=1\), with weights \(a_1=a_2=1/2\). Consider the hypothetical integrand \(h(u,v)=1+0.2u+0.1v+0.3u^2+0.4uv+0.2v^2\). Construct the tensor sum.

The grid consists of all four pairs \((-1,-1),(-1,1),(1,-1),(1,1)\). Each pair has weight \((1/2)(1/2)=1/4\). Substitution gives \(h(-1,-1)=1.6\), \(h(-1,1)=1.0\), \(h(1,-1)=1.2\), and \(h(1,1)=2.2\). Therefore,

$$ \sum_{j=1}^{2}\sum_{k=1}^{2}a_ja_kh(z_j,z_k) =\frac14(1.6+1.0+1.2+2.2)=1.50. $$

In this case the exact standard-normal expectation is also \(1.50\): the linear and cross terms have expectation zero, while \(E(U^2)=E(V^2)=1\). The two-node rule reproduces this polynomial expectation because the degree in each coordinate is at most two. This exactness for the chosen integrand does not mean the rule is exact for arbitrary smooth or likelihood integrands.

Applying the Grid to a GLMM Marginal Likelihood

For a cluster with observed responses \(y\), let \(L(b_1,b_2\mid y)\) be its conditional likelihood given the random effects. If the two random effects are independent standard normals, the cluster’s marginal likelihood is the expectation of that conditional likelihood over their joint distribution. Tensor quadrature evaluates the conditional likelihood at every paired node and averages those values using the product weights. With nonstandard independent effects, substitute their means and scales at each node as described above.

For example, in a binary-logit model, a conditional Bernoulli likelihood contribution for response \(y_r\) and linear predictor \(\eta_r\) is \(p_r^{y_r}(1-p_r)^{1-y_r}\), where \(p_r=\operatorname{expit}(\eta_r)=1/(1+e^{-\eta_r})\). The cluster likelihood is the product of the contributions, conditional on the shared random effects. The random effects are then integrated out; they are not replaced by their mean before computing that product.

Worked Example: Two-Effect Quadrature for a Binary Likelihood

Suppose a hypothetical cluster has two binary observations, \(y_1=1\) and \(y_2=0\). Let its conditional linear predictors be \(\eta_1=-1+b_1+0.5b_2\) and \(\eta_2=0.2+0.3b_1-0.4b_2\), with independent \(b_1,b_2\sim N(0,1)\). Use the two-node rule \(b_1,b_2\in\{-1,1\}\), each with weight \(1/2\). The model’s conditional likelihood is \(L=p_1(1-p_2)\), where \(p_r=\operatorname{expit}(\eta_r)\).

At \((b_1,b_2)=(-1,-1)\), the predictors are \((-2.5,0.3)\). Thus \(p_1\approx0.07586\), \(1-p_2\approx0.42556\), and \(L\approx0.03228\). At \((-1,1)\), the predictors are \((-1.5,-0.5)\); the corresponding values are \(0.18243\) and \(0.62246\), giving \(L\approx0.11355\).

At \((1,-1)\), the predictors are \((-0.5,0.9)\), so \(p_1\approx0.37754\), \(1-p_2\approx0.28905\), and \(L\approx0.10913\). At \((1,1)\), the predictors are \((0.5,0.1)\), giving \(p_1\approx0.62246\), \(1-p_2\approx0.47502\), and \(L\approx0.29568\). Every pair has product weight \(1/4\). The tensor approximation to the marginal likelihood is therefore

$$ L_{\mathrm{marg}} \ \approx\ \frac14(0.03228+0.11355+0.10913+0.29568) =\frac{0.55064}{4} =0.13766. $$

This is a quadrature approximation to the marginal likelihood under the stated model, not a conditional likelihood at an “average” random effect. The displayed values are rounded for presentation; the sum and final result are calculated from the unrounded logistic probabilities.

Unequal Weights and a Normalization Check

Tensor weights need not all be equal. For the three-node standard-normal rule, the nodes are \(0,\sqrt{3},-\sqrt{3}\), with respective normalized weights \(2/3,1/6,1/6\). A paired node’s weight is still the product of its coordinate weights. For example, the pair \((0,\sqrt{3})\) has weight \((2/3)(1/6)=1/9\), whereas \((\sqrt{3},-\sqrt{3})\) has weight \((1/6)(1/6)=1/36\).

Worked Example: A Three-by-Three Tensor Sum

Use the three-node rule in both coordinates to approximate \(E(U^2+V^2)\). At \((0,0)\), the integrand is \(0\) and the weight is \(4/9\). At each of the four axial pairs \((\pm\sqrt{3},0)\) and \((0,\pm\sqrt{3})\), the integrand is \(3\) and the weight is \(1/9\). At each of the four corner pairs \((\pm\sqrt{3},\pm\sqrt{3})\), the integrand is \(6\) and the weight is \(1/36\). Therefore,

$$ \frac49(0)+4\left(\frac19\right)(3)+4\left(\frac1{36}\right)(6) =0+\frac43+\frac23=2. $$

The result agrees with the exact expectation \(E(U^2)+E(V^2)=1+1=2\). The weights also pass a useful check: \(4/9+4(1/9)+4(1/36)=1\). Checking both the weighted sum and the total weight can reveal omitted pairs or incorrect weight products.

Assumptions, Checks, and Alternatives

The tensor formula applies directly when the transformed coordinates being integrated are independent standard normals and the target expectation exists. In a GLMM marginal likelihood, the integrand is the conditional likelihood as a function of those coordinates. The likelihood must be evaluated consistently at each node pair, including all responses in the cluster that share those effects. If a covariance structure makes the random effects dependent, applying independent product weights to the original correlated coordinates is not justified; first use an appropriate transformation to independent coordinates.

A practical diagnostic is to recompute the same integral at successively higher quadrature orders and compare the marginal likelihood, or the log marginal likelihood, at the precision needed for the analysis. Agreement is evidence of numerical stability, not a proof of exactness. Large changes with order, sensitivity to small changes in parameters, or non-finite conditional likelihood calculations warrant investigation. In particular, check that both node coordinates are substituted into every linear predictor, that all \(m^2\) pairs are included, and that the normalized weights sum to one. When likelihoods are extremely small, summing their logarithms with a stable log-sum-exp calculation can help avoid numerical underflow.

Tensor-product quadrature is a direct extension of one-dimensional Gauss–Hermite quadrature: it is systematic and easy to verify, but its accuracy depends on the chosen order and the integrand. Adaptive quadrature instead chooses nodes and weights in relation to the integrand’s local shape; tensor products can also be formed from such one-dimensional rules. The Laplace approximation is a different alternative, using local curvature near a mode rather than a weighted grid of function evaluations. These methods are not interchangeable by definition: compare numerical results when accuracy matters, and check that the integration approximation is stable enough for the intended inference.

A common mistake is to use physicists’ Hermite weights \(w_j\) directly as if they were normalized standard-normal weights, or to multiply the bivariate sum by another normalizing constant after already using \(a_j=w_j/\sqrt{\pi}\). That mixes conventions and changes the integral’s scale. Another error is to use weight \(a_j+a_k\) for a node pair; independence requires the product \(a_ja_k\). Write down the one-dimensional convention first, form product weights, and verify that the full grid weights sum to one.

Key takeaway: For two independent standard-normal coordinates, pair every one-dimensional node with every other node, evaluate the integrand at each pair, and multiply the two normalized weights. The bivariate approximation is the sum of those weighted evaluations.

Check Your Understanding

Try each question, then compare with the solutions below.

  1. A two-node standard-normal rule has nodes \(-1,1\), each with weight \(1/2\). What is the weight of each point in its two-dimensional tensor grid?
  2. Using that two-node rule, calculate the tensor approximation to \(E(UV)\).
  3. For the three-node rule with weights \(2/3,1/6,1/6\), what is the product weight of \((0,-\sqrt{3})\)?
  4. Why is it generally invalid to apply independent product weights directly to two correlated random effects?

Solutions. (1) Every pair has weight \((1/2)(1/2)=1/4\). (2) The four values of \(uv\) are \(1,-1,-1,1\), so the weighted sum is \((1-1-1+1)/4=0\). (3) The weight is \((2/3)(1/6)=1/9\). (4) The product rule represents a joint distribution that factors into independent marginal distributions; a correlated joint density does not factor that way. A transformation to independent coordinates is needed before using this tensor rule.

Clinical Biostats