Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scipy.stats as stats
- import numpy as np
- # To observe that as the parameter lambda increases, the variance — or spread — of possible values increases as well.
- # 5000 draws, lambda = 7
- rand_vars_7 = stats.poisson.rvs(7, size = 5000)
- # find variance & print minimum and maximum values
- print(np.var(rand_vars_7)) # Output: 7.02419964
- '''
- 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.
- '''
- print(min(rand_vars_7), max(rand_vars_7)) # Output: 0 19
- # Compared to a larger lambda
- # 5000 draws, lambda = 17
- rand_vars_17 = stats.poisson.rvs(17, size = 5000) # Output: 16.85025136
- print(np.var(rand_vars_17))
- 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