Tutorials › Generalized Linear Models › Deriving Mean And Variance From The Log-Partition Function

Mean Variance and Dispersion · Tutorial 42 of 981

Deriving Mean And Variance From The Log-Partition Function

See how derivatives of the log-partition function encode the response mean and variance, and why the dispersion scale matters.

Beginner 10 min read

What You'll Learn

  • State a normalized exponential-dispersion model and its log-partition function
  • Identify conditions that justify differentiating the normalization identity
  • Derive the mean from the first derivative of the cumulant function
  • Derive the variance from its second derivative, including the dispersion scale
  • Reconcile derivatives with respect to the scaled and unscaled natural parameters
  • Check the identities in Bernoulli, Poisson, and Gaussian examples

Why Differentiate the Normalizing Identity?

In an exponential-family model, the normalizing term is chosen so that the probabilities or density integrate to one. That requirement is more than a technical detail: differentiating it reveals how the distribution's mean and variance change with the natural parameter. The same calculation applies across response families, provided differentiation under the integral or sum is justified.

For generalized linear model work, it is particularly important to keep the dispersion scale visible. In the common exponential-dispersion form, the first derivative of the cumulant function gives the mean, while its second derivative must be multiplied by the dispersion scale to give the variance.

Exponential-Dispersion Form and Notation

Fix a dispersion parameter \(\phi\), and let \(a(\phi)>0\). Consider a response \(Y\) with density or probability mass function, relative to a measure \(\nu\), of the form

$$ f(y;\theta,\phi) = \exp\left\{ \frac{y\theta-b(\theta)}{a(\phi)}+c(y,\phi) \right\}. $$

Here \(\theta\) is the natural parameter in the usual exponential-dispersion convention, \(b(\theta)\) is the cumulant (or unscaled log-partition) function, and \(c(y,\phi)\) contains terms not involving \(\theta\). The parameter \(\theta\) ranges over an open interval on which the model is normalized. For each fixed \(\phi\), normalization means

$$ \int \exp\left\{ \frac{y\theta-b(\theta)}{a(\phi)}+c(y,\phi) \right\}\,d\nu(y) =1. $$

For a discrete response, the integral denotes a sum. In this tutorial, \(b\) is called the cumulant function, following the usual exponential-dispersion convention. Some authors reserve “log-partition function” for the entire normalizing term \(b(\theta)/a(\phi)\). The parameterization used for differentiation determines whether the scale appears explicitly in the derivative identities; both conventions are related below.

Definition: The cumulant function \(b(\theta)\) is the function in the normalized exponential-dispersion representation that appears in the term \(\{y\theta-b(\theta)\}/a(\phi)\). For fixed dispersion, its first derivative will give \(E[Y]\), and its second derivative, multiplied by \(a(\phi)\), will give \(\operatorname{Var}(Y)\).

The following regularity conditions suffice for the calculations. The support and measure \(\nu\) do not depend on \(\theta\); \(b\) is twice continuously differentiable on the open parameter interval; and, in a neighborhood of each \(\theta\), the integrand and its first two \(\theta\)-derivatives have integrable dominating functions. A convenient sufficient condition is that, on every sufficiently small closed interval \(K\) around \(\theta\),

$$ \sup_{t\in K} (1+y^2) \exp\left\{ \frac{yt-b(t)}{a(\phi)}+c(y,\phi) \right\} $$

is integrable with respect to \(\nu\). Since \(b'\) and \(b''\) are bounded on such an interval, this condition dominates the integrand and the derivatives needed below. It permits differentiation under the integral sign by the dominated convergence theorem. Parameter-dependent support requires separate care and is excluded from these identities as stated.

The First Derivative Gives the Mean

Write \(q_\theta(y)=f(y;\theta,\phi)\), holding \(\phi\) fixed. Direct differentiation of the log density gives

$$ \frac{\partial}{\partial\theta}\log q_\theta(y) = \frac{y-b'(\theta)}{a(\phi)}. $$

This derivative is the score with respect to \(\theta\). The normalization identity implies that its expectation is zero; the resulting equation identifies the mean.

Result: Under the stated regularity conditions,
$$ E[Y]=b'(\theta). $$

Proof. Because \(q_\theta\) integrates to one for every \(\theta\), its derivative integrates to zero. Differentiation under the integral is permitted by the domination condition. Using the score expression,

$$ 0 = \frac{\partial}{\partial\theta}\int q_\theta(y)\,d\nu(y) = \int q_\theta(y)\frac{y-b'(\theta)}{a(\phi)}\,d\nu(y) = \frac{E[Y]-b'(\theta)}{a(\phi)}. $$

Since \(a(\phi)>0\), multiplying by \(a(\phi)\) gives \(E[Y]=b'(\theta)\). \(\square\)

The Second Derivative Gives the Variance

The second derivative follows from differentiating normalization again. Differentiating the density itself, rather than only its logarithm, makes the squared deviation term visible. The first derivative of the density is

$$ \frac{\partial q_\theta(y)}{\partial\theta} = q_\theta(y)\frac{y-b'(\theta)}{a(\phi)}. $$

Differentiating once more yields

$$ \frac{\partial^2 q_\theta(y)}{\partial\theta^2} = q_\theta(y) \left\{ \frac{[y-b'(\theta)]^2}{a(\phi)^2} -\frac{b''(\theta)}{a(\phi)} \right\}. $$
Result: Under the same regularity conditions,
$$ \operatorname{Var}(Y)=a(\phi)b''(\theta). $$

Proof. The normalization integral is identically one, so its second derivative is zero. The second-derivative domination condition allows the derivative to pass inside the integral. Substituting the expression above gives

$$ \begin{aligned} 0 &= \int \frac{\partial^2 q_\theta(y)}{\partial\theta^2}\,d\nu(y)\\ &= E\left[ \frac{[Y-b'(\theta)]^2}{a(\phi)^2} -\frac{b''(\theta)}{a(\phi)} \right]. \end{aligned} $$

The first result gives \(b'(\theta)=E[Y]\). Thus \(E[(Y-b'(\theta))^2]=\operatorname{Var}(Y)\), and the equation becomes

$$ 0 = \frac{\operatorname{Var}(Y)}{a(\phi)^2} -\frac{b''(\theta)}{a(\phi)}. $$

Multiplication by \(a(\phi)^2\) gives \(\operatorname{Var}(Y)=a(\phi)b''(\theta)\). \(\square\)

Which Log-Partition Derivative?

The scale factor can appear in different places depending on how the natural parameter and log-partition function are defined. In the exponential-dispersion convention above, the coefficient of \(y\) is \(\theta/a(\phi)\), while \(b(\theta)\) is the unscaled cumulant function. That is why its derivatives satisfy \(b'(\theta)=E[Y]\) and \(a(\phi)b''(\theta)=\operatorname{Var}(Y)\).

For fixed \(\phi\), define the coefficient parameter \(\eta=\theta/a(\phi)\) and the corresponding log-partition function

$$ A_\phi(\eta) = \frac{b(a(\phi)\eta)}{a(\phi)}. $$

Then the model can be written with the parameter-dependent terms \(y\eta-A_\phi(\eta)\). Applying the chain rule gives

$$ A_\phi'(\eta)=b'(a(\phi)\eta)=E[Y], \qquad A_\phi''(\eta)=a(\phi)b''(a(\phi)\eta)=\operatorname{Var}(Y). $$

Thus, in the coefficient parameter \(\eta\), the first and second derivatives of the log-partition function are the mean and variance directly. In the usual dispersion convention, the same facts are expressed through \(b\), with the scale multiplying its second derivative. These are equivalent descriptions, not competing formulas.

Worked Examples

Worked Example: Bernoulli Response

Let \(Y\) be Bernoulli with success probability \(p\), where \(0<p<1\). Set \(\theta=\log\{p/(1-p)\}\), \(a(\phi)=1\), and \(b(\theta)=\log(1+e^\theta)\). The mass function is

$$ f(y;\theta) = \exp\{y\theta-\log(1+e^\theta)\}, \qquad y\in\{0,1\}. $$

Indeed, the probabilities at zero and one are \(1/(1+e^\theta)\) and \(e^\theta/(1+e^\theta)\), whose sum is one. Differentiation gives

$$ b'(\theta)=\frac{e^\theta}{1+e^\theta}=p, \qquad b''(\theta)=\frac{e^\theta}{(1+e^\theta)^2}=p(1-p). $$

For example, if \(p=0.6\), then \(\theta=\log(0.6/0.4)=\log(1.5)\). Substitution gives \(b'(\theta)=1.5/2.5=0.6\) and \(b''(\theta)=1.5/(2.5)^2=0.24\). The identities therefore recover \(E[Y]=0.6\) and \(\operatorname{Var}(Y)=0.24\), the Bernoulli mean and variance.

Worked Example: Poisson Count

Let \(Y\) have a Poisson distribution with rate \(\lambda>0\). Take \(\theta=\log\lambda\), \(a(\phi)=1\), and \(b(\theta)=e^\theta\). The probability mass function is

$$ f(y;\theta) = \exp\{y\theta-e^\theta-\log(y!)\}, \qquad y=0,1,2,\ldots. $$

The derivatives are \(b'(\theta)=e^\theta\) and \(b''(\theta)=e^\theta\). At \(\lambda=4\), \(\theta=\log 4\), so both derivatives equal \(4\). Since the dispersion scale is one, the formulas give \(E[Y]=4\) and \(\operatorname{Var}(Y)=4\). The example also shows that the two derivatives need not have different numerical values; their meanings are determined by the moment identities.

Worked Example: Gaussian Response with Known Variance

Suppose \(Y\sim N(\mu,\sigma^2)\), with \(\sigma^2\) known. Use \(\theta=\mu\), \(a(\phi)=\sigma^2\), \(b(\theta)=\theta^2/2\), and

$$ c(y,\phi) = -\frac{y^2}{2\sigma^2} -\frac12\log(2\pi\sigma^2). $$

The exponent in the exponential-dispersion representation simplifies as follows:

$$ \frac{y\mu-\mu^2/2}{\sigma^2} -\frac{y^2}{2\sigma^2} -\frac12\log(2\pi\sigma^2) = -\frac{(y-\mu)^2}{2\sigma^2} -\frac12\log(2\pi\sigma^2). $$

Thus the representation is the \(N(\mu,\sigma^2)\) density. Since \(b'(\mu)=\mu\) and \(b''(\mu)=1\), it yields \(E[Y]=\mu\) and \(\operatorname{Var}(Y)=\sigma^2\cdot1=\sigma^2\). For \(\mu=2\) and \(\sigma^2=9\), the derivatives give mean \(2\) and variance \(9\), confirming that the dispersion scale cannot be omitted from the variance formula.

Common Mistake: Losing the Dispersion Scale

A frequent error is to read \(b''(\theta)\) as the response variance in every exponential-dispersion model. That is correct only when \(a(\phi)=1\). In the Gaussian example, \(b''(\mu)=1\), but the response variance is \(9\) when \(\sigma^2=9\). The correct calculation is \(a(\phi)b''(\theta)=9\cdot1=9\).

A related notational error is to differentiate \(b(\theta)/a(\phi)\) with respect to \(\theta\) and claim the result is the mean. Its derivative is \(b'(\theta)/a(\phi)\), not \(b'(\theta)\). That is the derivative of the scaled normalizing term in the \(\theta\) coordinate; the coefficient parameter \(\eta=\theta/a(\phi)\) instead gives the direct log-partition identities \(A_\phi'(\eta)=E[Y]\) and \(A_\phi''(\eta)=\operatorname{Var}(Y)\).

Key takeaway: For the standard exponential-dispersion representation, \(E[Y]=b'(\theta)\) and \(\operatorname{Var}(Y)=a(\phi)b''(\theta)\). Always identify both the parameter coordinate and the scale before interpreting a log-partition derivative.

Check Your Understanding

Use the parameterization and scale explicitly in each answer.

  1. In the exponential-dispersion representation, what does \(b'(\theta)\) equal, and what does \(b''(\theta)\) equal after accounting for \(a(\phi)\)?
  2. Why is a common, parameter-independent support useful when differentiating the normalization integral?
  3. For a Gaussian response with known variance \(\sigma^2\), why does \(b''(\mu)=1\) not imply that the response variance is one?
  4. If the coefficient parameter is \(\eta=\theta/a(\phi)\), define \(A_\phi(\eta)\) and state its first two derivative identities.
  5. For a Poisson response with rate \(\lambda\), identify \(b(\theta)\), \(b'(\theta)\), and \(b''(\theta)\) using \(\theta=\log\lambda\).
Clinical Biostats