log_likelihood2 function

Calculate the negative log-likelihood for a beta-binomial regression model

Calculate the negative log-likelihood for a beta-binomial regression model

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.

log_likelihood2(params, X, Z, y, n, weights = NULL)

Arguments

  • 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.
  • X: A matrix of predictors for the alpha model.
  • Z: A matrix of predictors for the beta model.
  • y: A numeric vector of response values.
  • n: The maximum score (number of trials in the beta-binomial distribution).
  • weights: A numeric vector of weights for each observation. If NULL, equal weights are used.

Returns

The negative log-likelihood of the model.

Details

This function uses a numerically stable implementation of the beta-binomial log-probability. It allows for weighted observations, which can be useful for various modeling scenarios.