Binomiale willekeurige variabelen

Binomiale willekeurige variabelen

In dit bericht bespreken we binomiale willekeurige variabelen.
Voorwaarde : Willekeurige variabelen 
Een specifiek type discreet willekeurige variabele die telt hoe vaak een bepaalde gebeurtenis voorkomt in een vast aantal pogingen of pogingen. 
Om een ​​variabele een binomiale willekeurige variabele te laten zijn, moet aan ALLE volgende voorwaarden worden voldaan: 
 

  1. Er is een vast aantal onderzoeken (een vaste steekproefomvang).
  2. Bij elke proef vindt de gebeurtenis van belang wel of niet plaats.
  3. De waarschijnlijkheid dat dit voorkomt (of niet) is bij elke proef hetzelfde.
  4. Beproevingen zijn onafhankelijk van elkaar.


Wiskundige notaties 
 

 n = number of trials   
p = probability of success in each trial
k = number of success in n trials


Nu proberen we de waarschijnlijkheid van k succes in n pogingen te achterhalen.
Hier is de kans op succes in elke poging p, onafhankelijk van andere pogingen. 
We kiezen dus eerst k pogingen waarin er succes zal zijn en in de rest n-k pogingen zal er een mislukking zijn. Het aantal manieren om dit te doen is 
 

Binomiale willekeurige variabelen


Omdat alle n gebeurtenissen onafhankelijk zijn, is de kans op k succes in n pogingen gelijk aan de vermenigvuldiging van de waarschijnlijkheid voor elke poging.
Hier zijn k succes en n-k mislukkingen. Dus de waarschijnlijkheid voor elke manier om k succes en n-k mislukking te bereiken is 
 

Binomiale willekeurige variabelen


De uiteindelijke waarschijnlijkheid is dus 
 

 (number of ways to achieve k success   
and n-k failures)
*
(probability for each way to achieve k
success and n-k failure)


Vervolgens wordt de binominale willekeurige variabele waarschijnlijkheid gegeven door: 
 

Binomiale willekeurige variabelen


Laat X een binomiale willekeurige variabele zijn, waarbij het aantal pogingen n en de kans op succes in elke poging p zijn. 
Het verwachte aantal successen wordt gegeven door 
 

 E[X] = np  


De variantie van het aantal successen wordt gegeven door 
 

 Var[X] = np(1-p)  


Voorbeeld 1 : Beschouw een willekeurig experiment waarbij een bevooroordeelde munt (kans op kop = 1/3) 10 keer wordt gegooid. Bereken de kans dat het aantal hoofden dat verschijnt 5 is.
Oplossing : 
 

 Let X be binomial random variable    
with n = 10 and p = 1/3
P(X=5) = ? Binomiale willekeurige variabelen
     Binomiale willekeurige variabelen 
    

Hier is de implementatie voor hetzelfde 
 

C++
   // C++ program to compute Binomial Probability   #include          #include         using     namespace     std  ;   // function to calculate nCr i.e. number of    // ways to choose r out of n objects   int     nCr  (  int     n       int     r  )   {      // Since nCr is same as nC(n-r)      // To decrease number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;      int     answer     =     1  ;      for     (  int     i     =     1  ;     i      <=     r  ;     i  ++  )     {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }      return     answer  ;   }   // function to calculate binomial r.v. probability   float     binomialProbability  (  int     n       int     k       float     p  )   {      return     nCr  (  n       k  )     *     pow  (  p       k  )     *      pow  (  1     -     p       n     -     k  );   }   // Driver code   int     main  ()   {      int     n     =     10  ;      int     k     =     5  ;      float     p     =     1.0     /     3  ;      float     probability     =     binomialProbability  (  n       k       p  );      cout      < <     'Probability of '      < <     k  ;      cout      < <     ' heads when a coin is tossed '      < <     n  ;      cout      < <     ' times where probability of each head is '      < <     p      < <     endl  ;      cout      < <     ' is = '      < <     probability      < <     endl  ;   }   
Java
   // Java program to compute Binomial Probability   import     java.util.*  ;   class   GFG   {      // function to calculate nCr i.e. number of       // ways to choose r out of n objects      static     int     nCr  (  int     n       int     r  )      {      // Since nCr is same as nC(n-r)      // To decrease number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;          int     answer     =     1  ;      for     (  int     i     =     1  ;     i      <=     r  ;     i  ++  )     {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }          return     answer  ;      }          // function to calculate binomial r.v. probability      static     float     binomialProbability  (  int     n       int     k       float     p  )      {      return     nCr  (  n       k  )     *     (  float  )  Math  .  pow  (  p       k  )     *         (  float  )  Math  .  pow  (  1     -     p       n     -     k  );      }          // Driver code      public     static     void     main  (  String  []     args  )      {      int     n     =     10  ;      int     k     =     5  ;      float     p     =     (  float  )  1.0     /     3  ;          float     probability     =     binomialProbability  (  n       k       p  );          System  .  out  .  print  (  'Probability of '     +  k  );      System  .  out  .  print  (  ' heads when a coin is tossed '     +  n  );      System  .  out  .  println  (  ' times where probability of each head is '     +  p  );      System  .  out  .  println  (     ' is = '     +     probability     );      }   }   /* This code is contributed by Mr. Somesh Awasthi */   
Python3
   # Python3 program to compute Binomial    # Probability   # function to calculate nCr i.e.   # number of ways to choose r out   # of n objects   def   nCr  (  n     r  ):   # Since nCr is same as nC(n-r)   # To decrease number of iterations   if   (  r   >   n   /   2  ):   r   =   n   -   r  ;   answer   =   1  ;   for   i   in   range  (  1     r   +   1  ):   answer   *=   (  n   -   r   +   i  );   answer   /=   i  ;   return   answer  ;   # function to calculate binomial r.v.   # probability   def   binomialProbability  (  n     k     p  ):   return   (  nCr  (  n     k  )   *   pow  (  p     k  )   *   pow  (  1   -   p     n   -   k  ));   # Driver code   n   =   10  ;   k   =   5  ;   p   =   1.0   /   3  ;   probability   =   binomialProbability  (  n     k     p  );   print  (  'Probability of'     k     'heads when a coin is tossed'     end   =   ' '  );   print  (  n     'times where probability of each head is'     round  (  p     6  ));   print  (  'is = '     round  (  probability     6  ));   # This code is contributed by mits   
C#
   // C# program to compute Binomial   // Probability.   using     System  ;   class     GFG     {          // function to calculate nCr      // i.e. number of ways to       // choose r out of n objects      static     int     nCr  (  int     n       int     r  )      {          // Since nCr is same as      // nC(n-r) To decrease       // number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;          int     answer     =     1  ;      for     (  int     i     =     1  ;     i      <=     r  ;     i  ++  )      {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }          return     answer  ;      }          // function to calculate binomial      // r.v. probability      static     float     binomialProbability  (      int     n       int     k       float     p  )      {      return     nCr  (  n       k  )     *         (  float  )  Math  .  Pow  (  p       k  )      *     (  float  )  Math  .  Pow  (  1     -     p        n     -     k  );      }          // Driver code      public     static     void     Main  ()      {      int     n     =     10  ;      int     k     =     5  ;      float     p     =     (  float  )  1.0     /     3  ;          float     probability     =         binomialProbability  (  n       k       p  );          Console  .  Write  (  'Probability of '      +     k  );      Console  .  Write  (  ' heads when a coin '      +     'is tossed '     +     n  );      Console  .  Write  (  ' times where '      +     'probability of each head is '      +     p  );      Console  .  Write  (     ' is = '      +     probability     );      }   }   // This code is contributed by nitin mittal.   
JavaScript
    <  script  >   // Javascript program to compute Binomial Probability      // function to calculate nCr i.e. number of       // ways to choose r out of n objects      function     nCr  (  n       r  )      {      // Since nCr is same as nC(n-r)      // To decrease number of iterations      if     (  r     >     n     /     2  )      r     =     n     -     r  ;          let     answer     =     1  ;      for     (  let     i     =     1  ;     i      <=     r  ;     i  ++  )     {      answer     *=     (  n     -     r     +     i  );      answer     /=     i  ;      }          return     answer  ;      }          // function to calculate binomial r.v. probability      function     binomialProbability  (  n       k       p  )      {      return     nCr  (  n       k  )     *     Math  .  pow  (  p       k  )     *         Math  .  pow  (  1     -     p       n     -     k  );      }       // driver program      let     n     =     10  ;      let     k     =     5  ;      let     p     =     1.0     /     3  ;          let     probability     =     binomialProbability  (  n       k       p  );          document  .  write  (  'Probability of '     +  k  );      document  .  write  (  ' heads when a coin is tossed '     +  n  );      document  .  write  (  ' times where probability of each head is '     +  p  );      document  .  write  (     ' is = '     +     probability     );          // This code is contributed by code_hunt.    <  /script>   
PHP
      // php program to compute Binomial    // Probability   // function to calculate nCr i.e.   // number of ways to choose r out   // of n objects   function   nCr  (  $n     $r  )   {   // Since nCr is same as nC(n-r)   // To decrease number of iterations   if   (  $r   >   $n   /   2  )   $r   =   $n   -   $r  ;   $answer   =   1  ;   for   (  $i   =   1  ;   $i    <=   $r  ;   $i  ++  )   {   $answer   *=   (  $n   -   $r   +   $i  );   $answer   /=   $i  ;   }   return   $answer  ;   }   // function to calculate binomial r.v.   // probability   function   binomialProbability  (  $n     $k     $p  )   {   return   nCr  (  $n     $k  )   *   pow  (  $p     $k  )   *   pow  (  1   -   $p     $n   -   $k  );   }   // Driver code   $n   =   10  ;   $k   =   5  ;   $p   =   1.0   /   3  ;   $probability   =   binomialProbability  (  $n     $k     $p  );   echo   'Probability of '   .   $k  ;   echo   ' heads when a coin is tossed '   .   $n  ;   echo   ' times where probability of '   .   'each head is '   .   $p   ;   echo   ' is = '   .   $probability   ;   // This code is contributed by nitin mittal.   ?>   

Uitgang:  
 

 Probability of 5 heads when a coin is tossed 10 times where probability of each head is 0.333333   
is = 0.136565


 

Quiz maken