Skip to content

Instantly share code, notes, and snippets.

@strengejacke
Created December 23, 2020 21:41
Show Gist options
  • Save strengejacke/647937637589e5fd30c1dfa8344f9639 to your computer and use it in GitHub Desktop.
Save strengejacke/647937637589e5fd30c1dfa8344f9639 to your computer and use it in GitHub Desktop.
ggpredict and glmmTMB
library(glmmTMB)
library(ggeffects)
data("Salamanders")
m1 <- glmmTMB(
count ~ mined + (1 | site),
zi = ~ mined,
family = poisson,
data = Salamanders
)
ggpredict(m1, "mined")
#> # Predicted counts of count
#> # x = mined
#>
#> x | Predicted | 95% CI
#> ------------------------------
#> yes | 1.09 | [0.69, 1.72]
#> no | 3.42 | [2.86, 4.09]
#>
#> Adjusted for:
#> * site = NA (population-level)
predict(m1, type = "conditional", newdata = data.frame(mined = c("yes", "no"), site = NA))
#> [1] 1.091875 3.420613
ggpredict(m1, "mined", type = "zero_inflated")
#> # Predicted counts of count
#> # x = mined
#>
#> x | Predicted | 95% CI
#> ------------------------------
#> yes | 0.26 | [0.11, 0.41]
#> no | 2.21 | [1.79, 2.62]
#>
#> Adjusted for:
#> * site = NA (population-level)
predict(m1, type = "response", newdata = data.frame(mined = c("yes", "no"), site = NA))
#> [1] 0.264723 2.206005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment