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 Geometric distribution
  • Example
  1. Reference
  2. Statistics

Geometric

Represents the number of Bernoulli trials needed to get the first success.

Create a new Geometric distribution

Geometric X = Geometric(p); 

creates a discrete Geometric probability distribution.

Distribution properties:

Property
Type/Return type
Description

p

double -> [0, 1]

Probability of a successful trial.

E()

double

Returns the expected value of executed Bernoulli trials before a successful trial.

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 that the first success occurs on the exactly 𝑘-th trial: P(X = k)

P_LT(int k)

double

Probability that the first success occurs on less than 𝑘-th trials: P(X < k)

P_LTE(int k)

double

Probability that the first success occurs on less than or exactly 𝑘-th trials: P(X ≤ k)

P_HT(int k)

double

Probability that the first success occurs on higher than 𝑘-th trials: P(X > k) = P(X ≤ k)

P_HTE(int k)

double

Probability that the first success occurs on higher than or exactly 𝑘-th trials: P(X ≥ k) = P(X < k)

Example

//Example: A basketball player has a 20% chance of making a free throw. 
//What's the probability of his first successful free throw on his 4th attempt?
double p = 0.2; //probability of a successful event
Geometric X = Geometric(p);
std::cout << X.P(4) << std::endl; //0.1024
Geometric X = Geometric(1.2); // Error: Probability cannot be less than 0 or more than 1.
std::cout << X.P(0) << std::endl; // Error: Number of trials cannot be less than 1. 

Good to know: k cannot be less than 1 and probability p cannot be outside the bounds of [0, 1].

PreviousPoissonNextPascal

Last updated 11 months ago

🥶