# 補充:More Bayesian Concepts
在看本篇筆記以前,關於 prior pdf, posterior pdf⋯⋯的一些相關背景知識,可參考筆記「[補充:Bayesian Estimation](https://hackmd.io/@pipibear/Sy4XW138A)」。
這篇筆記很多概念基本上是延續那篇筆記的內容,所以如果有看不懂而我沒講的地方,基本上能在那篇筆記裡找到說明。
:::danger
本節內容有一些我自己也還沒搞懂的地方,但由於一些概念(如 conjugate prior, improper prior)的內容還是沒有問題的,因此仍先發出來。
我也不清楚的部分有標示,之後會再補。
除此之外,課本中本節最後還有一小段內容在簡短說明 Markov chain Monte Carlo 等相關名詞,我想等整體內容更熟悉後再回過頭來補上。
:::
---
令 $X_1,X_2,...,X_n$ 為一個 random sample,這個 sample 是從一個有著 pdf (或 pmf)為 $f(x|\theta)$ 的 distribution 中取的。
除此之外,我們令 $h(\theta)$ 為 prior pdf。
在筆記「[補充:Bayesian Estimation](https://hackmd.io/@pipibear/Sy4XW138A)」的最後我們有提到,我們可以不用單一個 statistic $Y$,而是像這樣用多個 sample observations $X_1,X_2,...,X_n$ 來討論我們的 distribution。
# predictive distribution
那麼我們先來回顧一下在那篇筆記裡,我們用 joint pdf 來表示 statistic $Y$ 的 marginal distribution 是怎麼做的:

那如果我們對這些 $X_1,X_2,...,X_n$ 也用相同的做法求它們的 marginal distribution,我們就給它一個名稱叫做 <font color = "snake">predictive distribution</font>:

---
:::danger
$\rightarrow$ 以下這段分隔線中的內容等我弄懂之後會再寫得清楚一些。
:::
> 為什麼叫做 predictive distribution ,是因為 $k(x_1,x_2,...,x_n)$ 提供了 $X_1,X_2,...,X_n$ outcome 的 probabilities 最好的描述。
>> 課本是這樣寫,雖然我覺得聽起來有點模糊,但還是將原話附上。之後如果有更深的理解以後會再來對這部分修改。
關於 predictive pdf (predictive distribution 的 pdf)的意義,其實是:
:::warning
我們將 paramter $\theta$ 利用積分積掉(使得 predictive distribution 不會 depend on $\theta$),進而在 given observed data,以及(得到 observed data 後產生的) updated postrior pdf 的情況下,來對新的 data 進行預測。
:::
所以儘管 predictive pdf 和 marginal pdf 的結構可能很類似、數學式也有可能長的一樣,但是他們是 for 不同的 purpose。
> Recall: marginal pdf 一樣會把 parameter 積掉,來在 given prior 的情況下找出 observed data 的 probability
>> 就像我們最上方圖中的 $k_1(y)$ ,是把 $\theta$ 積掉,來看 observe $Y=y$ 的 probability。
>>
> 兩者之間的差異在於 marginal pdf 並不會 incorporate 新的 data。
---
我們先按照課本的說法繼續討論:
通常 predictive distribution $k(x_1,x_2,...,x_n)$ 會具有特殊的 distribution,我們來看個例子比較清楚。
## precision
我們的例子假設一個具 normal distribution 的 random variable $X$, $X$ 具有 pdf 如下:

> 藉由這個例子,我們順便定義 <font color = "snake">precision (of $X$)</font> ==$\theta$==
接著,precision $\theta$ 也有自己的 distribution,這裡假設 $\theta$ 具 gamma distribution:
> 關於 gamma distribution 的介紹可參考筆記「[補充:Gamma Distribution](https://hackmd.io/@pipibear/r1agDjvUC)」。

有了這兩個式子($f(x|\theta)$ 和 $h(\theta)$)以後,我們就能來計算 predictive distribution 的 pdf,根據定義再一路化簡後會得到下圖中的結果:

> 圖中關於我拉出來算的那個積分其實可以透過旁邊 Note 的公式直接計算,但是我還是再推導一遍,主要的想法是把那個積分化為 $\Gamma(t)$ 的形式。
>> 關於這部分內容以及 Note 的公式,可參考筆記「[補充:Gamma Distribution](https://hackmd.io/@pipibear/r1agDjvUC)」中 「gamma function」 的部分以及它的子小節「特性」。
最後我們得到的 $k_1(x)$ 其實正比於一個 $t$ distribution with $r$ degrees of freedom。
> 關於 $t$ distribution 的 pdf 可參考筆記「[補充:random functions associated with normal distributions](https://hackmd.io/@pipibear/rkYLmUhVR)」的最後一部分「定理與例子」中「Thm 5.5-2」最下方的內容。

我們得到結論:
如果一個 normal distribution 的 precision $\theta = \frac{1}{\sigma^2}$ 為 gamma random variable(具 gamma distribution 的 random variable),那求出來的 predictive distribution $k_1(x)$ 就會是 generalized 的 $t$-distribution,有著比 normal distribution 更寬的 tails。
> 更寬的 tails 意味著極端值更容易發生。
>> 關於 $t$-distribution 的介紹可參考筆記「[A.3.7 t distribution](https://hackmd.io/@pipibear/HkU6rYqLC)」。

## GMM (Gaussian mixture model, mixture of normals)
除此之外,如果我們把 gamma distribution 視為 weight,則 $k_1(x)$ 可以被視為<font color = "snake">mixture of normals</font>(不同於 <font color = "snake">mixed distribution</font>),而這個過程又稱作 <font color = "snake">compounding</font>。
> 以上這段話我們一步一步在下方解釋。
Q:什麼是 "mixture of normals","compounding" 又是什麼?

### mixed distribution
Q:"mixture of normals" 和 "mixed distribution" 的差異是什麼?
> 上面解釋過 mixture of normals,所以我們這裡就只解釋 mixed distribution。

Q:所以為什麼 $k_1(x)$ 可以被視為 mixture of normals weighting with gamma distribution?

> 上面我們有講到 mixture of normals 就是加總許多不同的 normal distributions,每個有一個對應的 weight,我們的 $k_1(x)$ 其實就符合這樣的形式。
再簡短舉另一個例子:

### conjugate prior
我們先在這裡定義一下 <font color = "snake">conjugate prior</font>:
:::info
如果 parameter $\theta$ 的 prior pdf 為 $h(\theta)$,且 data $Y$ 的 likelihood function 為 $L(y|\theta)$,則若 ++posterior pdf++:
\begin{equation}
f(\theta|y) \propto h(\theta)L(y|\theta)
\end{equation}
++屬於和 prior 相同的 distributional family++,則我們稱這個 prior 為 conjugate prior。
:::
舉個例子:

### improper prior
接下來,我們要來介紹 <font color = "snake">improper prior</font>,先看個例子:

> 從這個例子裡,我們看到了如果一個 prior 並不滿足作為 pdf 的 properties,那麼就會被稱作 improper prior。
Q:既然 improper prior 根本不能算是 pdf,那它要作什麼用?
A:在 Bayesian statistics 中,我們通常會用 improper prior 來表示不清楚或 non-informative 的 prior information,雖然它 improper,但是我們可以在 observed data 以後,藉由結合 observed data 的 likelihood,讓 posterior distribution 變得 proper(也就是可以積成 $1$。)
延續上面的例子,我們接著就乘上 joint pdf 來看 posterior pdf 會變成什麼樣子:

經過下方兩張圖一連串的計算以後,我們最後會得到 $k_{12}(\theta_1|x_1,..,x_n)$ 正比於 $t$-distribution 的 pdf。
因此我們能夠發現,儘管一開始我們用的是 improper prior,最後還是可以得到 proper 的 pdf。


# 參考資料
- Hogg,Tanis,Zimmerman, Probability and Statistical Inference, 9th ed(2015),p.294-296
> Section 6.9 More Bayesian Concepts
- Introduction to Probability, Statistics and Random Processes:
- [4.3.1 Mixed Random Variables](https://www.probabilitycourse.com/chapter4/4_3_1_mixed.php)
> mixed distribution 例子。
- [9.2.0 End of Chapter Problems](https://www.probabilitycourse.com/chapter9/9_2_0_ch_probs.php)
> 17 題為 conjugate prior 例子。