nll_bnb | R Documentation |
The negative log-likelihood for bivariate negative binomial outcomes.
nll_bnb_null(param, value1, value2, ratio_null)
nll_bnb_alt(param, value1, value2)
param |
(numeric)
for samples 1 and 2. |
value1 |
(numeric) |
value2 |
(numeric) |
ratio_null |
(Scalar numeric: |
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}
Scalar numeric negative log-likelihood.
rettiganti_2012depower
\insertRefaban_2009depower
sim_nb()
, stats::nlminb()
, stats::nlm()
,
stats::optim()
#----------------------------------------------------------------------------
# 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
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.