
Parametric bootstrap likelihood-ratio test for nested count models
Source:R/zero_tests.R
bootstrap_lrtest.RdTests a restricted countreg() model against a larger one by a
likelihood-ratio statistic whose reference distribution is simulated from
the fitted restricted model. It covers comparisons for which the
chi-square approximation does not hold and regCompTest() reports no LR
test, such as a zero-inflation model with covariates against the count
model without one, or Poisson against zero-inflated NB2 (two parameters
on the boundary).
Arguments
- restricted
the smaller model, a
countreg()fit.- full
the larger model, a
countreg()fit on the same rows.- B
number of bootstrap replicates.
- seed
optional seed for the simulations; the caller's random-number stream is left unchanged.
Value
An object of class "htest" with statistic (named LR),
parameter (named B, the replicates used), p.value, method and
data.name, and also n_failed (replicates whose refits failed or did
not converge), boot_LR (the bootstrap statistics, NA for failed
replicates) and asymptotic_p (the p-value of regCompTest(), NA
when it reports no LR test). A warning is given when more than 5% of
the replicates fail.
Details
The observed statistic is \(LR = \max(0, 2(\ell_{full} -
\ell_{restricted}))\). B outcome vectors are simulated from the
restricted model (simulate()), both models are refitted to each, and the
p-value is \((1 + \#\{LR_b \ge LR\}) / (1 + B_{used})\), with each
\(LR_b\) also set to at least 0 and \(B_{used}\) the number of
replicates in which both refits converged. The larger model is refitted
from two starts, its own estimates and the restricted model's estimates
extended to the larger model (a zero-inflation intercept of -5, other
added mean and zero-model coefficients at 0), and the higher
log-likelihood is kept, so that a refit stopping at a local maximum does
not produce a negative statistic.
The test does not check that the models are nested; it requires the same
observations, outcome, offsets and weights, and that full has at least
as many parameters as restricted. A warning is given when the
restricted model has the higher log-likelihood. The bootstrap needs one
simulated outcome per observation, so models with frequency weights other
than 1, or with sampling weights, are not supported. Finite mixtures and
panel models are not supported yet.
Examples
# \donttest{
set.seed(1)
n <- 300
x <- rnorm(n)
d <- data.frame(x = x, y = rnbinom(n, size = 2, mu = exp(0.5 + 0.4 * x)))
nb2 <- countreg(y ~ x, data = d, family = "NB2", method = "BFGS")
# A zero-inflation model with a covariate: no closed-form LR test
zinb <- countreg(y ~ x, data = d, family = "NB2", zero_formula = ~ x,
method = "BFGS")
# Use several hundred replicates in practice
bootstrap_lrtest(nb2, zinb, B = 9, seed = 1)
#>
#> Parametric bootstrap likelihood-ratio test
#>
#> data: restricted: y ~ x (NB2)
#> full: y ~ x, zero ~x (NB2, zero-inflated)
#> LR = 2.6696, B = 9, p-value = 0.4
#>
# }