Created
          August 8, 2024 09:14 
        
      - 
      
- 
        Save davidclarance/4d7e427c7903ae6b655983981eb460fd to your computer and use it in GitHub Desktop. 
    Bootstrap mean and confidence intervals
  
        
  
    
      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 bootstrap_mean_and_ci( | |
| data: List[float], n_iter: int = 1000, alpha: float = 0.95 | |
| ) -> Tuple[float, float, float]: | |
| n = len(data) | |
| bootstrap_samples = np.random.choice(data, (n_iter, n), replace=True) | |
| means = bootstrap_samples.mean(axis=1) | |
| mean = means.mean() | |
| lower = np.percentile(means, (1 - alpha) / 2 * 100) | |
| upper = np.percentile(means, (1 + alpha) / 2 * 100) | |
| return mean, lower, upper | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment