# Is it possible to use two offsets?

I am doing negative binomial linear mixed model using lme4 package in R. My question is whether or not there is a way to put two offsets in glmer.nb or control one predictor variable of a model to see another predictor's effects. Using a model, I would like to test whether or not the number of aggression between males increases with the number of male and also with the number of females around them. My code is like this:

t <- glmer.nb(no.aggression~no.males+no.females+(1|id_target)+offset(log(hours)), data=x)


The response variable is the number of aggression between males which I observed during a day. Since the daily observation time varied over days, it was put in offset.

The number of males predicted the number of aggression but the number of females did not predict the number of aggression. However, the number of males was positively related with the number of females on the day. So I guess that males might be attracted by the females or something so when there are more females, there are more males. This might result in increase in the number of aggression of a given day. I thought that it will be possible to control the effect of number of males using two offsets or something, though I don't know the way to do that.

• (TWIMC, although this sounds like a question about how the R functions work, I think this is a meaningful statistical question.) – gung Dec 9 '16 at 1:51
• If the number of males and of females are correlated I would have added their sum as a single offset. I am not clear though that an offset has any advantages over adding them as covariates. – mdewey Dec 9 '16 at 12:31

An offset is generally just a coefficient set to a specific value. To get more than one offset, in general you just need to combine the different variables in a way that is consistent to get that fixed value.

In a Poisson equation if you set $Z$ as the offset (or exposure its sometimes called):

$$\log(\mathbb{E}[Y]) = \beta_0 + \beta_1X + 1\cdot Z$$

And you exponentiate both sides you then have:

$$\mathbb{E}[Y] = \text{exp}(\beta_0 + \beta_1X) \cdot \text{exp}(Z)$$

You can then interpret this as a rate per some unit $t$ if $Z = \text{log}(t)$:

$$\mathbb{E}[Y]/\text{exp}(\text{log}(t)) = \mathbb{E}[Y]/t = \text{exp}(\beta_0 + \beta_1X)$$

To get say two offsets we then start with:

$$\log(\mathbb{E}[Y]) = \beta_0 + \beta_1X + 1\cdot Z_1 + 1\cdot Z_2$$

Which we can exponentiate and regroup to be:

$$\mathbb{E}[Y] = \text{exp}(\beta_0 + \beta_1X) \cdot [\text{exp}(Z_1) \cdot \text{exp}(Z_2)]$$

Hopefully you see where I am going with this at this point. So if $Z_1 = \log(t_1)$ and $Z_2 = \log(t_2)$ we then have:

$$\mathbb{E}[Y]/(t_1 \cdot t_2) = \exp(\beta_0 + \beta_1X)$$

There are plenty of times to do this. Say you have people and then you have different exposure times for individuals, so you want the rate to be # of people*exposure time.

So to get two offsets in any software you simply need to add $\log(t_1) + \log(t_2)$, or equivalently $\log(t_1 \cdot t_2)$, and then specify that new variable as the offset. So in R you would just have offset(log(hours*no.males)) in your example. In other software you may need to calculate $\log(t_1 \cdot t_2)$ as one new variable and specify that (I think in Stata and SPSS you would need to do it that way at least).

Note for your particular example, that when setting an exposure term it is a restricted model compared to letting the effect of say log(hours) be something other than one. So I would suggest testing this via a likelihood ratio test, so something like:

Mod1 <- glmer.nb(no.aggression ~ log(no.males) + log(no.females)
+ (1|id_target) + offset(log(hours)), data=x)

Mod2 <- glmer.nb(no.aggression ~ log(no.females)
+ (1|id_target) + offset(log(hours*no.males)), data=x)

anova(Mod1,Mod2)


Where Mod2 is a more specific case of Mod1.

You could even have offset(log(hours*no.males*no.females)). This would make it a rate per all potential pairwise interactions (multiplied by hours). That does not sound too potentially inconsistent with what you have described, but currently you only have the linear no.males and no.females in the equation.

• I had interpreted the original question as requiring each variable to be entered with coefficient fixed to unity which i do not think your suggestion does. – mdewey Dec 9 '16 at 16:11
• Sure it does @mdewey. See after the first break, the original equation has $1 \cdot Z_1 + 1 \cdot Z_2$ on the right hand side - that is the coefficients set to unity. – Andy W Dec 9 '16 at 16:15
• Thanks @Andy. It is very cool that I can deal with it following your suggestion. The examples you suggested are very helpful to understand what is going on with the two offsets. Thank you again. – H. Ryu Dec 13 '16 at 7:48
• @mdewey, thank you for pointing out the concern. I guess my explanation was not clear as I am not a native English speaker. – H. Ryu Dec 13 '16 at 7:50