lgspline_negbin: Fit Negative Binomial Model via lgspline

View source: R/negbin_helpers.R

lgspline_negbinR Documentation

Fit Negative Binomial Model via lgspline

Description

Convenience wrapper that calls lgspline with the correct family, weight, dispersion, score, and unconstrained-fit functions for NB2 regression. All standard lgspline arguments (knots, penalties, constraints, parallel, correlation structures, etc.) are passed through.

Usage

lgspline_negbin(formula, data, ...)

Arguments

formula

Formula specifying the model. The response should be non-negative integer counts.

data

Data frame.

...

Additional arguments passed to lgspline, including Vhalf and VhalfInv for correlation structures.

Details

Internally sets:

  • family = negbin_family()

  • unconstrained_fit_fxn = unconstrained_fit_negbin

  • glm_weight_function = negbin_glm_weight_function

  • qp_score_function = negbin_qp_score_function

  • dispersion_function = negbin_dispersion_function

  • schur_correction_function = negbin_schur_correction

  • need_dispersion_for_estimation = TRUE

  • estimate_dispersion = TRUE

  • standardize_response = FALSE

A formula interface is needed, e.g. lgspline_negbin(t, y) won't work, unlike for ordinary lgspline.

When a correlation structure is supplied via Vhalf/VhalfInv, the model is fitted through the GEE Path 1b machinery in get_B. The dispersion function uses VhalfInv to whiten Pearson residuals for a better moment-based initialization of \theta, which stabilizes the profile MLE under moderate to strong correlation. The score function handles the whitened design consistently with the Weibull AFT GEE convention.

Value

An object of class "lgspline".

See Also

lgspline_cox for Cox PH, lgspline_weibull for Weibull AFT, negbin_family, unconstrained_fit_negbin

Examples


set.seed(1234)
N <- 300
t <- rnorm(N)
mu <- exp(1 + 0.5 * sin(2 * t))
y <- rnbinom(N, size = 3, mu = mu)
df <- data.frame(response = y, predictor = t)

fit <- lgspline_negbin(
  response ~ spl(predictor),
  data = df,
  K = 2,
  opt = FALSE,
  wiggle_penalty = 1e-2
)
print(summary(fit))
plot(fit, show_formulas = TRUE,
     custom_response_lab = 'Count')
points(t, mu, col = 'grey', cex=0.67)


lgspline documentation built on Aug. 5, 2026, 1:10 a.m.