Posted by
drfg2008 on
Sep 11, 2012; 10:57am
URL: http://spssx-discussion.165.s1.nabble.com/Negative-Binomial-SPSS-Bug-tp5715014.html
[This thread refers to the thread: "Poisson - negative binomial" Dec. 19, 2011 and Sep 06, 2012]
I have E(X) and V(X) of a neg.bin. distributed RV and would like to compute the cumulative Neg. Bin. function for P(X<=2).
CDF.NEGBIN(quant,thresh,prob)
---------------------
According to my textbook [1]
E(X)= k(1-p)/p
V(X)=k(1-p)/p^2
p = E(x)/V(x)
k= E(X) p(1-p)
(where p is the probability and k is the threshold)
--------------------
Example:
E(x) = 1.0815
V(x) = 1.7697
-> p = 0.611, k = 1.7
--------------------
My problem is that I do not get the results of the SPSS function reproduced . In the described example the result should be 0.8694. Instead SPSS computes 0.5366.
See for example this python recursive version:
begin program.
import math
import spss
def negbin(x,k,p):
if x==0:
return math.pow(p,k)
return negbin(x-1,k,p)*(1-p)*(x-1+k)/(x-1+1)
def VertNegBin(x,k,p):
zaehler=x
summe=0
while zaehler>=0:
summe=summe+negbin(zaehler,k,p)
zaehler=zaehler-1
return summe
end program.
*----------------------------------------------------------------.
COMPUTE var = 1.7697.
COMPUTE Lambda_f = 1.0815.
compute wert=2.
*----------------------------------------------------------------.
COMPUTE negProb=LAMBDA_F/var.
COMPUTE thresh=LAMBDA_F*(negProb/(1-negProb)).
execute.
spssinc trans result=CDFnegBinResult /Formula "VertNegBin( wert, thresh,negProb)".
execute.
spssinc trans result=PDFnegBinResult /Formula "negbin( wert, thresh,negProb)".
execute.
COMPUTE SPSS_version=CDF.NEGBIN(wert,thresh,negProb).
EXECUTE.
My question: Is it an SPSS Bug or my misunderstanding of thresh and prob in the SPSS function, and if the last applies, how then to compute CDF.NEGBIN(quant,thresh,prob) ?
Literature:
[1] Schlittgen, R.: Einführung in die Statistik. 5. Auflg. Oldenbourg 1995, S.203 ff
Dr. Frank Gaeth