
512 13 Goodness-of-Fit Tests
Given this data, one should test the hypothesis that the interarrivals times
are exponential. The density f (t)
= λe
−λt
, t ≥0,λ > 0 corresponds to the CDF
F(t)
=1 −e
−λt
, t ≥ 0, λ > 0, and the theoretical probability of an interval [a, b]
is F(b)
−F(a).
But we first need to estimate the parameter
λ in order to calculate the
(theoretical) probabilities. A standard estimator for the parameter
λ is
ˆ
λ =
1/T =1/(5/2) =0.4.
The theoretical frequencies of intervals [3,4] and [4,5] are p
4
=109·(F(4)−
F(3)) = 109 ·(1 − e
−0.4·4
−(1 −e
−0.4·3
)) = 109 ·(e
−0.4·3
−e
−0.4·3
) = 0.099298 ·109 =
10.823 and 0.066561 ·109 =7.255, respectively, yielding χ
2
equal to
(34
−35.9335)
2
35.935
+
(20 −24.089)
2
24.089
+
(16 −16.147)
2
16.147
+
(15 −10.823)
2
10.823
+
(9 −7.255)
2
7.255
+
(7 −4.863)
2
4.863
+
(8 −9.888)
2
9.888
=4.13.
The number of degrees of freedom is d f
=7−1−1 =5 and the 95% quantile
for
χ
2
5
is chi2inv(0.95,5)=11.071. Thus, we do not reject the hypothesis that
the interarrival times are exponential, i.e., the observed process is consistent
with a Poisson process.
Example 13.5. A sample of n=1000 exponential E (1/2) random variates is gen-
erated. We pretend that the generating distribution is unknown. Using MAT-
LAB’s
chi2gof function we test the consistency of the generated data with an
exponential distribution with the rate
λ estimated from the sample.
X = exprnd(2, [1, 1000]);
[h,p,stats] = ...
chi2gof(X,’cdf’,@(z)expcdf(z,mean(X)),’nparams’,1,’nbins’,7)
%
%h = 0
%p = 0.6220
%stats = chi2stat: 2.6271
% df: 4
% edges: [1x7 double]
% O: [590 258 96 34 14 8]
% E: [1x6 double]
The sample is consistent with the exponential distribution with p-value of
0.6220. Note that the number of intervals selected by MATLAB is 6, not the
requested 7. This is because the upper tail intervals with a low expected count
(
<5) are merged.
Example 13.6. Wrinkled Peas. Mendel crossed peas that were heterozygotes
for smooth/wrinkled, where smooth is dominant. The expected ratio in the off-
spring is 3 smooth: 1 wrinkled. He observed 423 smooth and 133 wrinkled