
Negative Binomial Regression Inference for Count Responses
Source:R/inference_count_negbin.R
InferenceCountNegBin.RdFits a negative binomial regression for count responses:
\(Y_i \mid w_i, x_i \sim \mathrm{NegBin}(\mu_i, \theta)\), \(\log
\mu_i = \beta_0 + \beta_T w_i + x_i^\top \gamma\), \(\mathrm{Var}(Y_i) =
\mu_i + \mu_i^2 / \theta\), jointly maximizing over the regression
coefficients and the dispersion parameter \(\theta\)
(fast_neg_bin_cpp/fast_neg_bin_with_var_cpp).
\(\hat\beta_T\) is a log-rate-ratio: \(\exp(\hat\beta_T)\) is the
estimated rate ratio. Unlike InferenceCountPoisson,
the negative-binomial model allows overdispersion (\(\mathrm{Var}(Y_i) >
E[Y_i]\)) via \(\theta\); smaller \(\theta\) indicates more
overdispersion, and the model converges to Poisson as \(\theta \to
\infty\). likelihood_tier = "full": Wald, score, gradient, and
likelihood-ratio tests are all available, plus parametric-likelihood
bootstrap calibration of the likelihood-ratio test (simulating new
responses from \(\mathrm{NegBin}(\hat\mu_i, \hat\theta)\) under the null).
Jackknife inference is not supported: delete-one refits of a
jointly-estimated dispersion parameter are numerically unstable, so
compute_jackknife_estimate() and related methods report explicit
non-estimability rather than attempting delete-one refits. Validity
requires the negative-binomial mean-variance relationship to hold and the
usual correctly-specified-linear-predictor-on-the-log-scale assumption.
References
Cameron, A. C., and Trivedi, P. K. (2013). Regression Analysis of Count Data (2nd ed.). Cambridge University Press, for the negative binomial regression model and its maximum-likelihood theory.
See also
Comparable Python API:
statsmodels
discrete models (NegativeBinomial). See also:
Negative
binomial distribution (Wikipedia).
Super class
Inference -> InferenceCountNegBin
Methods
Public methods
+ inherited public methods from Inference
Inference$capabilities()Inference$compute_asymp_confidence_interval()Inference$compute_asymp_two_sided_pval()Inference$compute_estimate()Inference$compute_exact_confidence_interval()Inference$compute_exact_two_sided_pval_for_treatment_effect()Inference$duplicate()Inference$get_analysis_data()Inference$get_covariates()Inference$get_design_object()Inference$get_model_formula()Inference$get_nonestimable_reason()Inference$get_nonestimable_stage()Inference$get_optimization_alg()Inference$get_response()Inference$get_response_type()Inference$get_treatment()Inference$is_nonestimable()Inference$set_optimization_alg()Inference$set_seed()Inference$supports()
InferenceCountNegBin$new()
Initialize inference for the negative binomial regression
model \(Y_i \mid w_i, x_i \sim \mathrm{NegBin}(\mu_i, \theta)\),
\(\log \mu_i = \beta_0 + \beta_T w_i + x_i^\top \gamma\); see
InferenceCountNegBin for the
model form. Does not fit the model; the fit is deferred to the first
call to compute_estimate() or a method that requires it.
Usage
InferenceCountNegBin$new(
des_obj,
model_formula = NULL,
verbose = FALSE,
smart_cold_start_default = NULL,
optimization_alg = NULL
)Arguments
des_objA completed
Designobject with a count response.model_formulaOptional formula for covariate adjustment. If
NULL(default), the formula from the design object is used and its pre-computed design matrix is reused. If a formula is provided, a new design matrix is constructed from the design's imputed covariates.verboseWhether to print progress messages.
smart_cold_start_defaultWhether to use smart optimizer start values by default.
optimization_algOptimization algorithm to use. Default is dispatched via policy.
InferenceCountNegBin$compute_estimate_with_bootstrap_weights()
Refits the negative binomial model with subject/block-level
weights applied to the fitting log-likelihood (Bayesian-bootstrap or
nonparametric-bootstrap draw weights, expanded to row level via
private$expand_subject_or_block_weights_to_row_weights()) via
fast_neg_bin_weighted_cpp, and returns the reweighted
log-rate-ratio estimate \(\hat\beta_T^{(w)}\). If the weighted
negative-binomial fit fails to converge, falls back to a weighted
Poisson GLM (stats::glm(family = poisson())) as an
estimating-equation-consistent point estimate of the same mean
structure (this fallback does not itself estimate \(\theta\), so no
standard error is computed in that path); no standard error is computed
in either path (s_beta_hat_T is always NA).
InferenceCountNegBin$compute_jackknife_estimate()
Negative-binomial delete-one refits are unstable for jackknife inference; report explicit non-estimability.
InferenceCountNegBin$compute_jackknife_bias_estimate()
Report that the jackknife bias estimate is unavailable for
negative-binomial fits when delete-one refits are not stable; see
InferenceJackknife for the shared
jackknife contract.
InferenceCountNegBin$compute_jackknife_std_error()
Report that the jackknife standard error is unavailable for
negative-binomial fits when delete-one refits are not stable; see
InferenceJackknife for the shared
jackknife contract.
InferenceCountNegBin$compute_jackknife_wald_two_sided_pval()
Reports that jackknife-Wald p-values are unavailable here; see
InferenceJackknife.
InferenceCountNegBin$compute_jackknife_wald_confidence_interval()
Reports that jackknife-Wald intervals are unavailable here; see
InferenceJackknife.
Examples
# \donttest{
seq_des = DesignSeqOneByOneBernoulli$new(n = 10, response_type = 'count')
for (i in 1:10) {
seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1)))
}
seq_des$add_all_subject_responses(rpois(10, 2))
inf = InferenceCountNegBin$new(seq_des)
inf$compute_estimate()
#> [1] -0.5785122
# }