## 2.1 Binomial Distribution

- The binomial distribution is a discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability p.
- Formulas:
- Probability mass function: \[f(k) = \binom{n}{k}p^k(1-p)^{n-k}\]
- Cumulative distribution function: \[F(k) = \sum_{i=0}^k \binom{n}{i}p^i(1-p)^{n-i}\], where \[\binom{n}{k} = \frac{n!}{k!(n-k)!}\], k is the number of successes, n is the number of trials, and p is the probability of success on each trial.

### 2.1.1 Outcome Tables

An outcome tables display all the possible outcomes in a trial . For instance, we wonder about all the possible outcomes when tossing n coins at the same time. When n equals 3, there are 4 possible outcomes including 1) 3 heads-up, 2) 2 heads-up and 1 tails-up, 3) 1 heads-up and 2 tails-up, 4) 3 tails-up. The possibility of the event of all 3 coins being heads-up is much smaller than 2 heads-up and 1 tails-up or 1 heads-up and 2 tails-up. With the trial number big enough, we can observe that the distribution of coin tossing follows the binomial distribution (meaning two names).

**R illustration**

Var1 | Freq |
---|---|

0 | 22 |

1 | 106 |

2 | 218 |

3 | 294 |

4 | 244 |

5 | 105 |

6 | 11 |

### 2.1.2 Contingency Tables

Contingency tables is a two-way table version of the outcome table where we write the outcomes of one event in rows and the outcomes of the other event in columns. For example, assuming we are tossing two coins in 10 trials, rows represent the outcome of the first coin and columns represent the outcomes of the second coin.H | T | Row.totals | |
---|---|---|---|

H | H,H (2) | H,T (1) | 3 |

T | T,H (3) | T,T (4) | 7 |

Columns totals | 5 | 5 | 10 |

**R illustration**

```
<- matrix(c(2, 1, 3, 4), ncol=2, byrow=TRUE)
coins colnames(coins) <- c("H", "T")
rownames(coins) <- c("H", "T")
<- as.table(coins)
coins ::kable(coins, digits = 3, row.names = TRUE, align = "c",
knitrcaption = "Contingency table of tossing two coins in 10 trials")
```

H | T | |
---|---|---|

H | 2 | 1 |

T | 3 | 4 |

```
margin.table(coins) # total number of trials
## [1] 10
margin.table(coins, 1) # marginal totals for rows
## H T
## 3 7
margin.table(coins, 2) # marginal totals for columns
## H T
## 5 5
/margin.table(coins) # probability of each outcome
coins## H T
## H 0.2 0.1
## T 0.3 0.4
```