Infermath logo

Infermath

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)

Borel-Cantelli lemma

Borel-Cantelli lemma describes the behaviour of infinite series of Bernoulli trials. It specifies under which conditions certain events keep on happening.

Part 1

We create a function in R returning a result of Bernoulli trial and we use it in for loop to generate series of trials. We try to understand what does it mean for a series of events to happen infinitely many times.
R commands and functions:
  • f=function(x){return(x*x)} - function syntax in R, f(3) returns square of 3
  • print(x) - prints value of x in console
  • flush.console() - forces output display
  • Sys.sleep(x) - holds execution for x sec

Part 2

We derive probability distribution of the Borel-Cantelli random variables and learn about Borel-Cantelli series. We encounter cumulative distribution function
Mathematical formulas:
Borel-Cantelli series

Part 3

We prove the second part of Borel-Cantelli lemma. We come across exponential function, complementary events, a monkey and William Shakespeare.
Borel - Cantelli lemma part 2:
Borel-Cantelli part 2

Part 4

In the last episode of discrete random variables we use Borel-Cantelli lemma to generate infinite series of successful Bernoulli trials. As we approach infinity we turn to philosophy and music.
R commands and functions:
  • .Machine$integer.max - returns maximal number od type integer
  • sqrt(x) - square root of x
  • if(bool){do} - executes do command if bool logical condition is TRUE