Negative Binomial Probability Distribution

Negative Binomial:
P(x | r, p) = Γ(r+x)
 pr . (1-p)x,
   integer x≥0, r>0, 0<p<1; let q=1-p.
x!  Γr
(For an int, n, Γn = (n-1).Γ(n-1), n! = Γ(n+1).)
e.g., P(0 | r, p) = pr,   P(1 | r, p) = r.pr.(1-p),
note, P(x+1 | r, p) = {r / (x+1)} . {(1-p) / p} . P(x | r+1, p)
P(x|r,p) is the probability of there being x failures prior to the rth success (if r is an int), where the probability of a success is p. Note that r=1 gives the geometric distribution.
 
x≥0 P(x | r, p) = 1
Proof: Let q=1-p,  LHS = (pr / Γr).{Γr + (Γr).r.q + (Γr).(r.(r+1)/2!).q2 + ... } = (pr / Γr).(Γr).{1 + r.q + (r.(r+1)/2!).q2 + ... } = pr.(1 - q)-r = 1.
 
mean, μ = r (1-p) / p
Proof: μ = ∑x≥0 x.P(x | r, p) = ∑x≥1 {r.(1-p)/p}.P(x-1 | r+1, p) = {r.(1-p)/p}.∑x≥0 P(x | r+1, p) = r (1-p) / p.
variance, v = r (1-p) / p2
Proof: v = ∑x≥0 x2.P(x | r, p) - μ2 = (r.(1-p)/p).∑x≥1 x.P(x-1 | r+1, p) - μ2 = (r.(1-p)/p).∑x≥0 (x+1).P(x | r+1, p) - μ2 = (r.(1-p)/p) . {(r+1)(1-p)/p + 1} - (r.(1-p)/p)2 = r.((1-p)/p)2.{(r+1) + p/(1-p) - r} = r.((1-p)/p)2{1 + p / (1-p)} = r.(1-p) / p2.
so μ = v.p,   p = μ/v
r = μ.p / (1-p) = (μ2/v) / (1 - μ/v) = μ2/v . v/(v-μ) = μ2 / (v-μ)
and we have
r = μ2 / (v - μ)
p = μ / v
 
negative log likelihood, L,
L = log(x!) + logΓr - logΓ(r+x) - r.log(p) - x.log(1-p)
 
ψ0y = d/dy log(Γy),
ψ1y = d2/dy2 log(Γy),
ψ1(y+1)=ψ1y - 1/y2 [wikip]
1st derivatives of L
d L/d r = ψ0(r) - ψ0(r+x) - log(p)
d L/d p = - r/p + x/(1-p)
if r given, maximum likelihood est.,
p = n.r / (n.r + ∑ixi), but is biased;
n.ψ0r - ∑iψ0(r+xi) = n.log(p)
 

2nd derivatives of L
d2L/d r2 = ψ1(r) - ψ1(r+x)
logΓy = log(y-1)!
~ (y-1)log(y-1), y≥2,
ψ0y ~ 1+log(y-1),
ψ1y ~ 1/(y-1).
Ex --"-- = ψ1(r) - ∑x≥0 ψ1(r+x).P(x|r,p)
= ψ1(r) - ∑x≥0ψ1(r+x).Γ(r+x).pr.qx/(x!.Γr)
~ ψ1(r) - ψ1(r).P(0|r,p) - ψ1(r+1).P(1|r,p) - ∑x≥2(1 / (r+x-1)).Γ(r+x).pr.qx/(x!.Γr)
= ψ1(r).(1 - pr) - ψ1(r+1).r.pr.q - (pr/Γr).∑x≥2Γ(r+x-1).qx/x!
= ψ1(r).(1 - pr) - ψ1(r+1).r.pr.q - (pr/Γr).{(Γ(r+1)/2!).q2 + (r+1).Γ(r+1)/3!).q2 + ...}
= ψ1(r).(1 - pr) - ψ1(r+1).r.pr.q - (pr/Γr).Γ(r-1).{((r-1).r/2!).q2 + ((r-1).r.(r+1)/3!).q3 + ...}
= ψ1(r).(1 - pr) - ψ1(r+1).r.pr.q - (pr / (r-1)).{1/(1-q)r-1 - 1 - (r-1).q}
= ψ1(r).(1 - pr) - ψ1(r+1).r.pr.q - (pr / (r-1)).{1 - pr - r.pr-1.(1-p)} / pr-1
= ψ1(r).(1 - pr) - ψ1(r+1).r.pr.q - (p / (r-1)).{1 - pr - r.pr-1.(1-p)}
NB. the last term is 0/0 if r=1, in which case we have
= ... - (p / Γ1).∑x≥2(1/x).(Γ(1+x)/x!).qx
= ... - p.∑x≥2(1/x).qx
= ... - p.{ - log(1-q) - q }
= ... - p.{ - log(p) - (1-p) }
 
d2L/d p2 = r/p2 + x/(1-p)2
Ex --"-- = r/p2 + μ/(1-p)2 = r/p2 + r/(p.(1-p)) = r / (p2.(1-p))
(this term is consistent with CSW's book p.253 where r is held constant.)
d2L/d r d p = - 1/p   = Ex d2L/d r d p
 
Fisher
  r p
r Exd2L/dr2 -1/p
p -1/p r/(p2.(1-p))
×n2