% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/negbin_helpers.R
\name{loglik_negbin}
\alias{loglik_negbin}
\title{Compute Negative Binomial Log-Likelihood}
\usage{
loglik_negbin(y, mu, theta, weights = 1)
}
\arguments{
\item{y}{Non-negative integer response vector.}

\item{mu}{Positive mean vector, same length as \code{y}.}

\item{theta}{Positive scalar shape parameter.}

\item{weights}{Optional observation weights (default 1).}
}
\value{
Scalar log-likelihood value.
}
\description{
Evaluates the NB2 log-likelihood for given mean vector and shape parameter.
}
\details{
The log-likelihood is
\deqn{\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]}
}
\examples{
set.seed(1234)
mu <- exp(rnorm(50))
y <- rpois(50, mu)
loglik_negbin(y, mu, theta = 5)

}
