This contains draft text for when we add dNmixture to the package.

## N-mixture

An N-mixture model gives the probability of a set of counts from repeated visits to each of multiple sites.  The N-mixture distribution in `nimbleEcology` gives probability calculations for data from one site.

Define $y_t$ as the number of individuals counted at the site on sampling occasion (time) $t$.  Define $\mathbf{y} = (y_1, \ldots, y_t)$.  Define $\lambda$ as the average density of individuals, such that the true number of individuals, $N$, follows a Poisson distribution with mean $\lambda$.  Define $p_t$ to be the detection probability for each individual at time $t$, and $\mathbf{p} = (p_1, \ldots, p_t)$.

The probability of the data given the parameters is:
\[
P(\mathbf{y} | \lambda, \mathbf{p}) = \sum_{N = 1}^\infty P(N | \lambda) \prod_{t = 1}^T P(y_t | N)
\]
where $P(N | \lambda)$ is a Poisson probability and $P(y_t | N)$ is a binomial probability.  That is, $y_t \sim \mbox{binomial}(N, p_t)$, and the $y_t$s are independent.

In practice, the summation over $N$ can start at a value greater than 0 and must be truncated at some value $\lt \infty$.  Two options are provided for the range of summation:

1. Start the summation at the largest value of $y_t$ (there must be at least this many individuals) and truncate it at a value of $N$ provided by the user.
2. The following heuristic can be used.

If we consider a single $y_t$, then $N - y_t | y_t \sim \mbox{Poisson}(\lambda (1-p_t))$ (*See opening example of Royle and Dorazio*).  Thus, a natural upper end for the summation range of $N$ would be $y_t$ plus a very high quantile of The $\mbox{Poisson}(\lambda (1-p_t))$ distribution.  For a set of observations, a natural choice would be the maximum of such values across the observation times.  We use the 0.99999 quantile to be conservative.

Correspondingly, the summation can begin at smallest of the 0.00001 quantiles of $N | y_t$. If $p_t$ is small, this can be considerably larger than the maximum value of $y_t$, allowing more efficient computation.

*Describe structural zeros.*

### N-mixture models in `nimbleEcology`

An example is:

`y[i, 1:T] ~ dNmix(lambda = lambda, p = p[1:T], knownZero = 0, len = T)`

- `lambda` is $\lambda$ above.
- `p[1:t]` is $\mathbf{p}$ above.
- `knownZero` is 1 if the `lambda` should be replaced with 0 and an easy answer can be returned without summing over $N$.
- `len` is $T$.


