Created
          August 11, 2024 09:06 
        
      - 
      
- 
        Save davidclarance/8e93dcc4fe541a8f17afb7effc2590de to your computer and use it in GitHub Desktop. 
    Poisson bootstrapping
  
        
  
    
      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 poisson_bootstrap_nth_percentile_and_ci( | |
| data: List[float], n_iter: int = 1000, alpha: float = 0.95, percentile: float = 95 | |
| ) -> Tuple[float, float, float, float]: | |
| data = np.array(data) | |
| n = len(data) | |
| weights = np.random.poisson(1, (n_iter, n)) | |
| percentiles = [] | |
| for weight in weights: | |
| resampled_data = np.repeat(data, weight) | |
| percentile = np.percentile(resampled_data, 95) | |
| percentiles.append(percentile) | |
| mean_percentile = np.mean(percentiles) | |
| lower_bound = np.percentile(percentiles, (1 - alpha) / 2 * 100) | |
| upper_bound = np.percentile(percentiles, (1 + alpha) / 2 * 100) | |
| return percentiles, mean_percentile, lower_bound, upper_bound | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment