# Marginal effects for negative binomial mixed effects models (glmer.nb and glmmTMB) #rstats

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**R – Strenge Jacke!**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here’s a small preview of forthcoming features in the ggeffects-package, which are already available in the GitHub-version: For marginal effects from models fitted with `glmmTMB()`

or `glmer()`

resp. `glmer.nb()`

, confidence intervals are now also computed.

If you want to test these features, simply install the package from GitHub:

```
library(devtools)
devtools::install_github("strengejacke/ggeffects")
```

Here are three examples:

```
library(glmmTMB)
library(lme4)
library(ggeffects)
data(Owls)
m1 <- glmmTMB(SiblingNegotiation ~ SexParent + ArrivalTime + (1 | Nest), data = Owls, family = nbinom1)
m2 <- glmmTMB(SiblingNegotiation ~ SexParent + ArrivalTime + (1 | Nest), data = Owls, family = nbinom2)
m3 <- glmer.nb(SiblingNegotiation ~ SexParent + ArrivalTime + (1 | Nest), data = Owls)
m4 <-
glmmTMB(
SiblingNegotiation ~ FoodTreatment + ArrivalTime + SexParent + (1 | Nest),
data = Owls,
ziformula = ~ 1,
family = list(family = "truncated_poisson", link = "log")
)
```

```
pr1 <- ggpredict(m1, c("ArrivalTime", "SexParent"))
plot(pr1)
```

```
pr2 <- ggpredict(m2, c("ArrivalTime", "SexParent"))
plot(pr2)
```

```
pr3 <- ggpredict(m3, c("ArrivalTime", "SexParent"))
plot(pr3)
```

```
pr4 <- ggpredict(
m4,
c("FoodTreatment", "ArrivalTime [21,24,30]", "SexParent")
)
plot(pr4)
```

The code to calculate confidence intervals is based on the FAQ provided from Ben Bolker. Here is another example, that reproduces this plot (note, since `age`

is numeric, `ggpredict()`

produces a straight line, and not points with error bars).

```
library(nlme)
data(Orthodont)
m5 <- lmer(distance ~ age * Sex + (age|Subject), data = Orthodont)
pr5 <- ggpredict(m5, c("age", "Sex"))
plot(pr5)
```

Tagged: data visualization, ggplot, R, rstats, sjPlot

To

**leave a comment**for the author, please follow the link and comment on their blog:**R – Strenge Jacke!**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.