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)

Bernoulli distribution

It is a course that links mathematical theory with programming application. Discrete Random Variables series gives overview of the most important discrete probability distributions together with methods of generating them in R and basics of numerical methods.

Part 1

Download R
R commands and functions:
  • # - comments out code
  • runif(n) - generates n draws from standard uniform distribution
  • round(x) - rounds x to the nearest integer
  • sum(v) - sums elements of vector v
  • mean(v) - averages elements of vector v
  • v [ i : j ] - looks at elements from vector v indexed from i to j

Part 2

In this video we generate a Bernoulli random variables using R. We familiarize ourselves with boolean variables and logical conditions in R.
R commands and functions:
  • a < b - returns TRUE if a is less than b and FALSE otherwise
  • rbinom(n,1,p) - generates n draws from bernoulli distribution distribution with parameter p