Tutorials › Generalized Linear Models › Gamma Dispersion Estimation By Deviance And Likelihood

Gamma Response Models · Tutorial 574 of 981

Gamma Dispersion Estimation By Deviance And Likelihood

Learn how method-of-moments, Pearson, deviance, and maximum-likelihood estimates quantify gamma dispersion around fitted means.

Intermediate 11 min read

What You'll Learn

  • Derive the gamma method-of-moments estimate from the variance function
  • Calculate Pearson and deviance estimates and understand their degrees-of-freedom adjustment
  • Derive the maximum-likelihood score equation for gamma dispersion
  • Solve the gamma shape equation and recognize its boundary case
  • Compare the estimates and understand when they are close
  • Avoid treating residual degrees-of-freedom corrections as exact in every fitted GLM

Why Estimate Gamma Dispersion?

A gamma response model specifies how the response mean changes with predictors, but it also needs to describe variation around that mean. With mean \(\mu_i\) and dispersion \(\phi>0\), the gamma model has variance \(\operatorname{Var}(Y_i)=\phi\mu_i^2\). Dispersion therefore controls the relative, rather than absolute, size of variation: the standard deviation is \(\sqrt{\phi}\mu_i\). Estimating \(\phi\) tells us how much scatter remains around the fitted means.

Assume throughout that \(Y_1,\ldots,Y_n\) are independent gamma responses with means \(\mu_i>0\) and a common dispersion \(\phi\). Write \(\hat\mu_i\) for the fitted mean. The estimates below differ in how they summarize residual variation: a squared-residual moment, the Pearson statistic, the deviance, or the full gamma likelihood.

Definition: Under the gamma parameterization used here, \(Y_i\) has shape \(1/\phi\) and scale \(\phi\mu_i\). Thus \(E[Y_i]=\mu_i\) and \(\operatorname{Var}(Y_i)=\phi\mu_i^2\). Define the Pearson residual \(r_{Pi}=(y_i-\hat\mu_i)/\hat\mu_i\), the Pearson statistic \(X_P^2=\sum_{i=1}^n r_{Pi}^2\), and the gamma unit deviance \(D=2\sum_{i=1}^n[y_i/\hat\mu_i-1-\log(y_i/\hat\mu_i)]\).

Method of Moments and the Pearson Estimate

If the means were known, the variance relationship immediately gives a moment estimate. Define \(R_i=(Y_i-\mu_i)/\mu_i\). Its expected value is zero and its second moment is

$$ E[R_i^2] =\frac{E[(Y_i-\mu_i)^2]}{\mu_i^2} =\frac{\phi\mu_i^2}{\mu_i^2} =\phi. $$

Matching the average of the observed squared relative residuals to this expected value gives the method-of-moments estimate. With unknown means, substitute the fitted means for the unknown \(\mu_i\). This yields the raw residual moment below. A degrees-of-freedom adjustment is often used when the means have been estimated.

Definition: The raw residual method-of-moments estimate is \(\hat\phi_{\mathrm{MM}}=X_P^2/n\). The commonly used Pearson estimate is \(\hat\phi_P=X_P^2/(n-p)\), where \(p\) is the rank of the fitted mean model. With known means, use \(p=0\). With estimated means, the adjustment reflects the approximate loss of \(p\) residual degrees of freedom; it is not generally an exact unbiasedness correction for every gamma GLM.

The approximation behind \(n-p\) can be seen by linearizing the fitted residuals near the true means. In standardized coordinates, suppose the residual vector is approximated by \((I-H)e\), where \(e\) has mean zero and covariance matrix \(\phi I\), and \(H\) is a symmetric idempotent projection matrix of rank \(p\). Then

$$ E\!\left[e^{\mathsf T}(I-H)e\right] =\operatorname{tr}\!\left((I-H)\operatorname{Cov}(e)\right) =\phi\operatorname{tr}(I-H) =\phi(n-p). $$

This calculation motivates the Pearson correction. In a general gamma GLM, the fitted means and residuals are nonlinear functions of the data, so the projection argument is a local approximation rather than an exact finite-sample result.

Worked Example: Moment, Pearson, and Deviance Estimates

Suppose four independent responses follow gamma distributions with means represented by fitted values \(\hat\mu=(2,4,5,10)\). The observed responses are \(y=(1,6,5,20)\). Assume the mean model has rank \(p=1\). Compute the moment, Pearson, and deviance estimates.

First calculate the ratios \(z_i=y_i/\hat\mu_i\): they are \(0.5,1.5,1,2\). The Pearson residuals are \(z_i-1\), so their squares are \(0.25,0.25,0,1\). Thus \(X_P^2=1.5\), and the raw moment estimate is \(1.5/4=0.375\). The degrees-of-freedom-adjusted Pearson estimate is \(1.5/(4-1)=0.5\).

For the deviance, each contribution is \(2(z_i-1-\log z_i)\). The contributions are \(0.3863\), \(0.1891\), \(0\), and \(0.6137\), respectively. Therefore \(D=1.1891\), and the deviance estimate is \(D/(4-1)=0.3964\). The three estimates differ because they use different summaries of the same residual pattern.

The Deviance Estimate

The gamma unit deviance measures the difference between the fitted model and a saturated model, which assigns each observation its own mean \(y_i\). For a common dispersion \(\phi\), the gamma log likelihood can be written, up to terms independent of the fitted mean, with mean-dependent contribution \(-\phi^{-1}[\log\mu_i+y_i/\mu_i]\). Comparing the fitted mean \(\hat\mu_i\) with the saturated mean \(y_i\) gives

$$ 2\{\ell_{\mathrm{sat}}-\ell_{\mathrm{fit}}\} =\frac{2}{\phi}\sum_{i=1}^n \left[\frac{y_i}{\hat\mu_i}-1-\log\left(\frac{y_i}{\hat\mu_i}\right)\right] =\frac{D}{\phi}. $$

The deviance estimate is \(\hat\phi_D=D/(n-p)\). Its degrees-of-freedom denominator is motivated by the fact that, near a good fit, deviance and Pearson variation agree to first order. To see the relationship, let \(z=y/\hat\mu\) and write \(z=1+u\). For small \(u\), Taylor expansion gives

$$ 2(z-1-\log z) =2\left(u-\log(1+u)\right) =u^2-\frac{2}{3}u^3+\frac{1}{2}u^4+O(u^5). $$

The leading term \(u^2\) is the squared Pearson residual. Consequently, when fitted ratios are close to one, deviance and Pearson estimates tend to be similar. For large residuals, the higher-order terms matter and the estimates need not agree.

Maximum Likelihood for Dispersion

The gamma likelihood uses more than a single residual sum of squares. Let \(k=1/\phi\) be the gamma shape, and suppose the fitted means are fixed at \(\hat\mu_i\). Define \(z_i=y_i/\hat\mu_i\). For positive observations, the part of the log likelihood that depends on \(k\) is

$$ \ell(k) =n\{k\log k-\log\Gamma(k)\} +(k-1)\sum_{i=1}^n\log y_i -k\sum_{i=1}^n\log\hat\mu_i -k\sum_{i=1}^n z_i. $$

Here \(\Gamma\) is the gamma function and \(\psi(k)=\frac{d}{dk}\log\Gamma(k)\) is the digamma function. Differentiating the displayed log likelihood gives the shape score. Setting it to zero and rearranging gives the likelihood equation for dispersion.

Result: The maximum-likelihood shape estimate \(\hat k\) solves \[ \log\hat k-\psi(\hat k) =\frac{1}{n}\sum_{i=1}^n(z_i-1-\log z_i) =\frac{D}{2n}, \] and the maximum-likelihood dispersion estimate is \(\hat\phi_{\mathrm{ML}}=1/\hat k\). This equation applies to positive observations and fitted means held at their maximum-likelihood estimates in the mean model.

To verify the equation, differentiate:

$$ \frac{d\ell}{dk} =n\{\log k+1-\psi(k)\} +\sum_{i=1}^n(\log z_i-z_i) =n\left[\log k-\psi(k)-\frac{1}{n}\sum_{i=1}^n(z_i-1-\log z_i)\right]. $$

The score is zero precisely when the stated equation holds. If the fitted means are estimated by maximum likelihood through a model \(\mu_i(\beta)\), the mean-dependent part of the score for \(\beta\) is multiplied by \(k\); its maximizing value of \(\beta\) does not depend on \(k\). Thus profiling over the mean parameters leads to the same dispersion equation, provided the fitted means are positive and the mean-model maximum exists.

There is at most one positive solution when \(D>0\). Indeed, the function \(g(k)=\log k-\psi(k)\) decreases strictly from infinity to zero as \(k\) goes from zero to infinity. For strict decrease, its derivative is \(1/k-\psi_1(k)<0\), since \(\psi_1(k)=\sum_{j=0}^\infty(k+j)^{-2}>\int_0^\infty(k+x)^{-2}\,dx=1/k\). The endpoint limits follow from the standard digamma limits \(\psi(k)\sim-1/k\) as \(k\) decreases to zero and \(\psi(k)=\log k-1/(2k)+O(k^{-2})\) as \(k\) increases. Also, \(z-1-\log z\geq0\) for \(z>0\), with equality only at \(z=1\). Hence \(D>0\) gives a unique root, while \(D=0\) places the likelihood maximum at the boundary \(\phi\downarrow0\). \(\square\)

Worked Example: Solving the Gamma Likelihood Equation

Use the ratios from the first example: \(z=(0.5,1.5,1,2)\). We already found \(D=1.1891\), so the right side of the likelihood equation is \(D/(2n)=1.1891/8=0.14864\). Solve \(\log k-\psi(k)=0.14864\).

At \(k=3.5\), \(\psi(3.5)=\psi(0.5)+1/0.5+1/1.5+1/2.5\). Using \(\psi(0.5)\approx-1.96351\), this is approximately \(1.10316\), so \(\log(3.5)-\psi(3.5)\approx1.25276-1.10316=0.14960\). This is slightly larger than \(0.14864\). Numerical solution gives \(\hat k\approx3.52\), for which \(\log(\hat k)-\psi(\hat k)\) is approximately \(0.1487\). Therefore \(\hat\phi_{\mathrm{ML}}=1/3.52\approx0.284\). This differs from the Pearson estimate \(0.5\) and deviance estimate \(0.3964\); maximum likelihood is not obtained by dividing a residual statistic by residual degrees of freedom.

When the Estimates Are Close—and When They Are Not

The estimates share a common purpose but not an identical calculation. The raw moment estimate matches the average squared relative residual to the gamma variance relationship. The Pearson estimate uses that same squared-residual statistic with a degrees-of-freedom adjustment. The deviance estimate uses the likelihood difference from a saturated fit and applies the same conventional adjustment. Maximum likelihood instead solves a nonlinear equation involving the full gamma likelihood.

Worked Example: A Close Fit Gives Similar Estimates

Suppose two known means are \(1\) and \(1\), with observations \(0.9\) and \(1.1\). Thus \(z=(0.9,1.1)\), and there are no estimated mean parameters, so \(p=0\). The Pearson contributions are \((0.9-1)^2=0.01\) and \((1.1-1)^2=0.01\). Hence \(X_P^2=0.02\) and \(X_P^2/n=0.01\).

The deviance contributions are \(2[-0.1-\log(0.9)]\approx0.01072\) and \(2[0.1-\log(1.1)]\approx0.00938\). Their sum is approximately \(0.02010\), so \(D/n\approx0.01005\), close to the Pearson estimate.

For maximum likelihood, \(D/(2n)\approx0.005025\). Since \(g(k)=\log k-\psi(k)\approx1/(2k)\) for large \(k\), the solution is approximately \(k\approx1/(2\times0.005025)\approx99.5\), giving \(\hat\phi_{\mathrm{ML}}\approx0.0101\). The close agreement is consistent with the small residuals and the expansion around \(z=1\); it is not a guarantee for data with more pronounced residuals.

Common Pitfall and Practical Interpretation

A frequent mistake is to call \(X_P^2/(n-p)\) an exactly unbiased gamma dispersion estimate in every fitted model. The exact moment identity applies when the true means are known: \(E[(Y_i-\mu_i)^2/\mu_i^2]=\phi\). Once means are fitted from the same responses, residuals are dependent on those estimates, and the simple projection argument is generally only approximate. The correction is to describe the Pearson and deviance estimates as conventional residual-degrees-of-freedom estimates, and to state the model and approximation when interpreting them.

A second mistake is to substitute \(D/(n-p)\) into the likelihood equation. The deviance estimate is a useful residual-based estimator; the likelihood estimate instead solves \(\log k-\psi(k)=D/(2n)\). The denominator \(n\) in this score equation is part of the likelihood derivation, not a residual degrees-of-freedom choice.

Key takeaway: Gamma dispersion describes squared relative variation. Pearson and deviance estimates summarize residual scatter with a conventional degrees-of-freedom correction; the maximum-likelihood estimate uses the full gamma likelihood and is found by solving a digamma equation.

Check Your Understanding

Use the definitions and derivations above to answer these questions.

  1. Why does \((Y_i-\mu_i)^2/\mu_i^2\) have expectation \(\phi\) when \(\mu_i\) is known?
  2. For a fitted model with rank \(p\), what is the Pearson estimate of dispersion, and why is its degrees-of-freedom adjustment generally approximate?
  3. What function of \(z_i=y_i/\hat\mu_i\) contributes to gamma unit deviance?
  4. State the equation that the maximum-likelihood shape estimate must solve, and explain how to obtain the dispersion estimate from that shape.
  5. Why do Pearson and deviance estimates tend to be close when all fitted ratios are near one?
Clinical Biostats