> Does anybody have a function that performs a goodness of fit test for
> discrete samples and geometric and poisson distributions?
Hi Erica 
Would a chisquared goodness of fit test help? There's no MATLAB function for
that per se, but the code do do the test is only a few lines long.
First fit a geometric distribution to your data:
>> x = [0 7 15 1 2 5 4 19 0 0 6 2 8 2 4 1 0 2 0 1 8 0 7 2 1]; % madeup data
>> n = length(x);
>> phat = mle('geometric',x)
phat =
0.2049
>> q = 1; % one estimated parameter
Next, figure out how to group the data so that the expected number of
observations in each group is at least 5. The first column here is k from
zero up to 10, the second column is the expected number of observations equal
to k under the estimated model, Geo(phat), i.e., the sample size times the
probability of getting k. After looking at this table, I decide to group
observations into {0}, {1,2}, {3,4,5}, and {6 or higher}:
>> [(0:10); geopdf((0:10),phat)*n]'
ans =
0 5.1230
1.0000 4.0732
2.0000 3.2385
3.0000 2.5749
4.0000 2.0472
5.0000 1.6277
6.0000 1.2942
7.0000 1.0290
8.0000 0.8181
9.0000 0.6505
10.0000 0.5172
>> binEdges = [0 1 3 6 Inf]; % left edge of each bin, plus Inf
Next, compute the expected number of observations in each group, and the
observed number:
>> binProbs = diff([0 geocdf(binEdges(2:(end1))1,phat) 1]);
>> e = n*binProbs
e =
5.1230 7.3117 6.2498 6.3156
>> o = histc(x,binEdges); o(end) = []
o =
6 9 3 7
>> chi2 = sum((oe).^2 ./ e)
Finally, compute the chisquareed statistic, its degrees of freedom, and its
pvalue:
chi2 =
2.3040
>> nbins = length(binEdges)  1;
>> dof = nbins  q  1
dof =
2
>> pval = 1chi2cdf(chi2,dof)
pval =
0.3160
So, this test does not provide strong evidence against the geometric model. A
chiquared test for the Poisson is more or less the same, just use poisspdf
and poisscdf.
Hope this helps.
 Peter Perkins
The MathWorks, Inc.
