# 補充: Joint distribution functions 在筆記「[A.2.2 Joint Distribution and Density Functions](https://hackmd.io/@pipibear/H1JnK9HEC)」中,我們有稍微提到一些關於「當我們有兩個 random variable $X,Y$ 時,它們共通的 probability distribution 如何定義」,以及一些相關名詞如 marginal distribution 等內容。 在這篇筆記裡,我參考 Sheldon Ross 的課本,更進一步的去討論這些東西,並給出更詳細的定義。 > $\rightarrow$ $A.2.2$ 的那篇比較短,也很基礎,建議可以先看那篇再看這篇。 --- # 原始定義 ## joint cdf 首先,我們先定義 $X,Y$ 兩個 random variables 的 joint cdf: :::info $X,Y$:random variables <font color = "blue">joint cumulative probability distribution function of $X$ and $Y$</font> 定義為: \begin{equation} F(a,b) = P(X \le a, Y \le b) \qquad -\infty < a,b < \infty \end{equation} ::: ## marginal distribution 透過 $X,Y$ 的 joint cdf,我們可以推導出 $X$ 和 $Y$ 自己的 distribution,也就是 <font color = "snake">marginal distribution of $X / Y$</font> ==$F_X()$== / ==$F_Y()$==: ![image](https://hackmd.io/_uploads/HJDAe-nIA.png) # discrete case ## joint pmf :::info $X,Y$:discrete random variables <font color = "blue">joint probability mass function</font> 定義為: \begin{equation} p(x,y) = P(X = x, Y = y) \end{equation} ::: ## marginal pmf 和上面的作法類似,我們也可以由 joint pmf 推導出 $X,Y$ 各自的 pmf,也稱作 marginal pmf: :::info <font color = "blue">marginal probability mass function of $X$</font>: \begin{equation} \begin{split} p_X(x) &= P(X=x) \\ &= \sum_{y | p(x,y)>0}p(x,y) \end{split} \end{equation} ::: > loop over 那些滿足 $p(x,y)>0$ 的所有可能的 $y$ 代表著無論 $y$ 的值是多少,加總所有情況下 $x$ 和 $y$ 的 joint probability。 > > 舉例來說: > > 假設 $X$ 的 sample space $=\{1,2,3\}$,$Y$ 的 sample space $=\{4,5,6\}$ > 我們想求 $p_X(1)$,也就是 $X=1$ 的機率,那麼就是加總: > - $p(1,4)$ 即 $Y$ 是 $4$ 時,$X$ 是 $1$ 的機率 > - $p(1,5)$ > - $p(1,6)$ $\rightarrow$ 如果還是不清楚,可以參考下面這個圖: ![image](https://hackmd.io/_uploads/SJGkmpkw0.png) 舉例來說,如果我們想知道的是 $P(Y=0)$,也就是 random variable $Y$ 的 outcome 為 $0$ 的機率,那我們的做法就是把最左的那行 $i=0,1,2,3$ 時的機率加總,得到左下角的 $\frac{56}{220}$。 正因為這些值都出現在邊界處(最下列和最右行),所以才稱作 "marginal"。 # continuous case ## joint cdf 首先我們定義 jointly continuous: :::info 我們說 $X,Y$ 是 <font color = "blue">jointly continuous</font> 若: \begin{equation} \exists f(x,y) \quad \text{defined} \ \forall x,y \in \mathbb{R} \end{equation} 使得對任意的 $C \subseteq \mathbb{R}\times\mathbb{R}$ \begin{equation} P((X,Y) \in C) = \iint_{(x,y) \in C}f(x,y) \,dx\,dy \end{equation} 其中 $f(x,y)$ 稱作 <font color = "blue">joint pdf of $X$ and $Y$</font>。 ::: > 也就是說,我們找的到一個 nonnegative function $f: \mathbb{R^2} \rightarrow \mathbb{R}$,使得我們從 $\mathbb{R^2}$ 中任找一些點(每個點都是 $X$ 的 outcome 為某個 $x$,且 $Y$ 的 outcome 為某個 $y$ 的情況),這些點的機率是連續的。 >> 要求 nonnegative 是因為 $f()$ 會 map 到一個機率,機率不可能為負。 因為 $C$ 可以是任意一個 $\subseteq \mathbb{R}\times\mathbb{R}$ 的 set,所以我們可以令 $A,B$ 各自為包含任意實數的 set,然後再去定義 $C$: > 意思就是我們可以分開要求兩個 random variables 各自要是哪些值。 \begin{equation} P(X \in A, Y \in B) = \int_B \int_A f(x,y) \,dx \,dy \end{equation} 並且,根據上面我們提到的 joint cdf 的原始定義($X$ 小於等於某個值且 $Y$ 也小於等於某個值的機率),在 $X,Y$ continuous 的情況下,它們的 joint cdf 為: \begin{equation} \begin{split} F(a,b) &= P(X \in (-\infty,a], \ Y \in (-\infty,b])\\ &= \int_{-\infty}^b \int_{-\infty}^a f(x,y) \,dx \,dy \end{split} \end{equation} ## joint pdf 從上面這個式子我們就能發現,如果要求 $f(x,y)$,只需要對 $F(a,b)$ 的 $a,b$ 偏微(只要 partial derivative defined),即可得到 $f(a,b)$: :::info <font color = "blue">joint pdf</font> $f(a,b)$: \begin{equation} f(a,b) = \frac{\partial^2}{\partial a \partial b} F(a,b) \end{equation} ::: $\rightarrow$ 除此之外,從剛剛這個 equation: \begin{equation} P(X \in A, Y \in B) = \int_B \int_A f(x,y) \,dx \,dy \end{equation} 我們可以有另一種解釋 joint pdf 的方式。 想像我們把 $X$ 可能的值的範圍設定在一個從 $a$ 到距離 $a$ 小小的範圍 $da$ 之間;$Y$ 也同理,範圍設定在一個從 $b$ 到距離 $b$ 小小的範圍 $db$ 之間,那麼我們的兩個 random variables 各自的 outcome,落在這個小範圍內的機率: \begin{equation} \begin{split} P(a < X < a + da, \ b < Y < b + db) &= \int_{b}^{b + db} \int_{a}^{a + da} f(x,y) \,dx \,dy \\ &= f(a,b) \,da \,db \end{split} \end{equation} 其中 $f(x,y)$ continuous at $a,b$。 因此,我們可以說: :::warning $f(a,b)$ 是一種衡量 random vector $(X,Y)$ 多有可能落在 $(a,b)$ 附近的方式。 ::: ## marginal pdf :::warning 如果 $X,Y$ 是 jointly continuous,則它們也會是 individually continuous。 ::: 因此,我們一樣也可以像 discrete case 一樣,由 joint cdf 去定義 marginal pdf: 如果我們以 $X$ 為例, $X$ 的 marginal pdf 就是只考慮 $X$ 的情形,不去考慮 $Y$ 的值到底是多少,也就代表 $Y$ 只要是屬於它的 domain 即可。 \begin{equation} \begin{split} P(X \in A) &= P(X \in A, \ Y \in (-\infty, \infty)) \\ &= \int_A \int_{-\infty}^{\infty}f(x,y) \,dy \,dx \\ &= \int_A f_X(x) \,dx \end{split} \end{equation} where \begin{equation} f_X(x) = \int_{-\infty}^{\infty} f(x,y) \,dy \end{equation} 為 <font color = "blue">marginal pdf of $X$</font>。 > $\int_{-\infty}^{\infty}f(x,y) \,dy$ 就是 sum over all possible $Y$,意思也就是不管 $Y$ 是什麼值,只要落在 domain ($-\infty$ 到 $\infty$)裡,也就把它們的 joint probability 加起來。 > > 最後,因為 $f_X(x)$ 也代表著不管 $Y$ 的情況下, $X$ 落在某個點 $x$ 的機率,所以我們去對所有落在 $A$ 裡的 outcomes 它們的機率去積分,也就是 $P(X \in A)$。 ## 例子 ![image](https://hackmd.io/_uploads/HJDAtCJDC.png) ![image](https://hackmd.io/_uploads/rym4cAJDA.png) ![image](https://hackmd.io/_uploads/ryZL5CkvA.png) ![image](https://hackmd.io/_uploads/S1sP9C1P0.png) # 參考資料 - Sheldon Ross, A first course in Probability, 9th ed, p.239-244 - [5.2.1 Joint Probability Density Function (PDF)](https://www.probabilitycourse.com/chapter5/5_2_1_joint_pdf.php)