% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/betaBinomial.R
\name{log_likelihood2}
\alias{log_likelihood2}
\title{Calculate the negative log-likelihood for a beta-binomial regression model}
\usage{
log_likelihood2(params, X, Z, y, n, weights = NULL, lch = NULL)
}
\arguments{
\item{params}{A numeric vector containing all model parameters. The first
n_alpha elements are coefficients for the alpha model, and the remaining
elements are coefficients for the beta model.}

\item{X}{A matrix of predictors for the alpha model.}

\item{Z}{A matrix of predictors for the beta model.}

\item{y}{A numeric vector of response values.}

\item{n}{The maximum score (number of trials).}

\item{weights}{A numeric vector of weights for each observation
(NULL = equal weights).}

\item{lch}{Optional precomputed \code{lchoose(n, y)}. Since this term does
not depend on the parameters, passing it once avoids recomputation in
every optimizer iteration.}
}
\value{
The negative log-likelihood of the model (large finite penalty
  if non-finite).
}
\description{
This function computes the negative log-likelihood for a beta-binomial
regression model where both the alpha and beta parameters are modeled as
functions of predictors (mode 2).
}
\details{
Uses a numerically stable implementation of the beta-binomial
log-probability via \code{lbeta}. The linear predictors of
log(alpha) and log(beta) are clamped to [-20, 20].
}
\keyword{internal}
