binomial.py

Created by numworks-nl

Created on March 04, 2020

397 Bytes

Dit script bevat twee functies voor het berekenen van binomiale kansen: binomialpdf(k,N,p) geeft p(X=k) en binomialcdf(k,N,P) geeft p(X≤k) voor N-herhalingen en een succeskans p.


from math import *
def factorial(n):
  n=int(n)
  if n<0:
    return None
  res=1
  for i in range(1,n+1):
    res=res*i
  return res
def n_choose_k(n,k):
  return int(factorial(n)/(factorial(k)*factorial(n-k)))
def binomialpdf(k,N,p):
  return n_choose_k(N,k)*(p**k)*((1-p)**(N-k))
def binomialcdf(k,N,p):
  res=0
  for i in range(k+1):
    res=res+binomialpdf(i,N,p)
  return res

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.