The geometric distribution

Foundations of Probability in R

David Robinson

Chief Data Scientist, DataCamp

Simulating waiting for heads

flips <- rbinom(100, 1, .1)
flips
#  [1] 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
# [16] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
which(flips == 1)
# [1] 8 27 44 55 82 89
which(flips == 1)[1]
# [1] 8
Foundations of Probability in R

Replicating simulations

which(rbinom(100, 1, .1) == 1)[1]
# [1] 28
which(rbinom(100, 1, .1) == 1)[1]
# [1] 4
which(rbinom(100, 1, .1) == 1)[1]
# [1] 11
replicate(10, which(rbinom(100, 1, .1) == 1)[1])
# [1] 22 12  6  7 35  2  4 44  4  2
Foundations of Probability in R

Simulating with rgeom

geom <- rgeom(100000, .1)
mean(geom)
# [1] 9.04376

$$X \sim \text{Geom}(p)$$

$$E[X]=\frac{1}{p}-1$$

Foundations of Probability in R

Let's practice!

Foundations of Probability in R

Preparing Video For Download...