The K-S test for Exponentiality
Test the null hypothesis that the interearthquake times of the Parkfield sequence are Exponentially distributed. That is, earthquakes happen at random with no memory of when the last one was. Note: This calculation is computationally intensive (you will draw more than 108 random numbers), so it will take about 10 seconds to complete.
This exercise is part of the course
Case Studies in Statistical Thinking
Exercise instructions
- Draw 10,000 replicates from the Exponential distribution using
np.random.exponential()
. The mean time gap between earthquakes is stored asmean_time_gap
, which you computed in a previous exercise. Store the result inx_f
. - Use these samples,
x_f
, along with the actual time gaps, stored intime_gap
, to compute the Kolmogorov-Smirnov statistic usingdcst.ks_stat()
. - Use the function you wrote in the last exercise, now conveniently stored as
dcst.draw_ks_reps()
to draw 10,000 K-S replicates from the Exponential distribution. Use thesize=10000
keyword argument for drawing out of the target Exponential distribution. Store the replicates asreps
. - Compute and print the p-value. Remember that "at least as extreme as" is defined in this case as the test statistic under the null hypothesis being greater than or equal to what was observed.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Draw target distribution: x_f
x_f = ____
# Compute K-S stat: d
d = ____
# Draw K-S replicates: reps
reps = ____(len(____), ____,
args=(mean_time_gap,), size=____, n_reps=____)
# Compute and print p-value
p_val = ____(____ >= ____) / 10000
print('p =', p_val)