Search code examples
pythonrnumpyscipy

numpy/scipy equivalent of R ecdf(x)(x) function?


What is the equivalent of R's ecdf(x)(x) function in Python, in either numpy or scipy? Is ecdf(x)(x) basically the same as:

import numpy as np
def ecdf(x):
  # normalize X to sum to 1
  x = x / np.sum(x)
  return np.cumsum(x)

or is something else required?

EDIT how can one control the number of bins used by ecdf?


Solution

  • Try these links:

    statsmodels.ECDF

    ECDF in python without step function?

    Example code

    import numpy as np
    from statsmodels.distributions.empirical_distribution import ECDF
    import matplotlib.pyplot as plt
    
    data = np.random.normal(0,5, size=2000)
    
    ecdf = ECDF(data)
    plt.plot(ecdf.x,ecdf.y)