nll_bnb: Negative log-likelihood for BNB

nll_bnbR Documentation

Negative log-likelihood for BNB

Description

The negative log-likelihood for bivariate negative binomial outcomes.

Usage

nll_bnb_null(param, value1, value2, ratio_null)

nll_bnb_alt(param, value1, value2)

Arguments

param

(numeric)
The vector of initial values for BNB parameters. Must be in the following order for each scenario:

  • Null: c(mean1, dispersion)

  • Alternative: c(mean1, mean2, dispersion)

for samples 1 and 2.

value1

(numeric)
The vector of BNB values from sample 1. Must be sorted by the subject/item index. Must not contain NAs.

value2

(numeric)
The vector of BNB values from sample 2. Must be sorted by the subject/item index. Must not contain NAs.

ratio_null

(Scalar numeric: ⁠(0, Inf)⁠)
The ratio of means assumed under the null hypothesis (sample 2 / sample 1). Typically ratio_null = 1 (no difference).

Details

These functions are primarily designed for speed in simulation. Arguments are not checked.

Suppose X_1 \mid G = g \sim \text{Poisson}(\mu g) and X_2 \mid G = g \sim \text{Poisson}(r \mu g) where G \sim \text{Gamma}(\theta, \theta^{-1}) is the random item (subject) effect. Then X_1, X_2 \sim \text{BNB}(\mu, r, \theta) is the joint distribution where X_1 and X_2 are dependent (though conditionally independent), X_1 is the count outcome for sample 1 of the items (subjects), X_2 is the count outcome for sample 2 of the items (subjects), \mu is the conditional mean of sample 1, r is the ratio of the conditional means of sample 2 with respect to sample 1, and \theta is the gamma distribution shape parameter which controls the dispersion and the correlation between sample 1 and 2.

The likelihood is

\begin{aligned} L(r, \mu, \theta \mid X_1, X_2) = & \left( \frac{\theta^{\theta}}{\Gamma(\theta)} \right)^{n} \times \\ & \frac{\mu^{\sum{x_{1i}} + \sum{x_{2i}}}}{\prod_{i=1}^{n} x_{1i}!} \frac{r^{\sum{x_{2i}}}}{\prod_{i=1}^{n} x_{2i}!} \times \\ & \frac{\prod_{i = 1}^{n} \Gamma(x_{1i} + x_{2i} + \theta)}{(\mu + r \mu + \theta)^{\sum x_{1i} + x_{2i} + \theta}} \end{aligned}

and the parameter space is \Theta = \left\{ (r, \mu, \theta) : r, \mu, \theta > 0 \right\}. The log-likelihood is

\begin{aligned} l(r, \mu, \theta) = \ & n \left[ \theta \ln \theta - \ln \Gamma(\theta) \right] + \\ & n (\bar{x}_1 + \bar{x}_2) \ln(\mu) + n \bar{x}_2 \ln r + \\ & \sum_{i=1}^{n}{\ln \Gamma(x_{1i} + x_{2i} + \theta)} - \\ & n (\bar{x}_1 + \bar{x}_2 + \theta) \ln(\mu + r\mu + \theta) - \\ & \sum_{i = 1}^{n}{\ln x_{1i}!} - \sum_{i = 1}^{n}{\ln x_{2i}!} \end{aligned}

Value

Scalar numeric negative log-likelihood.

References

\insertRef

rettiganti_2012depower

\insertRef

aban_2009depower

See Also

sim_nb(), stats::nlminb(), stats::nlm(), stats::optim()

Examples

#----------------------------------------------------------------------------
# nll_bnb*() examples
#----------------------------------------------------------------------------
library(depower)

set.seed(1234)
d <- sim_bnb(
  n = 40,
  mean1 = 10,
  ratio = 1.2,
  dispersion = 2
)

nll_bnb_alt(
  param = c(mean1 = 10, mean2 = 12, dispersion = 2),
  value1 = d[[1L]],
  value2 = d[[2L]]
)

nll_bnb_null(
  param = c(mean = 10, dispersion = 2),
  value1 = d[[1L]],
  value2 = d[[2L]],
  ratio_null = 1
)


depower documentation built on April 3, 2025, 9:23 p.m.