View source: R/negbin_helpers.R
| loglik_negbin | R Documentation |
Evaluates the NB2 log-likelihood for given mean vector and shape parameter.
loglik_negbin(y, mu, theta, weights = 1)
y |
Non-negative integer response vector. |
mu |
Positive mean vector, same length as |
theta |
Positive scalar shape parameter. |
weights |
Optional observation weights (default 1). |
The log-likelihood is
\ell(\mu, \theta) = \sum_i w_i \bigl[
\log\Gamma(y_i + \theta) - \log\Gamma(\theta) - \log\Gamma(y_i + 1)
+ \theta\log\theta - \theta\log(\mu_i + \theta)
+ y_i\log\mu_i - y_i\log(\mu_i + \theta)\bigr]
Scalar log-likelihood value.
set.seed(1234)
mu <- exp(rnorm(50))
y <- rpois(50, mu)
loglik_negbin(y, mu, theta = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.