# 聯合密度函數

(1)
\begin{align} f_{XY}(x,y) = P[X=x, Y=y] \\ \end{align}

(2)
\begin{eqnarray} 1. && f_{XY}(x,y) \ge 0 \\ 2. && \sum_{\forall x} \sum_{\forall y} f_{XY}(x,y) = 1 \end{eqnarray}

(3)
\begin{eqnarray} 1. && f_{XY}(x,y) \ge 0; \\ 2. && \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} f_{XY}(x,y) dy dx = 1 \\ 3. && P[a \le X \le b, c \le Y \le d,] = \int_{a}^{b} \int_{c}^{d} f_{XY}(x,y) dy dx \\ \end{eqnarray}

# 邊際密度函數

(4)
\begin{align} 1. && f_{X}(x) = \sum_{\forall y} f_{XY}(x,y) \\ 2. && f_{Y}(y) = \sum_{\forall x} f_{XY}(x,y) \\ \end{align}

(5)
\begin{eqnarray} 1. && f_{X}(x) = \int_{-\infty}^{\infty} f_{XY}(x,y) dy \\ 2. && f_{Y}(y) = \int_{-\infty}^{\infty} f_{XY}(x,y) dx \\ \end{eqnarray}

# 隨機變數之間的獨立性

(6)
\begin{eqnarray} f_{XY}(x,y) = f_{X}(x) f_{Y}(y) \end{eqnarray}

# 聯合分配的期望值

(7)
\begin{eqnarray} 1. 離散的情況：&& E[H(X,Y)] = \sum_{\forall x} \sum_{\forall y} H(x,y) f_{XY}(x,y) \\ 2. 連續的情況：&& E[H(X,Y)] = \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} H(x,y) f_{XY}(x,y) dy dx \\ \end{eqnarray}

(8)
\begin{eqnarray} 1. 離散：&& E[X] = \sum_{\forall x} \sum_{\forall y} x f_{XY}(x,y) \\ 2. 離散：&& E[Y] = \sum_{\forall x} \sum_{\forall x} x f_{XY}(x,y) \\ 3. 連續：&& E[X] = \int_{-\infty}^{\infty} x f_{XY}(x,y) dy dx \\ 4. 連續：&& E[Y] = \int_{-\infty}^{\infty} y f_{XY}(x,y) dy dx \\ \end{eqnarray}

# 共變異數 (Covariance, 協方差)

(9)
\begin{align} \sigma_{XY} = Cov(X, Y) = E[(X - \mu_X)(Y - \mu_Y)] \end{align}

# 相關係數 (Correlation)

(10)
\begin{align} Cor(X,Y) = \rho_{X Y} = \frac{Cov(X,Y)}{\sqrt{Var(X) Var(Y)}} \end{align}

# R 程式：相關係數

> cor(x, x+1)
[1] 1
> cor(x, -x)
[1] -1
> cor(x, 0.5x)

> cor(x, 0.5*x)
[1] 1
> 0.5*x
[1]  6.0  8.5 25.0 16.5 49.0 38.5 19.5 39.5  3.5 13.0
> cor(x, 0.5*x+1)
[1] 1
> cor(x, -0.5*x+1)
[1] -1
> y=sample(1:100, 10)
> y
[1] 53 69 57 93 27 37 60 83 77 55
>
> cor(x,y)
[1] -0.4683468


[[/code]]