# 概率論2

### Bayes 理論的概念

$P(S|A)P(A)=P(A|S)P(S)\\ \Rightarrow P(S|A)=\frac{P(A|S)P(S)}{P(A)}$

$P(S|A)=\frac{P(A|S)P(S)}{P(A|S)P(S)+P(A|\bar{S})P(\bar{S})}$

\begin{align} P(S|A) &= \frac{P(A|S)P(S)}{P(A|S)P(S)+P(A|\bar{S})P(\bar{S})} \\ &= \frac{0.09\times0.2}{0.09\times0.2+0.07\times0.8} \\ &= 0.24 \end{align}

### 期望 Expectation (或均值 or mean) 和 方差 Variance

$E(X)=\sum_x xP(X=x)$

$Var(X)=E((X-\mu)^2)\\其中，\mu=E(x)$

$Var(X)=E(X^2)-E(X)^2$

#### 證明 上面兩個方差公式相等

\begin{align} Var(x) &= E((X-\mu)^2) \\ &= E(X^2-2X\mu+\mu^2)\\ &= E(X^2) - 2\mu E(X) + \mu^2\\ &= E(X^2) - 2\mu^2 + \mu^2 \\ &= E(X^2) - \mu^2 \\ &= E(X^2) - E(X)^2 \end{align}

#### 方差的性質：

1. $$Var(X+b)=Var(X)$$
2. $$Var(aX)=a^2Var(X)$$
3. $$Var(aX+b)=a^2Var(X)$$

### 伯努利分佈 Bernoulli distribution

\begin{align} E(X) &=\sum_x xP(X=x) \\ &=1\times\pi + 0\times(1-\pi)\\ &=\pi \end{align}

\begin{align} Var(X) &=E[X^2]-E[X]^2 \\ &=E[X]-E[X]^2 \\ &=\pi - \pi^2 \\ &=\pi(1-\pi) \end{align}

### 證明，$$X,Y$$ 爲互爲獨立的隨機離散變量時，a) $$E(XY)=E(X)E(Y)$$ ; b) $$Var(X+Y)=Var(X)+Var(Y)$$

1. 證明

\begin{align} E(XY) &= \sum_x\sum_y xyP(X=x, Y=y) \\ \because &\; X,Y are\;independent\;to\;each\;other \\ \therefore &= \sum_x\sum_y xyP(X=x)P(Y=y)\\ &=\sum_x xP(X=x)\sum_y yP(Y=y)\\ &=E(X)E(Y) \end{align}

1. 證明 根據方差的定義： \begin{align} Var(X+Y) &= E((X+Y)^2)-E(X+Y)^2 \\ & \; Expand \\ &=E(X^2+2XY+Y^2)-(E(X)+E(Y))^2\\ &=E(X^2)+E(Y^2)+2E(XY)\\ &\;\;\; - E(X)^2-E(Y)^2-2E(X)E(Y)\\ &\; We\;just\;showed\; E(XY)=E(X)E(Y)\\ &=E(X^2)-E(X)^2+E(Y^2)-E(Y)^2 \\ &=Var(X)+Var(Y) \end{align}
##### 王　超辰 - Chaochen Wang
###### Real World Evidence Scientist

All models are wrong, but some are useful.