Hypergeometric distribution \(H(n, M, N)\) has three parameters \(N, M, n\), where \(N\) is size of total population, \(M\) is the size of the tagged subpopulation, \(n\) is the size of sampling population.
#' for example, we tag 100 voles and release them
#' then we catch 50 and 5 of them are tagged
n <- 50
M <- 100
k <- 5
#' likelihood function
pmf <- function(k, n, M, N) {
return(choose(M, k) * choose(N - M, n - k) / choose(N, n))
}
#’ we want to infer the number of voles in the area
N <- seq(M, 5000, 20)
pmfval <- pmf(k = k, n = n , M = M, N = N)
plot(N, pmfval, type = "h")
#’ the maximum likelihood is reached at
N <- seq(800, 1200, 1)
pmfval <- pmf(k = k, n = n , M = M, N = N)
N[which.max(pmfval)]
## [1] 999