score_negbin: Compute Negative Binomial Score Vector

View source: R/negbin_helpers.R

score_negbinR Documentation

Compute Negative Binomial Score Vector

Description

Gradient of the NB2 log-likelihood with respect to \boldsymbol{\beta} under the log link.

Usage

score_negbin(X, y, mu, theta, weights = 1)

Arguments

X

Design matrix (N x p).

y

Response vector.

mu

Mean vector \exp(\mathbf{X}\boldsymbol{\beta}).

theta

Shape parameter.

weights

Observation weights (default 1).

Details

Under log link, d\mu_i/d\eta_i = \mu_i, so the score is

\mathbf{u} = \mathbf{X}^{\top}\mathbf{w}_{\mathrm{obs}} \odot \frac{(y_i - \mu_i)\theta}{\theta + \mu_i}

where the per-observation contribution (y_i - \mu_i)\theta/(\theta + \mu_i) is the derivative of the log-likelihood with respect to \eta_i.

Value

Numeric column vector of length p (gradient).


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