Tutorials › Statistical Decision Theory › Divergence Form of Stein’s Identity

Stein Identity and Risk Improvement · Tutorial 418 of 982

Divergence Form of Stein’s Identity

Learn to express Gaussian Stein’s identity using divergence, connect divergence to the Jacobian trace, and calculate it for several vector fields.

Advanced 9 min read

What You'll Learn

  • State the divergence form of Stein’s identity for an isotropic multivariate normal distribution
  • Define the Jacobian matrix and relate its trace to vector-field divergence
  • Identify the boundary and integrability conditions used in the identity
  • Compute divergence for affine and separable vector fields
  • Distinguish diagonal derivatives from off-diagonal Jacobian entries
  • Check the identity by evaluating both sides in explicit Gaussian examples

From Coordinatewise Identities to Divergence

For a multivariate normal vector, Stein’s identity can be written as a sum of one-dimensional integration-by-parts identities, one for each coordinate. The vector-field form gathers those terms into a single expression: the inner product with the centered observation is paired with the divergence of the field. This notation is useful because it exposes exactly which derivatives contribute, without requiring the vector field to act separately on each coordinate.

Throughout, let \(X=(X_1,\ldots,X_p)^T\sim N_p(\mu,\sigma^2 I_p)\), where \(\mu=(\mu_1,\ldots,\mu_p)^T\), \(\sigma^2>0\), and \(I_p\) is the \(p\)-dimensional identity matrix. Let \(g:\mathbb R^p\to\mathbb R^p\) have component functions \(g_1,\ldots,g_p\). The dot product \((X-\mu)^Tg(X)\) is the sum of the coordinatewise products.

Definition: If \(g\) is differentiable, its Jacobian matrix at \(x\) is the \(p\times p\) matrix \(J_g(x)\) whose \((i,j)\) entry is \(\partial g_i(x)/\partial x_j\). The divergence of \(g\) is the trace of this Jacobian: $$ \operatorname{div}g(x) =\operatorname{tr}\!\bigl(J_g(x)\bigr) =\sum_{i=1}^p\frac{\partial g_i(x)}{\partial x_i}. $$

The trace selects the diagonal entries of the Jacobian: each component \(g_i\) is differentiated with respect to its own input coordinate \(x_i\). Derivatives such as \(\partial g_i/\partial x_j\) for \(i\ne j\) may be nonzero, but they do not appear in the divergence. This is not a claim that the field is coordinatewise; it is a specific sum of its own-coordinate derivatives.

Divergence Form of Stein’s Identity

Here is a sufficient set of conditions for the identity. Suppose each \(g_i\) is continuously differentiable, and, for every \(i\), the expectations \(E[|(X_i-\mu_i)g_i(X)|]\) and \(E[|\partial g_i(X)/\partial x_i|]\) are finite. Also suppose that for almost every fixed vector \(x_{-i}\) of the coordinates other than \(x_i\), the boundary terms \(g_i(x)\phi_i(x_i)\) tend to zero as \(x_i\to-\infty\) and \(x_i\to+\infty\), where \(\phi_i\) is the \(N(\mu_i,\sigma^2)\) density. These assumptions make the coordinatewise integrations by parts and the summation below valid.

Theorem: Under the conditions just stated, $$ E\!\left[(X-\mu)^Tg(X)\right] =\sigma^2 E\!\left[\operatorname{div}g(X)\right]. $$

Proof. The coordinates of \(X\) are independent, each with density $$ \phi_i(t)=\frac{1}{\sqrt{2\pi\sigma^2}} \exp\!\left(-\frac{(t-\mu_i)^2}{2\sigma^2}\right), \qquad \phi_i'(t)=-\frac{t-\mu_i}{\sigma^2}\phi_i(t). $$ Fix \(i\), and hold the other coordinates \(x_{-i}\) fixed at values for which the boundary condition holds. One-dimensional integration by parts gives $$ \int_{\mathbb R}(t-\mu_i)g_i(x)\phi_i(t)\,dt =-\sigma^2\int_{\mathbb R}g_i(x)\phi_i'(t)\,dt =\sigma^2\int_{\mathbb R}\frac{\partial g_i(x)}{\partial x_i}\phi_i(t)\,dt. $$ In the last equality, the boundary term \(-\sigma^2[g_i(x)\phi_i(t)]_{-\infty}^{\infty}\) is zero by assumption. Integrating over \(X_{-i}\) gives $$ E[(X_i-\mu_i)g_i(X)] =\sigma^2 E\!\left[\frac{\partial g_i(X)}{\partial x_i}\right]. $$ The stated absolute-integrability conditions allow these integrations and expectations to be taken as written. Summing over \(i=1,\ldots,p\), and using the definitions of dot product and divergence, yields $$ E\!\left[(X-\mu)^Tg(X)\right] =\sum_{i=1}^p E[(X_i-\mu_i)g_i(X)] =\sigma^2\sum_{i=1}^p E\!\left[\frac{\partial g_i(X)}{\partial x_i}\right] =\sigma^2 E[\operatorname{div}g(X)]. $$ \(\square\)

The proof shows how the vector formula relates to the coordinatewise identity: it adds the \(p\) scalar identities. The factor \(\sigma^2\) comes from differentiating the normal density, not from the definition of divergence. The regularity conditions are part of the result; the identity is not justified merely by writing down derivatives. More detailed classes of sufficient conditions require separate attention.

Calculating Divergence

For an affine field \(g(x)=Ax+b\), where \(A\) is a fixed \(p\times p\) matrix and \(b\) is a fixed vector, the Jacobian is constant and equals \(A\). Therefore its divergence is the trace of \(A\). This gives a useful check on both the derivative convention and the identity.

Worked Example: An Affine Vector Field

Let \(p=2\), \(X\sim N_2(\mu,4I_2)\), and $$ g(x)=Ax+b,\qquad A=\begin{pmatrix}2&5\\-1&-3\end{pmatrix}, \qquad b=\begin{pmatrix}7\\4\end{pmatrix}. $$ Compute the divergence and verify the two sides of Stein’s identity.

The Jacobian is \(J_g(x)=A\), so $$ \operatorname{div}g(x)=\operatorname{tr}(A)=2+(-3)=-1. $$ Thus the right side of the identity is \(4E[-1]=-4\).

For the left side, write \(X=\mu+(X-\mu)\). Since \(E[X-\mu]=0\), the constant vector \(A\mu+b\) has zero expected inner product with \(X-\mu\). The remaining term is $$ E[(X-\mu)^TA(X-\mu)] =\sum_{i=1}^2\sum_{j=1}^2 A_{ij}E[(X_i-\mu_i)(X_j-\mu_j)]. $$ The off-diagonal covariances are zero and each diagonal variance is \(4\), so this equals \(4A_{11}+4A_{22}=4(2-3)=-4\). Both sides agree. The off-diagonal entries \(5\) and \(-1\) affect the field itself but not its divergence or this expected inner product.

A particularly simple pattern occurs when each component depends only on its matching coordinate. If \(g_i(x)=h_i(x_i)\), then the Jacobian is diagonal and its \(i\)th diagonal entry is \(h_i'(x_i)\). Consequently, $$ \operatorname{div}g(x)=\sum_{i=1}^p h_i'(x_i). $$ No independence assumption about the functions is needed for this derivative calculation; the displayed formula follows from how the components are defined.

Worked Example: A Separable Field

Let \(X\sim N_2((1,-1)^T,I_2)\) and set \(g_1(x)=x_1^2\), \(g_2(x)=3x_2\). These smooth polynomial components satisfy the required Gaussian integrability and boundary conditions.

The Jacobian and divergence are $$ J_g(x)= \begin{pmatrix} 2x_1&0\\ 0&3 \end{pmatrix}, \qquad \operatorname{div}g(x)=2x_1+3. $$ Since \(E[X_1]=1\), the right side of Stein’s identity is \(E[2X_1+3]=5\), because here \(\sigma^2=1\).

To check the left side, expand it coordinatewise: $$ E[(X_1-1)X_1^2+3(X_2+1)X_2]. $$ Write \(X_1=1+Z_1\), \(X_2=-1+Z_2\), where each \(Z_i\) has mean \(0\) and variance \(1\). Then $$ E[(X_1-1)X_1^2]=E[Z_1(1+Z_1)^2] =E[Z_1+2Z_1^2+Z_1^3]=2, $$ using the zero first and third centered moments of a normal variable. Also, $$ 3E[(X_2+1)X_2]=3E[Z_2(-1+Z_2)] =3E[-Z_2+Z_2^2]=3. $$ The left side is \(2+3=5\), as required.

The divergence formula also applies when components depend on several coordinates. In that case, form the full Jacobian first, then select its diagonal. The next example makes explicit why “divergence” does not mean summing every entry of that matrix.

Worked Example: A Coupled Field

For \(x\in\mathbb R^2\), define \(g_1(x)=x_1x_2\) and \(g_2(x)=x_1^2\). Its Jacobian is $$ J_g(x)= \begin{pmatrix} x_2&x_1\\ 2x_1&0 \end{pmatrix}. $$ The diagonal entries are \(x_2\) and \(0\), so \(\operatorname{div}g(x)=x_2\). The two off-diagonal entries, \(x_1\) and \(2x_1\), are not included.

For a numerical check, take \(X\sim N_2((0,2)^T,I_2)\). The right side is \(E[X_2]=2\). The left side is $$ E[X_1(X_1X_2)+ (X_2-2)X_1^2] =E[X_1^2X_2]+E[(X_2-2)X_1^2]. $$ Independence gives \(E[X_1^2X_2]=E[X_1^2]E[X_2]=1\cdot2=2\), while \(E[(X_2-2)X_1^2]=E[X_2-2]E[X_1^2]=0\cdot1=0\). The left side is therefore \(2\), matching the divergence calculation.

Why the Trace Matters

The divergence form compresses a collection of coordinate identities into a single geometric expression. In a calculation, the trace is often easier to inspect than a list of separate derivatives, especially when the Jacobian has a recognizable structure. It also makes clear that a field can couple coordinates while still having a simple divergence: only the diagonal of its Jacobian determines this quantity.

A frequent mistake is to sum all entries of \(J_g(x)\), or to use the determinant instead of the trace. The determinant describes a different feature of a matrix and is not the divergence. For the coupled field above, summing all four Jacobian entries would give \(3x_1+x_2\), whereas the divergence is \(x_2\). Another common error is to omit \(\sigma^2\) in Stein’s identity. The derivative of the \(N(\mu_i,\sigma^2)\) density includes the factor \(1/\sigma^2\), so integration by parts produces the multiplier \(\sigma^2\) on the divergence side.

Key takeaway: For an isotropic normal vector, Stein’s identity pairs the centered vector with a field through \(E[(X-\mu)^Tg(X)]=\sigma^2E[\operatorname{div}g(X)]\). Compute divergence as the trace of the Jacobian: add \(\partial g_i/\partial x_i\), not every partial derivative.

Check Your Understanding

Use the definitions and identity above to answer the following.

  1. For \(g(x)=Ax+b\), what is the Jacobian, and which entries of \(A\) determine the divergence?
  2. If \(g_1(x)=\sin(x_1)\) and \(g_2(x)=x_2^3\), write the divergence as a function of \(x\).
  3. For a two-dimensional field with Jacobian \(\begin{pmatrix}a&b\\c&d\end{pmatrix}\), state its divergence and explain why \(b\) and \(c\) do not enter.
  4. In the affine worked example, why does the expected inner product depend on the diagonal entries of \(A\) but not on \(b\)?
  5. What factor multiplies the expected divergence when \(X\sim N_p(\mu,\sigma^2I_p)\), and where does that factor arise in the proof?
Clinical Biostats