Created
February 5, 2021 02:59
-
-
Save augustgl/b9d6006c26374ba2771226169ae1bfc9 to your computer and use it in GitHub Desktop.
binomial distribution function in python
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
# 2/2/2021 | |
# stats class | |
import math | |
def factorial(n): | |
fact = 1 | |
for i in range(1, n+1): | |
fact = fact * i | |
return fact | |
def findq(p): | |
return 1 - p | |
def binomdist(n, p): | |
for x in range(1, n + 1): | |
numerator = factorial(int(n)) | |
denominator = factorial(int(x)) * factorial(int(n) - int(x)) | |
fraction = numerator / denominator | |
q = findq(p) | |
secondhalf = pow(p, x) * pow(q, (n - x)) | |
final = fraction * secondhalf | |
print str(final) | |
print "[+] MEAN " + str(n * p) | |
print "[+] VARIANCE " + str(n * p * q) | |
print "[+] STANDARD DEVIATION " + str(math.sqrt((n * p * q))) | |
def main(): | |
binomdist(6, .85) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment