Skip to contents

Fits 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

+ inherited public methods from Inference


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_obj

A completed Design object with a count response.

model_formula

Optional 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.

verbose

Whether to print progress messages.

smart_cold_start_default

Whether to use smart optimizer start values by default.

optimization_alg

Optimization 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).

Usage

InferenceCountNegBin$compute_estimate_with_bootstrap_weights(
  subject_or_block_weights,
  estimate_only = FALSE
)

Arguments

subject_or_block_weights

Bootstrap weights at the subject or block level.

estimate_only

If TRUE, skip variance calculations.


InferenceCountNegBin$compute_jackknife_estimate()

Negative-binomial delete-one refits are unstable for jackknife inference; report explicit non-estimability.

Usage

InferenceCountNegBin$compute_jackknife_estimate(unit = "auto")

Arguments

unit

Deletion unit. Default "auto".


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.

Usage

InferenceCountNegBin$compute_jackknife_bias_estimate(unit = "auto")

Arguments

unit

Deletion unit. Default "auto".


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.

Usage

InferenceCountNegBin$compute_jackknife_std_error(unit = "auto")

Arguments

unit

Deletion unit. Default "auto".


InferenceCountNegBin$compute_jackknife_wald_two_sided_pval()

Reports that jackknife-Wald p-values are unavailable here; see InferenceJackknife.

Usage

InferenceCountNegBin$compute_jackknife_wald_two_sided_pval(
  delta = 0,
  unit = "auto"
)

Arguments

delta

Null treatment-effect value. Default 0.

unit

Deletion unit. Default "auto".


InferenceCountNegBin$compute_jackknife_wald_confidence_interval()

Reports that jackknife-Wald intervals are unavailable here; see InferenceJackknife.

Usage

InferenceCountNegBin$compute_jackknife_wald_confidence_interval(
  alpha = 0.05,
  unit = "auto"
)

Arguments

alpha

Significance level. Default 0.05.

unit

Deletion unit. Default "auto".


InferenceCountNegBin$clone()

The objects of this class are cloneable with this method.

Usage

InferenceCountNegBin$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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
# }