maTH
  • 👋Welcome!
  • 🗿Installation
  • Reference
    • 😱Mathematical operations
      • add
      • pascal
      • factorial
      • factorialL
      • GCD
      • LCM
      • pow
      • permutations
      • combinations
      • combinationsWithRep
      • subtract
      • multiply
      • divide
      • sin
      • cos
      • ln
      • log
      • radToDeg
      • degToRad
      • mod
      • abs
      • floor
      • ceil
      • root
      • exp
      • tan
      • arcsin
      • arccos
      • arctan
      • sinh
      • cosh
      • round
    • 🥶Statistics
      • Binomial
      • Poisson
      • Geometric
      • Pascal
      • Hypergeometric
      • Exponential
      • Uniform
    • 🥵Data structures
      • Stack
      • Queue
      • LinkedList
    • 🤓Algorithms
      • Bubble sort
      • Insertion sort
      • Selection sort
      • Merge sort
      • Quicksort
      • Heap sort
      • Count sort
      • Bucket sort
      • Radix sort
    • 😳Constants
Powered by GitBook
On this page
  • Create a new Binomial distribution
  • Example
  1. Reference
  2. Statistics

Binomial

Represents the number of successes in a fixed number of independent and identically distributed Bernoulli trials (each trial having two possible outcomes: success or failure)

Create a new Binomial distribution

Binomial X = Binomial(n, p); 

creates a discrete Binomial probability distribution.

Distribution properties:

Property
Type/Return type
Description

n

int

Number of executed events

p

double -> [0, 1]

Probability of a succesful event

E()

double

Returns the expected value of succesful events after executing n independend events, all with constant probability of p.

D()

double

Represents variance, that measures the spread of dispersion of the random variable around its expected value E(X).

P(int k)

double

Probability of obtaining exactly 𝑘 successes in 𝑛 trials: P(X = k)

P_LT(int k)

double

Probability of obtaining less than 𝑘 successes in 𝑛 trials: P(X < k)

P_LTE(int k)

double

Probability of obtaining less than or exactly 𝑘 successes in 𝑛 trials: P(X ≤ k)

P_HT(int k)

double

Probability of obtaining more than 𝑘 successes in 𝑛 trials: P(X > k) = P(X ≤ k)

P_HTE(int k)

double

Probability of obtaining more than or exactly 𝑘 successes in 𝑛 trials: P(X ≥ k) = P(X < k)

Example

//Example: what's the probability of getting exactly 5 heads 
//when flipping a coin 10 times?
double p = 0.5; //probability of getting heads is 50%
int n = 10; //10 independed events
Binomial X = Binomial(n, p);
std::cout << X.P(5) << std::endl; //0.246094
Binomial X = Binomial(25, -0.5); //Error: Probability cannot be less than 0 or more than 1.
std::cout << X.P(30) << std::endl; //Error: The number of succesful trials cannot exceed the number of all trials or be less than 0.  

Good to know: k cannot exceed the number of executed events and probability p cannot be outside the bounds of [0, 1].

PreviousStatisticsNextPoisson

Last updated 11 months ago

🥶