---
# System prepended metadata

title: Stat04
tags: [Stat]

---

---
title: Stat04
tags: Stat
---



#### 

---
I. Probability
1. Ch4: Law of total probability
2. Ch4: Bayes Rule
:::info
Example: A rat was trapped in a myth. Therer three doors. 
This rat choose door A with probabiltiy 0.3, door B with probability 0.5, door C with probabiltiy 0.2. 
If this rat chooses A, it will survive with probabiltiy 0.9, 
If this rat chooses B, it will survive with probabiltiy 0.2, 
If this rat chooses C, it will survive with probabiltiy 0.5, 
Question: if this rat survives, what is the probabiltiy that he chooses C? 

Sol.
$$P(C|S) = \frac{0.2\times 0.5}{0.3\times 0.9+ 0.5\times 0.2 + 0.2\times 0.5 } = \frac{10}{47}= 0.2121$$

:::
2. Ch4: Random variable

:::info
Example 1: A very simple example to illustrate a random variable. 

Toss a fair coin twice. Let $X$ denote a random variable that counts the number of heads. 

| $\omega$  | Probability |  $X=x$|
| ------- | -----| ---- |  
| HH | 1/4 | 2|  
| HT |1/4 | 1| 
|TH  |1/4 |1|
|TT | 1/4 | 0| 

As a neat person, we summarize the above results for $X$ in the following table:
|$X=x$ | $P(X=x)$| 
|--- | ---|
| 0 | 1/4 | 
| 1 | 1/2|
| 2 | 1/4| 

:::

:::info
Example 2: Bernoulli random variable. 

Bernoulli trial is an experiment that will succeed with probability $p$ and fail with probability $(1-p)$. Let $X$ denote the random variable that gives 1 if a Bernoulli trial succeeds, and 0 otherwise. 

Bernoulli trial 
| $\omega$ | Probility | $X=x$|
| ---|----|----|
| S | $p$ | 1 |
| F | $(1-p)$ | 0|

We re-organize the above results: 

|$X=x$ | $P(X=x)$| 
|--- | ---|
| 0 | $(1-p)$ | 
| 1 | $p$|



We denote $X\sim Bernoulli(p)$, here $p$ is the *parameter*. 


$$P(X=x) = \begin{cases}p ,& \mbox{for } x=1,\\
(1-p),&\mbox{for }x=0\end{cases}.$$

Or, even more succinct: 
$$P(X=x) =p^x(1-p)^{1-x} , \mbox{for } x=0,1.$$


Note that Bernoulli is a special case of Binomial when $n=1$. 
$Bernoulli(p) \stackrel{d}{=} Binomial(n=1,p)$

The mean):
$$\mu = 0 \times (1-p) + 1 \times p  = p $$

Variance:
$$\sigma^2 = (0-p)^2 \times (1-p) + (1-p)^2 \times p = p(1-p).$$


:::


3. Ch4: Mean and variance

### II. Discrete random variable 


## Homework

### 4.R.8 The Birthday Problem 

Two people enter a room and their birthdays (ignoring years) are recorded.

a. Identify the nature of the simple event in $S$.
b. What is the probability that tow two people have a specific pair of birthdates?
c. Identify the simple events in event $A$: Both people have the same birthday. 
d. Find $P(A)$.
e. Find $P(A^c)$.


### 4.R.9 The Birthday Problem, continued. 

If $n$ people enter a room, find these probabilities: 

$A$: None of the people have the same birthday
$B$: At least two of people have the same birthday


Solve for 
a. $n=3$
b. $n=4$

#### Sol. 

$P(A) = \frac{365\times 364 \times 363 \times \cdots \times (365-n+1)}{365^n}$

$P(B)=1-P(A)=1-\frac{365\times 364 \times 363 \times \cdots \times (365-n+1)}{365^n}$.

If $n=3$, 
$P(A)= 0.9918$, $P(B) = 0.0082$. 

If $n=4$, 
$P(A)= 0.9836$, $P(B) = 0.0164$. 




### 4.R.20: Tossing a Coin

How many times should a coin be tossed to obtain a probability equal to or greater than 0.9 of observing at least one head? 





