Advertisement
karlakmkj

Spread of the Poisson Distribution

Jul 26th, 2021
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import scipy.stats as stats
  2. import numpy as np
  3.  
  4. # To observe that as the parameter lambda increases, the variance β€” or spread β€” of possible values increases as well.
  5. # 5000 draws, lambda = 7
  6. rand_vars_7 = stats.poisson.rvs(7, size = 5000)
  7.  
  8. # find variance & print minimum and maximum values
  9. print(np.var(rand_vars_7)) # Output: 7.02419964
  10. '''
  11. Because this is calculated from a sample, it is possible that the variance might not equal EXACTLY lambda. However, we do expect it to be relatively close when the sample size is large, like in this example.
  12. '''
  13. print(min(rand_vars_7), max(rand_vars_7))  # Output: 0 19
  14.  
  15. # Compared to a larger lambda
  16. # 5000 draws, lambda = 17
  17. rand_vars_17 = stats.poisson.rvs(17, size = 5000) # Output: 16.85025136
  18.  
  19. print(np.var(rand_vars_17))
  20. print(min(rand_vars_17), max(rand_vars_17))  # Output: 4 33 which shows these values are spread wider, indicating a larger variance.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement