Question
Let's say we define the Negative Binomial as follows: $$f(x) = {x+r-1 \choose x} p^x (1-p)^r$$
With mean and variance: $$E(x) = \frac{rp}{1-p} \quad \quad V(x) = \frac{rp}{(1-p)^2}$$
We are given some set of data and need to get the maximum likelihood estimate and the method of moments estimate. How do we do this?
Attempt at Solution
For method of moments, I did:
M1 = mean(x)
M2 = mean(x^2)
p = 1 - (M1/(M2-M1^2))
r = (1-p)*M1/p
q1b = list(r = r, p = p)
print(q1b)
For MLE I did:
NBd_LLL <- function(x,par) {
return(-sum(log(dnbinom(x,size = par[0], prob = par[1]))))
}
q1c = optim(par = c(0.85,0.35), NBd_LLL, x = x, method = "L-BFGS-B", lower = c(0.1,0.1), upper = c(1,1))
q1c$par
But these give very different answers, where did it go wrong?