(*  negative_binomail_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate the negative binomial *)
(*    function at selected argument values, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  01 February 2006 *)
(*  Author:  John Burkardt *)

Needs["Statistics`DiscreteDistributions`"]

svec={4,5,6,
4,5,6,
4,5,6,
4,5,6,
4,5,6,
1,2,3,
1,2,3,
1,2,3,
1,2};
pvec = {
50/100,
50/100,
50/100,
50/100,
50/100,
50/100,
50/100,
50/100,
50/100,
40/100,
40/100,
40/100,
30/100,
30/100,
30/100,
30/100,
30/100,
30/100,
10/100,
10/100,
10/100,
10/100,
10/100,
10/100,
1/100,
1/100};
failvec={4,3,2,
3,2,1,
2,1,0,
2,1,0,
2,1,0,
11,10,9,
17,16,15,
9,8,7,
1,0};
fvec = {};
num = Length [ failvec ];

Do[{ s = svec[[i]], p = pvec[[i]], fail= failvec[[i]],
dist = NegativeBinomialDistribution[s,p], f = N[CDF[dist,fail],16],
fvec = Append [ fvec, f ],
Print["NegativeBinomialCDF[",s,",",p,"](",fail,")=",f]
}, {i, 1, num,1}]

fileout=OpenWrite["C:\\Documents and Settings\\burkardt\\Desktop\\Misc\\mathematica\\negative_binomial_cdf_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  negative_binomial_cdf_values.txt"];today=DateList[];Write[fileout,"#  Created on ",today];Write[fileout,"#"];
Write[fileout,"#  s  p  fail  f"];
Write[fileout,"#"];
Do[{s=svec[[i]];p=pvec[[i]];fail=failvec[[i]];f=fvec[[i]];Write[fileout,s,"  ",N[p,16],"  ",fail,"  ",N[f,16]]},{i,1,num,1}];Close[fileout];