Benroulli distribution to Binomial

Reminder: here is how we generated Bernoulli variables with the parameter \(\theta\).

theta <- .3
rbinom(n=10, size=1, prob=theta)
##  [1] 1 1 1 1 0 0 1 0 1 0

The Binomial(n) distribution is just a sum of a n Bernoulli variables. Let’s generate a Binomial(n) distribution

theta <- .3
sum(rbinom(n=10, size=1, prob=theta))
## [1] 6

Let’s just confirm that those are the same distribution.

(Note: the following replicates the computation sum(rbinom(n=5, size=1, prob=theta)) 1000 times.)

library(ggplot2)
sum_bernoulli1000 <- replicate(1000, sum(rbinom(n=5, size=1, prob=theta)))
binom1000 <- replicate(1000, rbinom(n=1, size=5, prob=theta))
qplot(sum_bernoulli1000)

qplot(binom1000)