# 10 draws with equal prob with replacement
sample(c('H', 'T'), 10, replace = T) [1] "H" "T" "T" "H" "H" "T" "H" "T" "T" "H"
Definition 2.1 We use sets to build the foundational concepts in probability:
Anything (a gamble, an exam, a financial year, …) with uncertain outcomes can be an experiment. The sample space can be finite, countably infinite, or uncountably infinite. It is convenient to visualize events with Venn diagrams.
Outcomes are individual results, while events are groups of outcomes that we are interested in. Outcomes are elements of the sample space, and events are subsets of this space.
Example 2.1 A coin is flipped twice. We write “H” if a coin lands Head, and “T” if a coin lands Tail.
| English | Sets |
|---|---|
| sample space | \(S\) |
| \(s\) is a possible outcome | \(s\in S\) |
| \(A\) is an event | \(A\subseteq S\) |
| \(A\) or \(B\) occurs | \(A\cup B\) |
| Both \(A\) and \(B\) occur | \(A\cap B\) |
| \(A\) does not occur | \(A^{c}\) |
| at least one of \(A_{1},\dots,A_{n}\) occur | \(A_{1}\cup\cdots\cup A_{n}\) |
| all of \(A_{1},\dots,A_{n}\) occur | \(A_{1}\cap\cdots\cap A_{n}\) |
| \(A\) implies \(B\) | \(A\subseteq B\) |
Definition 2.2 \(A\) and \(B\) are disjoint (mutually exclusive) if \(A\cap B=\phi\).
Definition 2.3 \(A_{1},\dots,A_{n}\) are a partition of \(S\) if
\(A_{1}\cup\cdots\cup A_{n}=S\), and
\(A_{i}\cap A_{j}=\phi\) for \(i\neq j\).
Randomly sampling from the set \(\{H,T\}\):
# 10 draws with equal prob with replacement
sample(c('H', 'T'), 10, replace = T) [1] "H" "T" "T" "H" "H" "T" "H" "T" "T" "H"
Compute the probability of \(HH\) when tossing two coins:
# simulate coin tossing 10000 times
toss <- sample(c('H','T'), 10000, replace =T)
# group them into pairs
toss.pair <- paste0(toss[-length(toss)], toss[-1])
# number of HH
n_HH <- sum(toss.pair == 'HH')
# total number of tosses
n_total <- length(toss.pair)
# compute the probability
prob <- n_HH / n_total
cat("Prob of HH: ", prob)Prob of HH: 0.2472247