Skip to content
Prev 19687 / 20628 Next

Truncated Negative Binomial Model Unexpected Marginal Means

A quick test suggests that emmeans is predicting the response based on 
the mean of the *un*truncated distribution (I don't remember and/or 
haven't looked into all of the guts of emmeans).  Don't know if Russ 
Lenth (emmeans maintainer) is reading ...

n <- 1000
dd <- data.frame(f = factor(rep(1:2, each = n)))
gb <- log(c(2,4))
set.seed(101)
dd <- transform(dd, y = rnbinom(2*n, mu = exp(gb[f]), size = 2))
dd2 <- subset(dd, y > 0)

## un-truncated means
aggregate(y ~ f, data = dd, FUN = mean)
##   f        y
## 1 1 2.047
## 2 2 3.917

## truncated means
aggregate(y ~ f, data = dd2, FUN = mean)
##   f        y
## 1 1 2.781250
## 2 2 4.446084

library(glmmTMB)
library(emmeans)
m1 <- glmmTMB(y ~ f, family = truncated_nbinom2, data = dd2)

## doesn't match exactly but close to untruncated means
emmeans(m1, ~ f, type = "response")
##  f response     SE   df lower.CL upper.CL
##  1     2.15 0.0891 1614     1.99     2.34
##  2     3.98 0.1262 1614     3.74     4.23

## matches means exactly
m2 <- glmmTMB(y ~ f, family = nbinom2, data = dd)
emmeans(m2, ~ f, type = "response")
##  f response     SE   df lower.CL upper.CL
##  1     2.05 0.0651 1997     1.92     2.18
##  2     3.92 0.1094 1997     3.71     4.14
On 2/15/22 10:04 AM, Alex Waldman wrote: