% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/negbin_helpers.R
\name{negbin_qp_score_function}
\alias{negbin_qp_score_function}
\title{NB Score Function for Quadratic Programming and Blockfit}
\usage{
negbin_qp_score_function(
  X,
  y,
  mu,
  order_list,
  dispersion,
  VhalfInv,
  observation_weights
)
}
\arguments{
\item{X}{Block-diagonal design matrix (N x P).}

\item{y}{Response vector (N x 1).}

\item{mu}{Predicted values (N x 1), same order as X and y.}

\item{order_list}{List of observation indices per partition.}

\item{dispersion}{Shape parameter \eqn{\theta}.}

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

\item{observation_weights}{Observation weights.}
}
\value{
Numeric column vector of length P.
}
\description{
Computes the score (gradient of NB log-likelihood) in the format
expected by lgspline's \code{qp_score_function} interface.
}
\details{
Without correlation (\code{VhalfInv = NULL}), the score is
\eqn{\mathbf{X}^{\top}\mathbf{w} \odot (y - \mu)\theta/(\theta + \mu)}.

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