Skip to content

Instantly share code, notes, and snippets.

@danjamker
Created October 18, 2016 19:29
Show Gist options
  • Save danjamker/15b546081ac7d9e841c1a7ce1408a1f9 to your computer and use it in GitHub Desktop.
Save danjamker/15b546081ac7d9e841c1a7ce1408a1f9 to your computer and use it in GitHub Desktop.
def plot_ccdf(data):
"""
Plot the complementary cumulative distribution function
(1-CDF(x)) based on the data on the axes object.
Note that this way of computing and plotting the ccdf is not
the best approach for a discrete variable, where many
observations can have exactly same value!
"""
# Note that, here we use the convention for presenting an
# empirical 1-CDF (ccdf) as discussed
# a quick way of computing a ccdf (valid for continuous data):
sorted_vals = np.sort(np.unique(data))
ccdf = np.zeros(max(sorted_vals))
n = float(len(data))
for i in range(1,max(sorted_vals)):
ccdf[i] = np.sum(data >= i)/n
return ccdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment