
Testing for excess zeros (and why not the Vuong test)
Source:vignettes/testing-for-excess-zeros.Rmd
testing-for-excess-zeros.Rmdvignette("zeros-hurdles-and-sampling", package = "flexCountReg")
explains what zero-inflated and hurdle models assume and stresses that a
separate zero process needs a substantive justification. This vignette
covers the complementary, statistical question: does a fitted
count model reproduce the number of zeros in the data, and does adding a
zero-inflation component improve the fit by more than chance?
It shows:
- why the Vuong test, still the most common “test for zero inflation”, is not valid for that purpose;
-
zero_test(), a count-of-zeros test that needs no zero-inflated model and works with any count family; - the boundary-corrected likelihood-ratio test that
regCompTest()reports for a constant zero-inflation component; -
bootstrap_lrtest(), a parametric bootstrap likelihood-ratio test for cases with no valid closed-form reference distribution; - how to read the results without over-interpreting them.
A statistical test can say that a model has too many (or too few) zeros, or that a zero component fits better. It cannot say why. Excess zeros relative to a Poisson model are often explained by overdispersion (Warton, 2005), and excess zeros relative to any model can come from a misspecified mean. Read every result below as evidence about fit, not about mechanism.
Why not the Vuong test
Vuong’s (1989) test compares two models by the mean of the pointwise log-likelihood differences \(m_i = \log f_1(y_i) - \log f_2(y_i)\), scaled by their standard deviation. It is widely used to compare a zero-inflated model with its non-inflated counterpart, but the literature identifies three problems.
- The models are nested, not non-nested. NB2 is zero-inflated NB2 with \(\pi = 0\). Vuong’s asymptotic results are for strictly non-nested or overlapping models, and Wilson (2015) shows that a model and its zero-inflated counterpart are neither. The null value \(\pi = 0\) is also on the boundary of the parameter space, so the usual normal theory does not apply. A significant Vuong statistic says only that one model fits closer in Kullback-Leibler terms, not that zero inflation is present, and the test cannot detect zero deflation.
- The statistic is degenerate exactly under the null. When there is no zero inflation, the fitted \(\hat\pi\) is at or near 0, the two fitted models nearly coincide, every \(m_i\) is near 0, and the standardized statistic divides one near-zero quantity by another.
- The uncorrected statistic favors the larger model. Without Vuong’s own penalty for the extra parameters, the test leans toward the zero-inflated model even when the data contain no zero inflation (Desmarais and Harden, 2013). The AIC/BIC-corrected versions they propose fix the bias but not problems 1 and 2. He et al. (2019) add that the result depends on how the zero component is specified (which covariates enter it).
flexCountReg deliberately provides no Vuong test. The degeneracy in point 2 is easy to see: simulate NB2 data with no zero inflation, fit NB2 and zero-inflated NB2, and look at the pointwise differences.
set.seed(2024)
n <- 1000
x <- rnorm(n)
mu <- exp(1 + 0.5 * x)
d0 <- data.frame(x = x, y = rnbinom(n, size = 4, mu = mu))
nb2_0 <- countreg(y ~ x, data = d0, family = "NB2", method = "BFGS")
zinb_0 <- suppressWarnings(
countreg(y ~ x, data = d0, family = "NB2", zero_formula = ~ 1,
method = "BFGS"))
# Pointwise log-likelihood: log P(Y_i = y_i) from type = "prob"
pointwise_ll <- function(m, y) {
P <- predict(m, type = "prob", max_count = max(y))
log(P[cbind(seq_along(y), y + 1)])
}
ll_nb2 <- pointwise_ll(nb2_0, d0$y)
m_i <- pointwise_ll(zinb_0, d0$y) - ll_nb2
vuong <- c(pi_hat = plogis(coef(zinb_0)[["Zero:(Intercept)"]]),
mean_m = mean(m_i), sd_m = sd(m_i),
vuong_z = sqrt(n) * mean(m_i) / sd(m_i))
round(vuong, 4)
#> pi_hat mean_m sd_m vuong_z
#> 0.0202 0.0013 0.0526 0.8069The estimated zero-inflation probability is 0.02, and the pointwise differences have mean 0.0013 and standard deviation 0.053, against an average pointwise log-likelihood of -2.07. The two fitted models barely differ, and the \(z\) statistic is a ratio of two small quantities. When \(\hat\pi\) reaches 0, which happens often when there is no zero inflation, every \(m_i\) is 0 and the statistic is not defined at all. The tests below avoid these problems.
Data with a known answer
Two datasets with the same covariate and mean: one ordinary NB2 count
(the d0 above) and one in which 20% of the observations are
structural zeros.
set.seed(2025)
d1 <- data.frame(x = x,
y = ifelse(runif(n) < 0.2, 0,
rnbinom(n, size = 4, mu = mu)))
c(zeros_nb2_data = mean(d0$y == 0), zeros_zinb_data = mean(d1$y == 0))
#> zeros_nb2_data zeros_zinb_data
#> 0.145 0.313
nb2_1 <- countreg(y ~ x, data = d1, family = "NB2", method = "BFGS")
zinb_1 <- suppressWarnings(
countreg(y ~ x, data = d1, family = "NB2", zero_formula = ~ 1,
method = "BFGS"))How easily zero inflation can be detected depends on the count distribution, not only on the share of structural zeros. With strongly overdispersed small counts (for example size 1 and a mean near 1.5, where about 45% of the counts are zero anyway), NB2 absorbs much of a 15% zero inflation through a larger dispersion, and every test below loses much of its power at this sample size. The data here are moderately overdispersed (size 4) with a mean near 3.
Step 1: choose the baseline before testing for zeros
Zero inflation is always relative to a model. Testing a zero
component against Poisson mostly detects overdispersion, so the baseline
should be the best non-inflated model (here NB2; see
vignette("choosing-a-count-distribution", package = "flexCountReg")).
Ridout et al. (2001) show that a zero-inflated Poisson fitted to
overdispersed counts gives biased estimates, which is the same point
from the other side.
zero_test() compares the observed number of zeros with
the number expected under a fitted model:
pois_0 <- countreg(y ~ x, data = d0, family = "POISSON", method = "BFGS")
pois_1 <- countreg(y ~ x, data = d1, family = "POISSON", method = "BFGS")
zero_summary <- function(t) {
c(observed = unname(t$statistic), expected = unname(t$estimate),
lower_95 = unname(t$null_interval[1]),
upper_95 = unname(t$null_interval[2]), p_value = t$p.value)
}
zt <- rbind(
"NB2 data, Poisson" = zero_summary(zero_test(pois_0)),
"NB2 data, NB2" = zero_summary(zero_test(nb2_0)),
"ZINB data, Poisson" = zero_summary(zero_test(pois_1)),
"ZINB data, NB2" = zero_summary(zero_test(nb2_1)))
round(zt, 4)
#> observed expected lower_95 upper_95 p_value
#> NB2 data, Poisson 145 90.8144 74 108 0.0000
#> NB2 data, NB2 145 140.2676 120 161 0.6489
#> ZINB data, Poisson 313 137.7708 118 158 0.0000
#> ZINB data, NB2 313 285.5623 259 313 0.0497The Poisson model fails the test on both datasets (p < 0.0001 and p < 0.0001), including the one with no zero inflation at all: it expects only 91 zeros where the NB2 data have 145. Against NB2, the NB2 data pass (p = 0.649), and the zero-inflated data show 313 zeros against 286 expected (p = 0.0497), an excess, but only just. The excess is much smaller than the 200 structural zeros in the data, because the NB2 fit absorbs part of them; Steps 3 and 4 detect the zero inflation more clearly.
Step 2: the count-of-zeros test
Under a fitted model, observation \(i\) is zero with probability \(p_i = \hat P(Y_i = 0)\). If the model is
correct, the number of zeros \(Z = \sum_i
1\{y_i = 0\}\) follows a Poisson-binomial distribution
with probabilities \(p_1, \dots, p_n\).
Comparing the observed \(Z\) with that
distribution gives an exact test of zero modification,
inflation or deflation, that needs no zero-inflated model (Wilson and
Einbeck, 2019; for related tests built on the observed versus expected
share of zeros, see He et al., 2019, and Tang and Tang, 2019).
null_interval is the central 95% range of \(Z\) under the fitted model, and the p-value
uses the mid-p convention for a discrete statistic.
zero_test(nb2_1)
#>
#> Exact Poisson-binomial test of zero modification
#>
#> data: y ~ x (NB2)
#> observed = 313, p-value = 0.04969
#> alternative hypothesis: two.sided
#> sample estimates:
#> expected
#> 285.5623
zero_test(nb2_1, alternative = "greater") # inflation only
#>
#> Exact Poisson-binomial test of zero modification
#>
#> data: y ~ x (NB2)
#> observed = 313, p-value = 0.02484
#> alternative hypothesis: greater
#> sample estimates:
#> expected
#> 285.5623The computation is short enough to show in full. The Poisson-binomial distribution is built by convolution:
p0 <- predict(nb2_1, type = "prob", max_count = 0)[, 1]
f <- 1
for (pk in p0) f <- c(f * (1 - pk), 0) + c(0, f * pk) # P(Z = 0..n)
z <- sum(d1$y == 0)
upper <- sum(f[(z + 1):length(f)]) - 0.5 * f[z + 1]
lower <- sum(f[1:(z + 1)]) - 0.5 * f[z + 1]
c(by_hand = min(1, 2 * min(upper, lower)),
zero_test = zero_test(nb2_1)$p.value)
#> by_hand zero_test
#> 0.0496869 0.0496869zero_test() does the same convolution in compiled code,
so it stays fast for tens of thousands of observations (above
exact_max_n, 20,000 by default, it switches to a normal
approximation).
Because only \(p_i\) is needed, the same test applies to any count value (Wilson and Einbeck, 2015). Testing each small count in turn shows where a model’s probabilities go wrong:
scan <- t(sapply(0:5, function(k)
zero_summary(zero_test(nb2_1, value = k))))
rownames(scan) <- paste0("y = ", 0:5)
round(scan, 4)
#> observed expected lower_95 upper_95 p_value
#> y = 0 313 285.5623 259 313 0.0497
#> y = 1 161 216.4701 191 242 0.0000
#> y = 2 143 150.1408 128 173 0.5313
#> y = 3 123 102.6124 84 122 0.0374
#> y = 4 87 70.3580 55 87 0.0445
#> y = 5 53 48.6898 36 62 0.5175Under NB2 the zero-inflated data show too many zeros (313 against 286) and, more clearly, too few ones (161 against 216, p < 0.0001): to accommodate the extra zeros, the NB2 fit takes a larger dispersion, which moves probability from the ones to both the zeros and the larger counts (here 3 and 4, observed more often than expected). Under the zero-inflated fit none of the counts 0 to 5 departs from its expected frequency (the smallest p-value is 0.2).
Two caveats keep this honest:
- With
method = "exact", the \(p_i\) are plugged in from a model fitted to the same data, which ignores estimation uncertainty. If zeros are inflated, the baseline fit absorbs some of them, which pulls \(p_i\) up and costs power; the test is also conservative when the model is correct.method = "bootstrap"(Step 4) refits the model to each simulated dataset and accounts for both. - A significant result says the baseline gets the zeros wrong. A misspecified mean or the wrong count family can do that as well as a separate zero process.
Step 3: a likelihood-ratio test on the boundary
The LR statistic \(LR = 2(\ell_{ZINB} -
\ell_{NB2})\) compares the nested models directly. Because \(\pi = 0\) is on the boundary, \(LR\) does not follow \(\chi^2_1\). With a
constant zero-inflation probability, its asymptotic
null distribution is the 50:50 mixture \(\tfrac12\chi^2_0 + \tfrac12\chi^2_1\) (Self
and Liang, 1987), so the p-value is half the \(\chi^2_1\) tail. regCompTest()
recognizes this restriction and reports the corrected p-value:
lr0 <- regCompTest(zinb_0, model2 = nb2_0)
lr1 <- regCompTest(zinb_1, model2 = nb2_1)
lrt <- rbind(
nb2_data = c(LR = lr0$LR, p_boundary = lr0$LR_pvalue,
p_naive_chisq1 = pchisq(lr0$LR, 1, lower.tail = FALSE)),
zinb_data = c(LR = lr1$LR, p_boundary = lr1$LR_pvalue,
p_naive_chisq1 = pchisq(lr1$LR, 1, lower.tail = FALSE)))
signif(lrt, 4)
#> LR p_boundary p_naive_chisq1
#> nb2_data 2.685 5.066e-02 1.013e-01
#> zinb_data 47.540 2.694e-12 5.387e-12The naive \(\chi^2_1\) p-value is twice the correct one, so it is conservative. On the zero-inflated data the evidence is overwhelming (LR = 47.5), far stronger than the count-of-zeros test above: the likelihood uses the whole distribution, including the shortage of ones. On the NB2 data the boundary p-value is 0.0507, just above the 5% level. Data without zero inflation give a p-value this small in a minority of samples, which is what the level of a test allows; this sample is one of them, and the estimated zero-inflation probability above is small but not 0.
The correction has limits, and regCompTest() reports no
LR test (with a reason in LR_reason) outside them:
-
Covariates in the zero model. When
zero_formulahas covariates, the slopes of the zero model are not identified under \(\pi = 0\), and the \(\tfrac12\chi^2_0 + \tfrac12\chi^2_m\) approximation sometimes quoted for this case is not justified by standard boundary theory. - Two boundaries at once. Poisson against zero-inflated NB2 restricts both the dispersion and \(\pi\) to their boundaries; the one-parameter mixture does not apply.
- Hurdle models. A hurdle model’s zero part replaces, rather than extends, the count distribution’s zeros, so NB2 is not a parameter restriction of a hurdle NB2 model. Compare hurdle models with AIC/BIC or held-out log scores.
Score tests (van den Broek, 1995, against Poisson; Ridout et al., 2001, for ZIP against ZINB; Yang et al., 2010, for zero inflation in overdispersed data) need only the null model, but Min and Czado (2010) found substantial power losses relative to the Wald and LR tests, so flexCountReg does not implement them.
Step 4: parametric bootstrap
The bootstrap replaces asymptotic reference distributions with ones
simulated from the fitted null model, refitting each simulated dataset
so that the reference distribution includes estimation uncertainty.
bootstrap_lrtest() simulates from the restricted model with
simulate() and refits both models;
zero_test(method = "bootstrap") does the same for the count
of zeros.
bt0 <- bootstrap_lrtest(nb2_0, zinb_0, B = B, seed = 1)
bt0
#>
#> Parametric bootstrap likelihood-ratio test
#>
#> data: restricted: y ~ x (NB2)
#> full: y ~ x, zero ~1 (NB2, zero-inflated)
#> LR = 2.6848, B = 29, p-value = 0.1
bt1 <- bootstrap_lrtest(nb2_1, zinb_1, B = B, seed = 2)
bt1
#>
#> Parametric bootstrap likelihood-ratio test
#>
#> data: restricted: y ~ x (NB2)
#> full: y ~ x, zero ~1 (NB2, zero-inflated)
#> LR = 47.541, B = 29, p-value = 0.03333
zt_boot <- zero_test(nb2_1, method = "bootstrap", B = B, seed = 3)
zt_boot
#>
#> Parametric bootstrap test of zero modification
#>
#> data: y ~ x (NB2)
#> observed = 313, p-value = 0.03333
#> alternative hypothesis: two.sided
#> sample estimates:
#> expected
#> 285.5623The bootstrap LR test leads to the same conclusions as the
boundary-corrected test: p = 0.1 on the NB2 data (asymptotic p = 0.0507)
and p = 0.0333 (the smallest attainable with 29 replicates) on the
zero-inflated data. The asymptotic p-value is stored in
asymptotic_p. The bootstrap count-of-zeros test gives p =
0.0333 (the smallest attainable with 29 replicates), against p = 0.0497
for the exact version. Refitting NB2 to each dataset simulated from NB2
shows how much the fit itself pulls the expected number of zeros toward
the observed one, and the bootstrap reference distribution takes that
into account, so it is less conservative than the exact test.
The bootstrap is the method to use when the zero model has
covariates, where regCompTest() reports no LR test:
zinb_x <- suppressWarnings(
countreg(y ~ x, data = d1, family = "NB2", zero_formula = ~ x,
method = "BFGS"))
lr_x <- suppressWarnings(regCompTest(zinb_x, model2 = nb2_1))
lr_x$LR_pvalue
#> [1] NA
lr_x$LR_reason
#> [1] "the zero-model slopes are not identified when the zero-inflation probability is 0; use bootstrap_lrtest()"
bootstrap_lrtest(nb2_1, zinb_x, B = B, seed = 4)
#>
#> Parametric bootstrap likelihood-ratio test
#>
#> data: restricted: y ~ x (NB2)
#> full: y ~ x, zero ~x (NB2, zero-inflated)
#> LR = 47.915, B = 29, p-value = 0.03333With 29 replicates the smallest attainable p-value is 0.033; use several hundred replicates for reported results. The number of failed refits is reported; if it is more than a few percent, the bootstrap p-value should not be trusted. Each replicate refits the larger model from two starting points (its own estimates and the restricted model’s estimates with a zero-inflation probability near 0) and keeps the better fit, so that a refit stuck at a local maximum does not distort the reference distribution.
Step 5: look at the whole distribution
A test on the zeros alone can miss a model that gets the zeros right and the ones and twos wrong. A rootogram (Kleiber and Zeileis, 2016) shows the fit at every count:
op <- par(mfrow = c(1, 2))
rootogram(nb2_1, max_count = 10, main = "NB2")
rootogram(zinb_1, max_count = 10, main = "Zero-inflated NB2")
par(op)In these hanging rootograms a bar that ends below zero marks a count
observed more often than expected. Under NB2 the zero bar ends below
zero (more zeros observed than expected) and the bar for one ends above
it (too few ones); the zero-inflated model removes that pattern.
vignette("diagnosing-count-models", package = "flexCountReg")
covers rootograms and probability calibration in more detail.
An applied example: articles by PhD biochemists
e <- new.env()
utils::data("bioChemists", package = "pscl", envir = e)
b <- e$bioChemists
fb <- art ~ fem + mar + kid5 + phd + ment
nb2_b <- countreg(fb, data = b, family = "NB2", method = "BFGS")
zinb_b <- suppressWarnings(
countreg(fb, data = b, family = "NB2", zero_formula = ~ 1,
method = "BFGS"))
zt_b <- zero_test(nb2_b)
zt_b
#>
#> Exact Poisson-binomial test of zero modification
#>
#> data: art ~ fem + mar + kid5 + phd + ment (NB2)
#> observed = 275, p-value = 0.8421
#> alternative hypothesis: two.sided
#> sample estimates:
#> expected
#> 277.7901
lr_b <- regCompTest(zinb_b, model2 = nb2_b)
c(LR = lr_b$LR, LR_pvalue = lr_b$LR_pvalue,
pi_hat = plogis(coef(zinb_b)[["Zero:(Intercept)"]]))
#> LR LR_pvalue pi_hat
#> 0.000000e+00 1.000000e+00 4.442605e-06NB2 already reproduces the share of zeros in these data (275
observed, 278 expected, p = 0.842), and a constant zero-inflation
probability adds nothing: its estimated probability is essentially 0
(4e-06), so LR = 0 and the boundary-corrected p = 1. This is the
degenerate case of the Vuong test in real data: the two fitted models
coincide. The zero model with covariates in
vignette("zeros-hurdles-and-sampling", package = "flexCountReg")
does improve AIC, which says that the probability of a zero varies with
the covariates in a way the NB2 mean does not capture. That is a
statement about the shape of the fit, not proof of “structural
non-publishers”.
Interpreting the results
- Decide on substantive grounds first. Whether a separate zero-generating process is plausible is a question about the data collection and the subject matter (Blasco-Moreno et al., 2019). The tests above check a model; they do not identify a mechanism.
- Many zeros are not zero inflation. A low mean or a large variance produces many zeros by itself (Warton, 2005). Test against the best non-inflated family, not against Poisson.
-
Pretesting has a cost. Choosing the model with a
preliminary test and then reporting the chosen model’s inference as if
it had been fixed in advance can inflate false-positive rates,
particularly in small samples (Campbell, 2021). When the choice is
uncertain, report the key estimates under both models, or compare them
on held-out data
(
vignette("predictive-validation", package = "flexCountReg")). - Explicit and implicit zero inflation compete. A more flexible count family can reproduce excess zeros without a separate component (Haslett et al., 2022). If a zero component and a more flexible family fit about equally well, the simpler story usually deserves the benefit of the doubt.
| Question | flexCountReg | Needs a zero-inflated fit? | Notes |
|---|---|---|---|
| Are the zeros consistent with the baseline? | zero_test() |
No | Exact Poisson-binomial; detects inflation and deflation; any family; conservative |
| Same, with estimation uncertainty | zero_test(method = "bootstrap") |
No (refits baseline) | Slower; better calibrated |
| Is any other count over- or under-represented? | zero_test(value = k) |
No | Scan small counts |
| Does a constant zero component improve fit? | regCompTest(zi_fit, model2 = base_fit) |
Yes | \(\tfrac12\chi^2_0 + \tfrac12\chi^2_1\); asymptotic |
| Same, with covariates in the zero model | bootstrap_lrtest() |
Yes | No valid closed form |
| Where does the fit fail? |
rootogram(), calibration |
No | Looks beyond the zeros |
| Which model to use? |
regCompTable(), held-out log score |
Yes | Valid for nested and non-nested models alike, including hurdle models |
| Yes | Not valid for nested models (Wilson, 2015); not provided |
Reproducibility
The simulations use set.seed(2024) and
set.seed(2025); the bootstrap calls use seeds 1 to 4. The
number of bootstrap replicates is read from the environment variable
FCR_VIGNETTE_B (default 29).
References
Blasco-Moreno, A., Pérez-Casany, M., Puig, P., Morante, M. and Castells, E. (2019). What does a zero mean? Understanding false, random and structural zeros in ecology. Methods in Ecology and Evolution, 10(7), 949-959.
Campbell, H. (2021). The consequences of checking for zero-inflation and overdispersion in the analysis of count data. Methods in Ecology and Evolution, 12(4), 665-680.
Desmarais, B. A. and Harden, J. J. (2013). Testing for zero inflation in count models: Bias correction for the Vuong test. Stata Journal, 13(4), 810-835.
Haslett, J., Parnell, A. C., Hinde, J. and de Andrade Moral, R. (2022). Modelling excess zeros in count data: A new perspective on modelling approaches. International Statistical Review, 90(2), 216-236.
He, H., Zhang, H., Ye, P. and Tang, W. (2019). A test of inflated zeros for Poisson regression models. Statistical Methods in Medical Research, 28(4), 1157-1169.
Kleiber, C. and Zeileis, A. (2016). Visualizing count data regressions using rootograms. The American Statistician, 70(3), 296-303.
Min, A. and Czado, C. (2010). Testing for zero-modification in count regression models. Statistica Sinica, 20(1), 323-341.
Ridout, M., Hinde, J. and Demétrio, C. G. B. (2001). A score test for testing a zero-inflated Poisson regression model against zero-inflated negative binomial alternatives. Biometrics, 57(1), 219-223.
Self, S. G. and Liang, K.-Y. (1987). Asymptotic properties of maximum likelihood estimators and likelihood ratio tests under nonstandard conditions. Journal of the American Statistical Association, 82(398), 605-610.
Tang, Y. and Tang, W. (2019). Testing modified zeros for Poisson regression models. Statistical Methods in Medical Research, 28(10-11), 3123-3141.
van den Broek, J. (1995). A score test for zero inflation in a Poisson distribution. Biometrics, 51(2), 738-743.
Vuong, Q. H. (1989). Likelihood ratio tests for model selection and non-nested hypotheses. Econometrica, 57(2), 307-333.
Warton, D. I. (2005). Many zeros does not mean zero inflation: Comparing the goodness-of-fit of parametric models to multivariate abundance data. Environmetrics, 16(3), 275-289.
Wilson, P. (2015). The misuse of the Vuong test for non-nested models to test for zero-inflation. Economics Letters, 127, 51-53.
Wilson, P. and Einbeck, J. (2015). A simple and intuitive test for number-inflation or number-deflation. In H. Friedl and H. Wagner (Eds.), Proceedings of the 30th International Workshop on Statistical Modelling, Linz, Austria, 2, 299-302.
Wilson, P. and Einbeck, J. (2019). A new and intuitive test for zero modification. Statistical Modelling, 19(4), 341-361.
Yang, Z., Hardin, J. W. and Addy, C. L. (2010). Score tests for zero-inflation in overdispersed count data. Communications in Statistics - Theory and Methods, 39(11), 2008-2030.