[SciPy-User] empirical CDF
Sun Oct 14 11:29:03 CDT 2012
On Sun, Oct 14, 2012 at 12:03 PM, Degang Wu <firstname.lastname@example.org> wrote:
> Is Scipy able to calculate empirical CDF (calculating a CDF from a sequence of random samples)? I have searched the documentation for quite a while, but have found nothing useful.
We have an empirical distribution class in statsmodels.
The sm.nonparametric.KDE class also has the ability to return a CDF
for a fitted density estimator.
If you're feeling ambitious and want to make a pull request the ECDF
needs a little clean-up. The ECDF class could use a plot method that
incorporates the private _conf_set, and there is finished code to use
interpolation instead of the step function but it's not available in
the API yet.
from statsmodels.distributions import ECDF
from statsmodels.distributions.empirical_distribution import _conf_set
import matplotlib.pyplot as plt
nerve_data = urllib.urlopen('http://www.statsci.org/data/general/nerve.txt')
nerve_data = np.loadtxt(nerve_data)
x = nerve_data / 50. # was in 1/50 seconds
cdf = ECDF(x)
F = cdf(x)
fig, ax = plt.subplots()
lower, upper = _conf_set(F)
ax.step(x, lower, 'r')
ax.step(x, upper, 'r')
ax.vlines(x, 0, .05)
More information about the SciPy-User