Infermath logo


Open source of math

Probability in R: Discrete Random Variables

  1. Bernoulli distribution (2 tutorials)
  2. Binomial distribution (3 tutorials)
  3. Geometric distribution (3 tutorials)
  4. Borel-Cantelli lemma (4 tutorials)

Geometric distribution

Binomial distribution is an extension of Bernoulli ditribution. It models the first successful trial in a multiple Bernoulli.

Part 1

We define geometric distribution and draw random variables from it in R. We familiarize ourselves with while loop and scientific notation.
R commands and functions:
  • while(bool){do} - repeats do command while bool logical condition is TRUE
  • rgeom(n,p) - generates n draws from geometric distribution with parameter p
  • 1+e6 - short notation for 10 to power 6

Part 2

We derive probability distribution of the geometric random variables and learn about geometric series. We encounter cumulative distribution function
Mathematical formulas:
Geometric series

Part 3

We want to increase to infinity the maximum value coming from geometric distribution. On our way we encounter NAs and machine epsilon but don't give up.
R commands and functions:
  • max(v) - returns maximal element in data set v
  • na.rm=TRUE - optional function argument making it ignore NA values
  • .Machine$Double.eps - returns lowest in absolute value number of type double