outcome_A <- sample(LETTERS, 1)
outcome_A <- sample(LETTERS, 1)
sample
probabilitiessample
probabilitiesThere are many random processes where all the possible outcomes are equally likely.
In these settings, \[ P(\text{Outcome}) = \frac{1}{\text{number of possible outcomes}} \]
sample
probabilitiesThere are many random processes where all the possible outcomes are equally likely.
In these settings, \[ P(\text{Outcome}) = \frac{1}{\text{number of possible outcomes}} \]
Example:
\[ P(\text{Randomly selected letter from English alphabet}) = \frac{1}{\text{26}} \]
sample
probabilitiesThere are many random processes where all the possible outcomes are equally likely.
Informally, outcomes of this type are often called sample
outcomes or urn
outcomes.
More formally, outcomes of this type are sometimes called discrete uniform
random variables.
sample
probabilitiesThere are many random processes where all the possible outcomes are equally likely.
Informally, outcomes of this type are often called sample
outcomes or urn
outcomes.
More formally, outcomes of this type are sometimes called discrete uniform
random variables.
sample
probabilitiesurn
outcomes (or discrete uniform
random variables).sample
probabilitiesurn
outcomes (or discrete uniform
random variables).three_letter_word <- c( sample(LETTERS, 1) , sample(LETTERS, 1) , sample(LETTERS, 1) ) three_letter_word
[1] “D” “T” “B”
sample
probabilitiesurn
outcomes (or discrete uniform
random variables).three_letter_word <- c( sample(LETTERS, 1) , sample(LETTERS, 1) , sample(LETTERS, 1) )
TOM
?sample
probabilitiesanother_three_letter_word <- sample(LETTERS, 3)
What is the probability that another_three_letter_word = TOM
?
In order to calculate
\[ \begin{array}{l} P(\texttt{three_letter_word = TOM}) = \\ \phantom{ = }\phantom{ = } \frac{1}{\text{Number of 3 letter sequences}} \end{array} \]
we need need to calculate the number of 3 letter sequences.
three_letter_word <- c( sample(LETTERS, 1) , sample(LETTERS, 1) , sample(LETTERS, 1) )
another_three_letter_word <- sample(LETTERS, 3)
Is the outcome TOM
the same as MOT
or OTM
?
Is the outcome TOM
the same as MOT
or OTM
?
Sequence: Order matters TOM
\(\neq\) MOT
Hand: Order doesn’t matter TOM
= MOT
A systematic way to write out all sequences.
\[ \underbrace{N \times N \times \cdots \times N}_{K \text{ draws}} = N^K \]
\[ \underbrace{N \times (N-1) \times \cdots \times (N-K+1)}_{K \text{ draws}} = \frac{N!}{(N-K)!} \]
\[N! = N\times(N-1)\times(N-2)\times \cdots \times 3 \times 2 \times 1\]
\[ 5! = 5 \times 4 \times 3 \times 2 \times 1\]
In R:
factorial(5)
## [1] 120
Note
\[ 0! = 1 \]
\[ABC \neq CAB\]
\[ABC = CAB\]
Go back to all the sequences:
\[\frac{\text{Number sequences}}{\text{hand to sequence multiplier}} = \frac{\frac{N!}{(N-K)!}}{K!} = \frac{N!}{(N-K)!K!} \]
\[ {N \choose K} = \frac{N!}{(N-K)!K!} \]
The number of hands of size \(K\) from a deck of \(N\) cards when drawing without replacement.
In R
#The number of 5 card hands from a 52 card deck choose(52,5)
## [1] 2598960
A process or experiment that generates a binary outcome (0 or 1; heads or tails; success or failure)
Successive replications of the process are independent
The probability \(P(outcome = 1)\) is constant
Notation:
\[ Success,\ Success,\ Failure,\ Success\] \[ 1,\ 0,\ 1,\ 1,\ 1,\ 0 \] \[tails,\ tails,\ tails,\ heads\]
Note: A Bernoulli sequence can be thought of as \(K\) draws with replacement from a deck of \(N=2\) cards.
Because successive outcomes are independent and \(p\) is constant,
\[ \begin{align*}P(1,\ 0,\ 1,\ 1,\ 1,\ 0) &= P(1)P(0)P(1)P(1)P(1)P(0) \\ & = p(1-p)ppp(1-p) \\ & = p^4(1-p)^2 \end{align*} \]
The number of successes in a Bernoulli sequence
Bernoulli properties still apply: independent outcomes, constant probability
Notation:
\[\begin{align*}P(\text{2 heads}\ & \text{in 4 flips}) =\\ P(&\text{HHTT or HTHT or HTTH or} \\ &\text{THHT or THTH or TTHH})\end{align*}\]
\[\begin{align*}P(\text{2 heads in 4 flips}) &= P(HHTT)\\& + P(HTHT)\\& + P(HTTH)\\& + P(THHT)\\& + P(THTH)\\& + P(TTHH) \end{align*}\]
\[\begin{align*}P(\text{2 heads in 4 flips}) &= p^2(1-p)^2\\& + p^2(1-p)^2\\& + p^2(1-p)^2\\& + p^2(1-p)^2\\& + p^2(1-p)^2\\& + p^2(1-p)^2 \end{align*}\]
\[P(\text{2 heads in 4 flips}) = 6\ p^2(1-p)^2\]
\[\begin{align*}P(X &\text{ heads in } N \text{ flips}) = \\ &\text{[Number of sequences with X heads]} \times p^X(1-p)^{N-X}\end{align*}\]
\[ \text{cards: } [2],\ [1] \to \{\text{heads}, \text{heads}, \text{tails}, \text{tails}\} \] \[ \text{cards: } [2],\ [4] \to \{\text{tails}, \text{heads}, \text{tails}, \text{heads}\} \]
\[ \text{cards: } [2],\ [1] \to \{\text{heads}, \text{heads}, \text{tails}, \text{tails}\} \] \[ \text{cards: } [1],\ [2] \to \{\text{heads}, \text{heads}, \text{tails}, \text{tails}\} \] \[ \text{cards: } [2],\ [4] \to \{\text{tails}, \text{heads}, \text{tails}, \text{heads}\} \] \[ \text{cards: } [4],\ [2] \to \{\text{tails}, \text{heads}, \text{tails}, \text{heads}\} \]
\[\text{Every sequence with X heads in N flips}\] \[\text{corresponds to}\] \[\text{A hand of X cards from a deck of N (without replacement)}\]
\[\text{Every sequence with X heads in N flips}\] \[\text{corresponds to}\] \[\text{A hand of X cards from a deck of N (without replacement)}\]
We already know how to calculate the number of possible hands of X cards from a deck of N (without replacement)
\[{N \choose X}\]
\[P(X \text{ heads in } N \text{ flips}) = {N \choose X} p^X(1-p)^{N-X}\]
# Probability 2 heads in 4 flips when p = 0.5 dbinom(2,4,.5) # Probability 2 or fewer heads in 4 flips when p = 0.5 pbinom(2,4,.5) # Pseudo-random draw of the number of heads in 10 flips when p = 0.75 rbinom(1,10,.75)
## [1] 0.375 ## [1] 0.6875 ## [1] 5
The number of failures before the \(K^{th}\) success in a Bernoulli sequence is a negative binomial random variable
Bernoulli properties still apply: independent outcomes, constant probability
Notation:
dbinom(4,7,p)*p
# Probability of 3 tails before 5th heads with a fair coin dnbinom(3,5,.5) # Probability of 3 or fewer tails before 5th heads with a fair coin pnbinom(3,5,.5) # Pseudo-random draw of number of tails before 5th heads with a fair coin rnbinom(1,5,.5)
## [1] 0.1367188 ## [1] 0.3632813 ## [1] 5