loglik_negbin: Compute Negative Binomial Log-Likelihood

View source: R/negbin_helpers.R

loglik_negbinR Documentation

Compute Negative Binomial Log-Likelihood

Description

Evaluates the NB2 log-likelihood for given mean vector and shape parameter.

Usage

loglik_negbin(y, mu, theta, weights = 1)

Arguments

y

Non-negative integer response vector.

mu

Positive mean vector, same length as y.

theta

Positive scalar shape parameter.

weights

Optional observation weights (default 1).

Details

The log-likelihood is

\ell(\mu, \theta) = \sum_i w_i \bigl[ \log\Gamma(y_i + \theta) - \log\Gamma(\theta) - \log\Gamma(y_i + 1) + \theta\log\theta - \theta\log(\mu_i + \theta) + y_i\log\mu_i - y_i\log(\mu_i + \theta)\bigr]

Value

Scalar log-likelihood value.

Examples

set.seed(1234)
mu <- exp(rnorm(50))
y <- rpois(50, mu)
loglik_negbin(y, mu, theta = 5)


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