Significance Testing Of Differences Between Predictions IV: Contrasts And Comparisons For ZeroInflation Models
Source:vignettes/introduction_comparisons_4.Rmd
introduction_comparisons_4.Rmd
## Warning in checkDepPackageVersion(dep_pkg = "TMB"): Package version inconsistency detected.
## glmmTMB was built with TMB version 1.9.14
## Current TMB version is 1.9.15
## Please reinstall glmmTMB from source or restore original 'TMB' package (see '?reinstalling' for more information)
This vignette is the last in a 4part series:
Significance Testing of Differences Between Predictions I: Contrasts and Pairwise Comparisons
Significance Testing of Differences Between Predictions IV: Contrasts and Comparisons for ZeroInflation Models
Contrasts and comparisons for ZeroInflation Models
Lastly, we show an example for models with zeroinflation component.
What is a zeroinflated model?
A zeroinflated model is a statistical approach used when dealing with count data that has an excessive number of zero values. Imagine counting something that can be zero, like the number of customers a store gets in a day, and it happens that there are a lot more zeros in the data than a typical count model (e.g., Poisson regression) would ecpect. That’s where we need zeroinflated regression models. These models consider two ways zeros can happen:
True Zeros: These are days the store is naturally closed, or maybe there’s just no demand for the product.
Counting Zeros: These are days the store is open but just happens to get no customers. Maybe it’s bad luck, or a random fluctuation.
The model treats these differently. It uses one part (the zeroinflation component, a logistic regression) to predict the probability of a true zero, based on things that make the store less likely to be open at all. Then it uses another part (the conditional, or count component, a count regression) to predict the number of customers on days the store is actually open, considering other factors like weather or discounts.
Consequently, such regression models usually have two parts in their formula, or (depending on the package) separate formulas for the count and the zeroinflation components. Adjusted predictions can be calculated for both parts, and contrasts or comparisons can be calculated for both parts, too.
How to choose predictors for zeroinflation models?
The two model parts do not necessarily need to use the same predictors. Therefore, it is not always straightforward to find predictors that can be used in the zeroinflation model. Think about why you have excess zeros in your data. Are they true zeros (inherently no counts) or due to limitations (measurement limitations, biological process, …)? Choose variables that explain why some data points have zero counts even when conditions might allow for some count. For instance, if modeling customer complaints, store location in a remote area might predict zero complaints due to fewer customers.
Summary of most important points:
 For zeroinflation models, the model has two parts: a zeroinflation component and a count component. Adjusted predictions can be calculated for both parts, and contrasts or comparisons can be calculated for both parts, too.

The easiest way to compute contrasts or pairwise comparisons is simply to pass the result from
predict_response()
totest_predictions()
. Specify thetype
argument to calculate predictions and contrasts or comparisons for the corresponding model component.
Zeroinflation models using the glmmTMB package
In the following example, we use the Salamanders
dataset
from the glmmTMB
package.We fit a zeroinflated Poisson
regression model to the data, with mined
as the predictor
variable.
Adjusted predictions using predict_response()
can be
made for the different model components:
The conditional, or count component, which predicts the average count of salamanders. This is the default and uses
type = "fixed"
. This would return the predicted mean from the count component only, which is the conditional mean (average counts) of the reponse only for “counting zeros”. It does not take into account the probability of “true zeros”.The full model, which predicts the average count of the response, including the zeroinflation component. This would return the expected value of the response for an average observation, which can be a “true zero” or a “count zero”. Use
type = "zero_inflation"
to calculate adjusted predictions that also take the zeroinflation component into account. For the above example, use this option if you want to predict the average number of customers per week, including days the store is closed.The zeroinflation probabilities, which predicts the probabilities whether an observation is a “true zero” or not. Use
type = "zi_prob"
for this. It only related to the zeroinflation component of the model.
library(ggeffects)
library(glmmTMB)
data(Salamanders)
m < glmmTMB(count ~ mined + (1  site),
ziformula = ~mined,
family = poisson(),
data = Salamanders
)
Contrasts and comparisons for the conditional model
We will start with the conditional mean, using
margin = "empirical"
, as we want to average predictions
across random effects (see introduction
on random effects for details).
The easiest way to compute contrasts or pairwise comparisons is
simply to pass the result from predict_response()
to
test_predictions()
. The correct focal terms and model
components are automatically detected.
For zeroinflated models, the default type
of
predictions is "fixed"
, i.e. the conditional mean is
predicted. This is the average count of the response, excluding the
zeroinflation component.
# predicting the conditional mean
p < predict_response(m, "mined", margin = "empirical")
p
#> # Average predicted (conditional) counts of count
#>
#> mined  Predicted  95% CI
#> 
#> yes  1.12  0.61, 1.63
#> no  3.51  2.89, 4.14
test_predictions(p)
#> # Pairwise comparisons
#>
#> mined  Contrast  95% CI  p
#> 
#> yesno  2.39  3.18, 1.60  < .001
#>
#> Contrasts are presented as conditional means.
Contrasts and comparisons for the full model
If type = "zero_inflated"
, adjusted predictions are
returned for the full model, i.e. the average expected count of the
response, including the zeroinflation component.
# predicting the expected value of the response
p < predict_response(m, "mined", type = "zero_inflated", margin = "empirical")
p
#> # Average expected counts of count
#>
#> mined  Predicted  95% CI
#> 
#> yes  0.27  0.15, 0.40
#> no  2.27  1.86, 2.67
test_predictions(p)
#> # Pairwise comparisons
#>
#> mined  Contrast  95% CI  p
#> 
#> yesno  1.99  2.41, 1.58  < .001
#>
#> Contrasts are presented as counts.
Contrasts and comparisons for the zeroinflation probabilities
If you’re interested in the probabilities of being a “true zero” or
not, use type = "zi_prob"
. Note that margin
should not be "empirical"
in this case, because this will
not include confidence intervals for the adjusted predictions.
# predicting the zeroinflation probabilities
p < predict_response(m, "mined", type = "zi_prob")
p
#> # Predicted zeroinflation probabilities of count
#>
#> mined  Predicted  95% CI
#> 
#> yes  0.76  0.66, 0.83
#> no  0.36  0.30, 0.41
#>
#> Adjusted for:
#> * site = NA (populationlevel)
test_predictions(p)
#> # Pairwise comparisons
#>
#> mined  Contrast  95% CI  p
#> 
#> yesno  0.40  0.30, 0.50  < .001
#>
#> Contrasts are presented as probabilities (in %points).