negbin_qp_score_function: NB Score Function for Quadratic Programming and Blockfit

View source: R/negbin_helpers.R

negbin_qp_score_functionR Documentation

NB Score Function for Quadratic Programming and Blockfit

Description

Computes the score (gradient of NB log-likelihood) in the format expected by lgspline's qp_score_function interface.

Usage

negbin_qp_score_function(
  X,
  y,
  mu,
  order_list,
  dispersion,
  VhalfInv,
  observation_weights
)

Arguments

X

Block-diagonal design matrix (N x P).

y

Response vector (N x 1).

mu

Predicted values (N x 1), same order as X and y.

order_list

List of observation indices per partition.

dispersion

Shape parameter \theta.

VhalfInv

Inverse square root of correlation matrix; when non-NULL the score is computed on the whitened scale as \tilde{X}^{\top}\tilde{r} where \tilde{X} = V^{-1/2}X and the residual vector accounts for the correlation.

observation_weights

Observation weights.

Details

Without correlation (VhalfInv = NULL), the score is \mathbf{X}^{\top}\mathbf{w} \odot (y - \mu)\theta/(\theta + \mu).

With correlation, the GEE score is \tilde{\mathbf{X}}^{\top}\mathrm{diag}(\mathbf{W}) \mathbf{V}^{-1}(\mathbf{y} - \boldsymbol{\mu}) where \mathbf{W} contains the NB working weights. The whitening is absorbed by pre-multiplying both \mathbf{X} and the residual by \mathbf{V}^{-1/2}.

Value

Numeric column vector of length P.


lgspline documentation built on May 8, 2026, 5:07 p.m.