nll_nb | R Documentation |
The negative log-likelihood for two independent samples of negative binomial distributions.
nll_nb_null(param, value1, value2, equal_dispersion, ratio_null)
nll_nb_alt(param, value1, value2, equal_dispersion)
param |
(numeric)
for groups 1 and 2. |
value1 |
(numeric) |
value2 |
(numeric) |
equal_dispersion |
(Scalar logical) |
ratio_null |
(Scalar numeric: |
These functions are primarily designed for speed in simulation. Arguments are not checked.
Suppose X_1 \sim \text{NB}(\mu, \theta_1)
and
X_2 \sim \text{NB}(r\mu, \theta_2)
where X_1
and X_2
are
independent, X_1
is the count outcome for items in group 1, X_2
is the count outcome for items in group 2, \mu
is the arithmetic mean
count in group 1, r
is the ratio of arithmetic means for group 2 with
respect to group 1, \theta_1
is the dispersion parameter of group 1,
and \theta_2
is the dispersion parameter of group 2.
When the dispersion parameters are not equal, the likelihood is
\begin{aligned}
L(r, \mu, \theta_1, \theta_2 \mid X_1, X_2) = & \left( \frac{\theta_1^{\theta_1}}{\Gamma(\theta_1)} \right)^{n_1} \frac{\mu^{\sum{x_{1i}}}}{(\mu + \theta_1)^{\sum{x_{1i} + n_1 \theta_1}}} \times \\
& \left( \frac{\theta_2^{\theta_2}}{\Gamma(\theta_2)} \right)^{n_2} \frac{(r \mu)^{\sum{x_{2j}}}}{(r \mu + \theta_2)^{\sum{x_{2j} + n_2 \theta_2}}} \times \\
& \prod_{i = 1}^{n_1}{\frac{\Gamma(x_{1i} + \theta_1)}{x_{1i}!}} \prod_{j = 1}^{n_2}{\frac{\Gamma(x_{2j} + \theta_2)}{x_{2j}!}}
\end{aligned}
and the parameter space is
\Theta = \left\{ (r, \mu, \theta_1, \theta_2) : r, \mu, \theta_1, \theta_2 > 0 \right\}
.
The log-likelihood is
\begin{aligned}
l(r, \mu, \theta_1, \theta_2) = \ &n_1 \left[ \theta_1 \ln \theta_1 - \ln \Gamma(\theta_1) \right] + \\
&n_2 \left[ \theta_2 \ln \theta_2 - \ln \Gamma(\theta_2) \right] + \\
&(n_1 \bar{x}_1 + n_2 \bar{x}_2) \ln(\mu) - n_1 (\bar{x}_1 + \theta_1) \ln(\mu + \theta_1) + \\
&n_2 \bar{x}_2 \ln(r) - n_2 (\bar{x}_2 + \theta_2) \ln(r \mu + \theta_2) + \\
&\sum_{i = 1}^{n_1}{\left( \ln \Gamma(y_{1i} + \theta_1) - \ln(y_{1i}!) \right)} + \\
&\sum_{j = 1}^{n_2}{\left( \ln \Gamma(y_{2j} + \theta_2) - \ln(y_{2j}!) \right)}
\end{aligned}
When the dispersion parameters are equal, the likelihood is
\begin{aligned}
L(r, \mu, \theta \mid X_1, X_2) = & \left( \frac{\theta^{\theta}}{\Gamma(\theta)} \right)^{n_1 + n_2} \times \\
& \frac{\mu^{\sum{x_{1i}}}}{(\mu + \theta)^{\sum{x_{1i} + n_1 \theta}}} \frac{(r \mu)^{\sum{x_{2j}}}}{(r \mu + \theta)^{\sum{x_{2j} + n_2 \theta}}} \times \\
& \prod_{i = 1}^{n_1}{\frac{\Gamma(x_{1i} + \theta)}{x_{1i}!}} \prod_{j = 1}^{n_2}{\frac{\Gamma(x_{2j} + \theta)}{x_{2j}!}}
\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_1 + n_2) \left[ \theta \ln \theta - \ln \Gamma(\theta) \right] + \\
&(n_1 \bar{x}_1 + n_2 \bar{x}_2) \ln(\mu) - n_1 (\bar{x}_1 + \theta) \ln(\mu + \theta) + \\
&n_2 \bar{x}_2 \ln(r) - n_2 (\bar{x}_2 + \theta) \ln(r \mu + \theta) + \\
&\sum_{i = 1}^{n_1}{\left( \ln \Gamma(y_{1i} + \theta) - \ln(y_{1i}!) \right)} + \\
&\sum_{j = 1}^{n_2}{\left( \ln \Gamma(y_{2j} + \theta) - \ln(y_{2j}!) \right)}
\end{aligned}
Scalar numeric negative log-likelihood.
rettiganti_2012depower
\insertRefaban_2009depower
sim_nb()
, stats::nlminb()
, stats::nlm()
,
stats::optim()
#----------------------------------------------------------------------------
# nll_nb_*() examples
#----------------------------------------------------------------------------
library(depower)
set.seed(1234)
d <- sim_nb(
n1 = 60,
n2 = 40,
mean1 = 10,
ratio = 1.5,
dispersion1 = 2,
dispersion2 = 8
)
nll_nb_alt(
param = c(mean1 = 10, mean2 = 15, dispersion = 2, dispersion2 = 8),
value1 = d[[1L]],
value2 = d[[2L]],
equal_dispersion = FALSE
)
nll_nb_null(
param = c(mean = 10, dispersion = 2, dispersion2 = 8),
value1 = d[[1L]],
value2 = d[[2L]],
equal_dispersion = FALSE,
ratio_null = 1
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.