Negative binomial deviance (source code)

= Negative binomial deviance
{title2=$D=2\sum_i\left[y_i\log(y_i/e_i)-(y_i+\theta)\log\frac{y_i+\theta}{e_i+\theta}\right]$}

With known size $\theta>0$, the mean-dependent log mass of a <negative binomial distribution> is $y\log\mu-(y+\theta)\log(\mu+\theta)$. Its derivative is $\theta(y-\mu)/[\mu(\mu+\theta)]$, so the saturated mean is $y$, including its boundary value zero. Subtracting the fitted log mass from that maximum gives the displayed <deviance>. This formula needs no fitted-intercept cancellation. As $\theta\to\infty$, its second term tends to $-2(y_i-e_i)$ and it becomes the full <Poisson deviance>.