Compares the observed number of zeros (or of any other count value) in
the training data with the number expected under a fitted
countreg() model. Under the fitted model, row \(i\) equals value
with probability \(p_i = \hat P(Y_i = value)\), so if the model is
correct the count \(Z = \sum_i 1\{y_i = value\}\) follows a
Poisson-binomial distribution with probabilities \(p_1, \dots, p_n\)
(Wilson and Einbeck, 2015, 2019). Too many zeros relative to the model
indicates zero inflation, too few zero deflation.
Arguments
- object
a model fitted with
countreg(), of any family, with or without a zero model or underreporting.- value
the count to test, a single non-negative whole number (default 0, the zeros).
- alternative
"two.sided"(default: inflation or deflation),"greater"(more observed than expected: inflation) or"less"(deflation).- method
"exact"(default) or"bootstrap"; see Details.- B
number of bootstrap replicates (for
method = "bootstrap").- seed
optional seed for the bootstrap simulations; the caller's random-number stream is left unchanged.
- exact_max_n
largest number of observations (counting frequency weights) for which the exact distribution is computed; above it a normal approximation is used.
- conf_level
coverage of
null_interval.
Value
An object of class "htest" with elements
statistic: the observed count, namedobserved;estimate: the count expected under the fitted model, namedexpected;p.value,alternative,methodanddata.name;null_interval: the centralconf_levelrange of the count under the fitted model (namedlower,upper), from the quantiles of the null distribution (exact or normal) or of the simulated counts (bootstrap);value: the count tested;for the bootstrap,
B_used(refits that converged) andn_failed. A warning is given when more than 5% of the refits fail.
Details
The test checks whether the fitted model gets the zeros right. It does
not identify a separate zero-generating process: a misspecified mean or
the wrong count family can produce too many or too few zeros as well
(see He et al., 2019). Fit the zero-inflated alternative and compare the
models (regCompTest(), bootstrap_lrtest()) to judge whether a zero
component improves the fit.
The package has no Vuong test: a count model and its zero-inflated counterpart are nested at the boundary \(\pi = 0\), not non-nested, so the Vuong test does not apply to them (Wilson, 2015).
With method = "exact", the null distribution of \(Z\) is computed by
convolution when the number of observations (counting frequency weights)
is at most exact_max_n, and approximated otherwise by a normal
distribution with mean \(\sum p_i\) and variance
\(\sum p_i (1 - p_i)\), discretized with a continuity correction. The
p-value uses the mid-p convention for a discrete statistic:
\(P(Z > z) + P(Z = z)/2\) for "greater",
\(P(Z < z) + P(Z = z)/2\) for "less", and twice the smaller of the
two (at most 1) for "two.sided". The exact test plugs in the
\(p_i\) of a model fitted to the same data and so ignores estimation
uncertainty; if the zeros are inflated, the fit absorbs some of them,
which costs power.
With method = "bootstrap", B outcome vectors are simulated from the
fitted model (simulate()), the model is refitted to each, and the
statistic \(Z^{(b)} - \sum_i p_i^{(b)}\) (simulated count minus the
count expected under the refitted model) is compared with the observed
\(z - \sum_i p_i\): by absolute value for "two.sided" and by sign
otherwise. The p-value is \((1 + \#\{\text{as or more extreme}\}) /
(1 + B_{used})\), where \(B_{used}\) counts the refits that converged.
This includes estimation uncertainty in the reference distribution, at the
cost of B refits.
Integer frequency weights count each row w_i times. The exact test
handles them inside the convolution. The bootstrap needs one simulated
outcome per observation and is available only without weights (or with
all weights equal to 1). Sampling weights and non-integer weights are not
supported: the test assumes independent observations drawn from the
model. Offsets are handled through the model's predictions.
References
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. doi:10.1177/0962280217749991
Wilson, P. (2015). The misuse of the Vuong test for non-nested models to test for zero-inflation. Economics Letters, 127, 51-53. doi:10.1016/j.econlet.2014.12.029
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, Volume 2, 299-302. Linz, Austria.
Wilson, P. and Einbeck, J. (2019). A new and intuitive test for zero modification. Statistical Modelling, 19(4), 341-361. doi:10.1177/1471082X18762277
See also
bootstrap_lrtest() and regCompTest() to compare a model with
its zero-inflated counterpart; rootogram() to see the fit at every
count; vignette("testing-for-excess-zeros", package = "flexCountReg").
Examples
data("washington_roads")
nb2 <- countreg(Total_crashes ~ lnaadt + lnlength, data = washington_roads,
family = "NB2", method = "BFGS")
zero_test(nb2)
#>
#> Exact Poisson-binomial test of zero modification
#>
#> data: Total_crashes ~ lnaadt + lnlength (NB2)
#> observed = 1101, p-value = 0.6219
#> alternative hypothesis: two.sided
#> sample estimates:
#> expected
#> 1093.633
#>
zero_test(nb2, value = 1)
#>
#> Exact Poisson-binomial test of count-1 modification
#>
#> data: Total_crashes ~ lnaadt + lnlength (NB2)
#> observed = 242, p-value = 0.3354
#> alternative hypothesis: two.sided
#> sample estimates:
#> expected
#> 255.5765
#>
# \donttest{
zero_test(nb2, method = "bootstrap", B = 19, seed = 1)
#>
#> Parametric bootstrap test of zero modification
#>
#> data: Total_crashes ~ lnaadt + lnlength (NB2)
#> observed = 1101, p-value = 0.15
#> alternative hypothesis: two.sided
#> sample estimates:
#> expected
#> 1093.633
#>
# }
