redline



In [1]:
from __future__ import print_function, division

import numpy as np
import thinkstats2
import thinkplot

import redline

%matplotlib inline
formats = ['png', 'pdf']

In [45]:
gap_times = np.array(redline.OBSERVED_GAP_TIMES)
len(gap_times), min(gap_times), max(gap_times)


Out[45]:
(70, 143.0, 901.0)

In [46]:
pmf_z = thinkstats2.Pmf(gap_times, label='actual')
cdf_z = pmf_z.MakeCdf()

pmf_zb = redline.BiasPmf(pmf_z, label='biased')
cdf_zb = pmf_zb.MakeCdf()

pmf_y = redline.PmfOfWaitTime(pmf_z)
cdf_y = pmf_y.MakeCdf()

pmf_yb = redline.PmfOfWaitTime(pmf_zb)
cdf_yb = pmf_yb.MakeCdf()

In [58]:
pmf_z.Mean() / 60, pmf_y.Mean() / 60


Out[58]:
(7.7680952380952384, 3.919047619047618)

In [52]:
pmf_zb.Mean() / 60, pmf_yb.Mean() / 60


Out[52]:
(8.7205184004577116, 4.3937886961319181)

In [55]:
thinkplot.PrePlot(2)
thinkplot.Plot(cdf_z.xs/60, cdf_z.ps, label=cdf_z.label)
thinkplot.Config(xlabel='time between trains (minutes)', ylabel='CDF', loc='lower right')
thinkplot.Save('redline1', formats=formats)


Writing redline1.png
Writing redline1.pdf
<matplotlib.figure.Figure at 0x7f6283fe2c90>

In [56]:
thinkplot.PrePlot(2)
thinkplot.Plot(cdf_z.xs/60, cdf_z.ps, label=cdf_z.label)
thinkplot.Plot(cdf_zb.xs/60, cdf_zb.ps, label=cdf_zb.label)
thinkplot.Config(xlabel='time between trains (minutes)', ylabel='CDF', 
                 ylim=[0, 1], loc='lower right')
thinkplot.Save('redline2', formats=formats)


Writing redline2.png
Writing redline2.pdf
<matplotlib.figure.Figure at 0x7f6284027b50>

In [7]: