Ben Bolker bbolker at gmail.com
Fri Aug 23 15:51:54 PDT 2013

```On 13-08-22 05:26 AM, Lars Qviller wrote:
>
> I am trying to extract scaled residuals from a truncated negative
> binomial model using glmmadmb. I understand that it is possible to
> parameterize a negative binomial model in different ways. My two
> questions are:
> Is the negative binomial dispersion parameter in the ountput the same as
> is used to scale the residuals with the formula:
>
> (y-fitted(mod))/sqrt(fitted(mod)+ mod\$alpha*fitted(mod)^2)
>
> where "y" is the response of the fitted model "mod"?
>
> 2) is the formula correct?
>

r-sig-mixed-models at r-project.org rather than here, but:

According to the 'details' section of ?glmmadmb, for the default "NB2"
model:

• for ‘family=="nbinom"’:

Var(Y) = E(Y) * (1 + E(Y)/alpha)

i.e. the 'alpha' returned in the default (NB2) case actually corresponds
to what is more often called 'k' or 'theta' in other contexts [we should
consider renaming it].  So you should divide the fitted mean^2 by alpha
rather than multiplying it.

Whether the formula is correct depends on how you want to scale -- but
I think the answer is basically 'no'.  The truncated NB won't have the
same variance as the un-truncated NB (in fact as far as I can tell it
would be a bit of a pain to compute, although straightforward).

For example, using R (sorry! I'm happy if someone wants to contribute
ADMB code that does the same calculations ...)

> set.seed(101)
> r <- rnbinom(1e6,mu=1,size=0.5)
> var(r)
 2.990093  ## ~ mu + mu^2/'size'
> var(r[r>0])
 3.851681

You could compute the correction term due to truncation by
calculating the zero probability and adjusting the variance formula for
the changes in sum and sum of squares ...

Ben Bolker

```