binomio.py

Created by numworks-italia

Created on April 10, 2020

377 Bytes

Questo script contiene due funzioni per il calcolo delle probabilità binomiali: binomialpdf(k,N,p) rimanda a p(X=k) e binomialcdf(k,N,P) rimanda a p(X≤k) per N ripetizioni e una probabilità di successo p.


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 cookies policy.