---
title: "Binomial and Poisson Distributions"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Benroulli distribution to Binomial

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

```{r}
theta <- .3
rbinom(n=10, size=1, prob=theta)
```

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

```{r}
theta <- .3
sum(rbinom(n=10, size=1, prob=theta))
```

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.)

```{r message=FALSE}
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)
```


