Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scipy.stats as stats # import library
- # full formula: stats.binom.pmf(x, n, p)
- # binom stands for binomial distribution, pmf stands for probability mass function
- # value of interest
- x = 3
- # sample size/no. of trials
- n = 10
- # calculate probability
- prob_1 = stats.binom.pmf(x, n, 0.5) # last parameter represents probability of success (p)
- print(prob_1)
- # To calculate probability over a range
- # for observing between 4 to 6 heads from 10 coin flips - add them together
- prob_1 = stats.binom.pmf(4, 10, 0.5) + stats.binom.pmf(5, 10, 0.5) + stats.binom.pmf(6, 10, 0.5)
- print(prob_1)
- # for observing more than 2 heads from 10 coin flips (ie. from 3 to 10)
- # use the 1 minus the sum of some values as a shortcut for unwanted 0 to 2 heads
- prob_2 = 1 - (stats.binom.pmf(0, 10, 0.5) + stats.binom.pmf(1, 10, 0.5) + stats.binom.pmf(2, 10, 0.5))
- print(prob_2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement