Created
          October 18, 2016 19:29 
        
      - 
      
- 
        Save danjamker/15b546081ac7d9e841c1a7ce1408a1f9 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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