From a Fitted Model to Numerical Results
A gamma log-link regression turns a linear predictor into a positive fitted mean. In a worked analysis, the calculation does not end at the coefficients: we also need to quantify how dispersion affects uncertainty in fitted means and in comparisons between covariate values. This tutorial carries out those calculations and makes clear which uncertainties refer to the mean and which refer to a future response.
Assume independent responses \(Y_i\) with gamma distributions, means \(\mu_i\), and a common positive dispersion parameter \(\phi\), so that \(\operatorname{Var}(Y_i)=\phi\mu_i^2\). For a design vector \(x_i\) and coefficient vector \(\beta\), the log link specifies \(\log(\mu_i)=x_i^\mathsf{T}\beta\). Thus \(\hat{\mu}_i=\exp(x_i^\mathsf{T}\hat{\beta})\). The calculations below use the usual large-sample Wald approximation for coefficient uncertainty; the resulting intervals are approximate, not exact finite-sample intervals.
Worked Example: Fitted Means at Two Covariate Values
Worked Example: Fitted Means at Two Covariate Values
Suppose a fitted model for a positive clinical outcome has linear predictor \(\hat{\eta}=\log(20)+0.05x+\log(1.4)A\), where \(x\) is a continuous covariate and \(A\) is an indicator equal to 1 for the exposed group and 0 otherwise. Calculate fitted means at \(x=4\) for each group.
For the unexposed group, \(A=0\). The fitted linear predictor and fitted mean are
For the exposed group, \(A=1\), so
The fitted mean ratio at the same value of \(x\) is \(34.199/24.428\approx1.400\). The arithmetic checks directly: the only change in the two predictors is the added \(\log(1.4)\), whose exponential is \(1.4\). These are fitted means, not claims that every individual response in a group equals its fitted mean.
Why Dispersion Enters Coefficient Uncertainty
The covariance formula can be derived directly from the gamma likelihood. For this derivation, use the gamma density parameterized by mean \(\mu_i\) and dispersion \(\phi\):
With \(\log(\mu_i)=x_i^\mathsf{T}\beta\), terms in the log-likelihood that depend on \(\beta\) are \(y_i/(\phi\mu_i)\) with a negative sign and \(-\log(\mu_i)/\phi\). Differentiation gives the score contribution; differentiating once more gives the Hessian contribution:
Because \(E[Y_i/\mu_i]=1\), the expected negative Hessian for observation \(i\) is \(x_ix_i^\mathsf{T}/\phi\). Independence means the expected information contributions add. Summing over observations proves that the information matrix is \(X^\mathsf{T}X/\phi\). When \(X\) has full column rank, its inverse is \(\phi(X^\mathsf{T}X)^{-1}\). Under the usual regularity conditions for maximum likelihood asymptotics—an identifiable interior parameter, a correctly specified model, and a nonsingular limiting information matrix—this is the large-sample covariance of the coefficient estimator. Replacing \(\phi\) by an estimate gives the stated plug-in covariance estimate. \(\square\)
This derivation explains the role of dispersion: larger \(\phi\) multiplies coefficient variances, and hence standard errors, by a larger amount. In a routine fit, \(\phi\) may be estimated in several ways. The next example uses the Pearson estimate divided by residual degrees of freedom; it is an estimate, not a declaration that the true dispersion is known.
Worked Example: A Two-Group Fit and Its Dispersion-Adjusted Uncertainty
Worked Example: A Two-Group Fit and Its Dispersion-Adjusted Uncertainty
Consider eight independent positive responses: 8, 9, 11, and 12 in the unexposed group, and 12, 14, 16, and 18 in the exposed group. Fit a gamma log-link model with an intercept and a binary exposure indicator \(A\), so that \(\log(\mu_i)=\beta_0+\beta_1A_i\).
This two-parameter model allows a separate mean for each group. For a group with common fitted mean \(\mu\), the part of the log-likelihood depending on \(\mu\) is \(-\sum_i y_i/(\phi\mu)-m\log(\mu)/\phi\), where \(m\) is the group size. Setting its derivative with respect to \(\mu\) to zero gives \(\sum_i y_i/( \phi\mu^2)-m/(\phi\mu)=0\), and therefore \(\hat{\mu}=\sum_i y_i/m\). The unexposed mean is \((8+9+11+12)/4=10\); the exposed mean is \((12+14+16+18)/4=15\). Hence
The fitted mean ratio for exposed versus unexposed is \(\exp(\hat{\beta}_1)=1.5\). To estimate dispersion, calculate the Pearson residual sum of squares. In the unexposed group, the squared deviations from 10 sum to \(4+1+1+4=10\), so its contribution after division by \(10^2\) is \(10/100=0.1\). In the exposed group, squared deviations from 15 sum to \(9+1+1+9=20\), giving \(20/225\approx0.088889\). There are \(8-2=6\) residual degrees of freedom, so
With four observations in each group, the design matrix has \(X^\mathsf{T}X=\left(\begin{smallmatrix}8&4\\4&4\end{smallmatrix}\right)\), whose inverse is \(\left(\begin{smallmatrix}1/4&-1/4\\-1/4&1/2\end{smallmatrix}\right)\). The estimated coefficient covariance matrix is therefore
In particular, \(\widehat{\operatorname{Var}}(\hat{\beta}_1)=(17/540)(1/2)=17/1080\), so the dispersion-adjusted standard error of the log mean ratio is \(\sqrt{17/1080}\approx0.1255\). A 95% Wald interval on the log-ratio scale is \(0.4055\pm1.96(0.1255)\), or approximately \((0.1596,0.6514)\). Exponentiating both endpoints gives an approximate 95% interval for the ratio of \((1.173,1.918)\). The interval uses the estimated dispersion; omitting that factor would not give the covariance estimate specified by this model.
The same matrix quantifies uncertainty in each fitted mean. The coefficient vector for the unexposed mean has design vector \((1,0)^\mathsf{T}\), giving log-mean standard error \(\sqrt{(17/540)(1/4)}\approx0.0887\). For the exposed mean, the vector is \((1,1)^\mathsf{T}\), giving variance \((17/540)(1/4-1/2+1/2)=(17/540)(1/4)\), also about \(0.00787\). Thus both fitted log means have standard error about \(0.0887\) in this balanced design. Their estimated means differ, but the model gives them equal log-scale precision here.
Uncertainty for Means and Contrasts
The calculations above follow from a general first-order result. Suppose \(\hat{\beta}\) is approximately normal with mean \(\beta\) and covariance matrix \(V\), and let \(g(\beta)\) be differentiable. A first-order Taylor expansion around \(\beta\) gives \(g(\hat{\beta})\approx g(\beta)+\nabla g(\beta)^\mathsf{T}(\hat{\beta}-\beta)\). The variance of this linear term is \(\nabla g(\beta)^\mathsf{T}V\nabla g(\beta)\). Substituting estimates for unknown quantities yields the usual delta-method variance estimate. For a log-link fitted mean at design vector \(x\), the gradient of \(\mu=\exp(x^\mathsf{T}\beta)\) is \(\mu x\). For a log mean ratio between two design vectors, define \(c=x_a-x_b\); the ratio is \(R=\exp(c^\mathsf{T}\beta)\), with log-ratio standard error \(\sqrt{c^\mathsf{T}Vc}\). These approximations require the coefficient estimator to have the stated large-sample normal approximation and the relevant covariance matrix to be estimable.
Worked Example: A Continuous-Covariate Contrast
Worked Example: A Continuous-Covariate Contrast
Suppose a fitted model has \(\hat{\beta}_1=0.12\) for a continuous covariate \(x\), and the estimated covariance matrix is \(\hat{\phi}V_0\), where \(\hat{\phi}=0.09\) and \((V_0)_{11}=0.02\). Compare fitted means at \(x=5\) and \(x=2\), holding all other covariates fixed.
The difference in the two design vectors is three units in the \(x\)-coefficient and zero in the other coefficients. Thus \(c^\mathsf{T}\hat{\beta}=3(0.12)=0.36\), and the estimated mean ratio is \(\exp(0.36)\approx1.433\). Its log-scale variance includes the dispersion multiplier:
The 95% Wald interval on the log scale is \(0.36\pm1.96(0.1273)\), approximately \((0.1105,0.6095)\). Exponentiating gives a mean-ratio interval of approximately \((1.117,1.840)\). The numerical interval describes uncertainty in the ratio of fitted means, not the range in which an individual future response must fall.
Common Mistake: Confusing Mean Uncertainty with Response Variation
A fitted mean is an estimated model quantity, whereas a future gamma response also has intrinsic variation around that mean. For a future response at covariate vector \(x\), the model variance is \(\phi\mu^2\). The estimated uncertainty in the fitted mean instead comes from uncertainty in \(\hat{\beta}\); on the log scale its estimated variance is \(x^\mathsf{T}\widehat{\operatorname{Cov}}(\hat{\beta})x\). These quantities answer different questions and should not be substituted for one another.
- Wrong reasoning: “The standard error of the fitted mean is \(\sqrt{\hat{\phi}}\hat{\mu}\), because that is the gamma standard deviation.”
- Correction: \(\sqrt{\hat{\phi}}\hat{\mu}\) estimates the response standard deviation at a specified mean. For uncertainty in the estimated mean, first calculate the log-mean variance \(x^\mathsf{T}\widehat{\operatorname{Cov}}(\hat{\beta})x\), then use the delta method if a standard error on the response mean scale is wanted.
- Wrong reasoning: “A mean-ratio standard error can be calculated from the standard error of one coefficient in every contrast.”
- Correction: Use the whole contrast \(c\) and the full coefficient covariance matrix: the log-ratio variance is \(c^\mathsf{T}\widehat{\operatorname{Cov}}(\hat{\beta})c\). Covariances between coefficient estimates can matter.
Check Your Understanding
Use the log-link and dispersion-adjusted covariance ideas to answer these questions.
- For a fitted predictor \(\hat{\eta}=\log(8)+0.1x\), calculate the fitted mean at \(x=3\).
- In a binary-exposure model, why is the fitted mean ratio obtained by exponentiating the exposure coefficient?
- In the two-group example, which entries of the coefficient covariance matrix are needed to estimate the variance of the log mean ratio?
- Explain why \(\sqrt{\hat{\phi}}\hat{\mu}\) is not, by itself, the standard error of a fitted mean.
- For a covariate contrast \(c\), write the estimated variance of the log mean ratio using the coefficient covariance matrix.