---
# System prepended metadata

title: 連續隨機變數分配-相關推導
tags: [統研所考試, 機率數統]

---

# 連續機率密度函數的$E(X)、VAR(X)、M_x(t)$
###### tags: `統研所考試`、`機率數統`


## 連續部分

### 均勻分配
$f_x=\frac{1}{b-a}$ , $a≦x≦b$

#### ++E(X)++
**1.使用定義**
$E(X)=\int_a^bx\frac{1}{b-a}  \mathrm{d} x$
$=\frac{1}{b-a}[\frac{1}{2}x^2]^b_a=\frac{1}{b-a}\times\frac{(b+a)(b-a)}{2}$
$=\frac{(b+a)}{2}$

**2.使用Monment Generating Function**
$E(X)=M^`_x(0)$
$M^`_x(t)=\frac{(e^{tb}-e^{ta})(b-a)^2t-(e^{tb}-e^{ta})(b-a)}{[(b-a)t]^2}$
$=\frac{(e^{tb}-e^{ta})}{t}-\frac{(e^{tb}-e^{ta})}{(b-a)t^2}$


#### ++VAR(X)++
**1.使用定義**
$VAR(X)=E(X^2)-[E(X)]^2$
$E(X^2)=\int_a^bx^2\frac{1}{b-a}  \mathrm{d} x$
$=\frac{1}{b-a}[\frac{1}{3}x^3]^b_a=\frac{1}{b-a}\times\frac{(b^3-a^3)}{3}$
$=\frac{1}{b-a}\times\frac{(b-a)(b^2+ab+a^2)}{3}$
$=\frac{(b^2+ab+a^2)}{3}$

$VAR(X)=\frac{(b^2+ab+a^2)}{3}-\frac{(b+a)^2}{2}$
$=\frac{(4b^2+4ab+4a^2-3b^2-6ab-3a^2)}{12}$
$=\frac{(b^2-2ab+a^2)}{12}=\frac{(b^-a)^2}{12}$

**2.使用Monment Generating Function**
$E(X^2)=M^{``}_x(0)$


#### ++M~x~(x)++
$M_x(X)=\int_a^b e^{tx}\frac{1}{b-a}  \mathrm{d} x$
$=\frac{1}{b-a}[\frac{1}{t}e^{tx}]^b_a=\frac{e^{tb}-e^{ta}}{(b-a)t}$

### 指數分佈1
> 指數分佈共2種寫法
$f_x=\frac{1}{θ}e^{\frac{-x}{θ}}$ , $0<x<\infty$

#### ++E(X)++
**1.使用定義**
$E(X)=\int_0^\infty x\frac{1}{θ}e^{\frac{-x}{θ}}  \mathrm{d} x$
$=\frac{1}{θ}\int_0^\infty xe^{\frac{-x}{θ}}  \mathrm{d} x$
Let $u = \frac{-x}{θ}$,　$x=-θu$　$dx = -θdu$,　range不變
$=-θ\int_0^\infty ue^u \mathrm{d} u$
$=-θ[ue^u-e^u]_0^\infty=θ$

**2.使用Monment Generating Function**
$E(X)=M^`_x(0)$
$M^`_x(t)=θ(1-tθ)^{-2}$
$M^`_x(0)=θ$

`
#### ++VAR(X)++
**1.使用定義**
$E(X^2)=\int_0^\infty x^2\frac{1}{θ}e^{\frac{-x}{θ}}  \mathrm{d} x$
$=\frac{1}{\theta}\Gamma (3)\theta^3$
$=2\theta^2$

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



**2.使用Monment Generating Function**
$E(X)=M^{``}_x(0)$
$M^`_x(t)=θ(1-tθ)^{-2}$
$M^{``}_x(t)=2θ^2(1-tθ)^{-3}$
$M^{``}_x(0)=2θ^2$
$VAR(X)=2θ^2-θ^2=θ^2$


#### ++M~x~(x)++
$M_x(X)=\int_0^\infty e^{tx}\frac{1}{θ}e^{\frac{x}{θ}}  \mathrm{d} x$
$=\int_0^\infty \frac{1}{θ}e^{(\frac{-1}{θ}+t)^x}  \mathrm{d} x$
Let $u = x(1-tθ)$, $du=(1-tθ)dx,range不變$
$=\frac{1}{1-tθ}\times \frac{1}{θ}\int_0^\infty e^{\frac{-u}{θ}} \mathrm{d} u$
$=\frac{1}{1-tθ}\times \frac{1}{θ}[-θe^{\frac{-u}{θ}}]_0^\infty=\frac{1}{1-tθ}\times \frac{1}{θ} \times θ$
$=\frac{1}{1-tθ}$

### 指數分佈2
> 指數分佈共2種寫法
> $\lambda=\frac{1}{θ}$

$f_x=\lambda e^{-\lambda x}$ , $0<x<\infty$
> 兩種寫法的差異在於，$\lambda$ 代表的是某個時間區間下的發生頻率，$\beta$ or $\theta$ 則是發生事件1次的所需CD時間。

#### ++E(X)++
**1.使用定義**
$E(X)=\int_0^\infty x\lambda e^{-\lambda x}\mathrm{d} x$
Let $u = \lambda x$, $du =\lambda du$
$=\frac{1}{\lambda}\int_0^\infty u e^{-u}\mathrm{d} u$
$=\frac{1}{\lambda}[-ue^{-u}-e^{-u}]_0^\infty$
$\frac{1}{\lambda}$

#### ++VAR(X)++
**1.使用定義**
$E(X^2)=\int_0^\infty x^2\lambda e^{-\lambda x}\mathrm{d} x$
Let $u = \lambda x$, $du =\lambda du$
$=\frac{1}{\lambda^2}\int_0^\infty u^2 e^{-u}\mathrm{d} u$
$=\frac{1}{\lambda^2}[-u^2e^{-u}-2ue^{-u}+2e^{-u}]_0^\infty$
$=\frac{2}{\lambda^2}$
$VAR(X)=\frac{2}{\lambda^2}-\frac{1}{\lambda^2}=\frac{1}{\lambda^2}$

#### ++M~x~(x)++
$M_x(X)=\int_0^\infty e^{tx}\lambda e^{-\lambda x}\mathrm{d} x$
$=\int_0^\infty \lambda e^{(t-\lambda )x}\mathrm{d} x$
Let $u=tx-\lambda x$, $du=(t-\lambda)dx$
$=\frac {\lambda}{t- \lambda} \int_0^{\infty} e^u du=\frac {\lambda}{t- \lambda} [e^u]_0^{\infty}$
$\frac {\lambda}{t- \lambda}$,　$t<\lambda$

### Gamma分布1
> 共2種寫法
> 是指數分布的累加版本

:::info
:information_source: Gamma Function:
$Γ(α)= \int_0^\infty x^{α-1}e^{-x} dx=(α-1)!$
:::

$f_x=\frac {\lambda ^αx^{α-1}e^{-\lambda x}}{Γ(α)}$, $x>0$

#### ++E(X)++
**1.使用定義**
$E(X)=\int_0^\infty \frac {x \times\lambda ^αx^{α-1}e^{-\lambda x}}{Γ(α)}$
$=\int_0^\infty \frac {\lambda ^αx^{α}e^{-\lambda x}}{Γ(α)}$
$=\frac{α}{\lambda}\int_0^\infty \frac {\lambda ^{α+1}x^{α}e^{-\lambda x}}{Γ(α+1)}=\frac{α}{\lambda}$


#### ++VAR(X)++
**1.使用定義**
$E(X^2)=\int_0^\infty \frac {x^2 \times\lambda ^αx^{α-1}e^{-\lambda x}}{Γ(α)}$
$=\int_0^\infty \frac {\lambda ^αx^{α+1}e^{-\lambda x}}{Γ(α)}$
$=\frac{α(α+1)}{\lambda^2}\int_0^\infty \frac {\lambda ^{α+1}x^{α}e^{-\lambda x}}{Γ(α+1)}=\frac{α(α+1)}{\lambda^2}$

$VAR(X)=\frac{α(α+1)}{\lambda^2}-\frac{α^2}{\lambda^2}=\frac{\alpha}{\lambda^2}$


#### ++M~x~(x)++
$M_x(X)=\int_0^\infty \frac {e^{tx} \times\lambda ^αx^{α-1}e^{-\lambda x}}{Γ(α)}$
$=\int_0^\infty \frac {\lambda ^αx^{α-1}e^{-(\lambda-t) x}}{Γ(α)}$
$=\frac{\lambda^α}{Γ(α)}\int_0^\infty x^{α-1}e^{-(\lambda-t)x}dx$
$=\frac{\lambda^α}{Γ(α)}(\frac{1}{\lambda-t})^α(α-1)!=(\frac{\lambda}{\lambda-t})^α$

:::info
:information_source: Use DI method:



![](https://hackmd.io/_uploads/S1eQ7gU8n.png)

帶入值$[0,\infty]$的話，會發現有x的值都會變成0，只剩下0帶入的最後一個成積有東西，解x=0代入$-[(α-1)!x^{α-α=0} \times -(\frac{1}{\lambda-t})^αe^{-(\lambda-t)x}]$
即為$(\frac{1}{\lambda-t})^α(α-1)!$
:::

### Gamma分布2
> 共2種寫法
> 是指數分布的累加版本

$f_x = \frac { αx^{α-1}e^{\frac {-x}{\beta} }}{\beta^aΓ(α)}$, $x>0$

證明同1，部份省略。

#### ++E(X)++
**1.使用定義**


\begin{array}{rcl}
E(X) &=& \int_0^\infty \frac{x  x^{\alpha-1} e^{-\beta x}}{\Gamma(\alpha)\beta^\alpha} \, dx \\
     &=& \int_0^\infty \frac{ x^\alpha e^{-\beta x}}{\Gamma(\alpha) \beta^\alpha} \, dx \\
     &=& \alpha \beta \int_0^\infty \frac{ x^\alpha e^{-\beta x}}{\Gamma(\alpha+1)\beta^{\alpha+1}} \, dx \\
     &=& \alpha \beta
\end{array}



#### ++VAR(X)++
**1.使用定義**

\begin{array}{rcl}
E(X^2) &=& \int_0^\infty \frac{x^2  x^{\alpha-1} e^{-\beta x}}{\Gamma(\alpha)\beta^\alpha} \, dx \\
       &=& \int_0^\infty \frac{ x^{\alpha+1} e^{-\beta x}}{\Gamma(\alpha)\beta^\alpha} \, dx \\
       &=& \alpha(\alpha+1)\beta^2\int_0^\infty \frac {x^{\alpha}e^{-\lambda x}}{\Gamma(\alpha+1)\beta ^{\alpha+1}}  \, dx\\
       &=&\alpha(\alpha+1)\beta^2
\end{array}


$\mathsf{Var}X=\alpha(\alpha+1)\beta^2 -(\alpha \beta)^2= \alpha \beta ^2$


### Laplace 分布
>常態分佈的前身
$f_x= \frac{1}{2\sigma}e^{-|x-\mu|/\sigma},　-\infty<x<\infty$

#### ++E(X)++、 ++VAR(X)++

正常情況求出他的$E(X), Var(X)$極度麻煩，所以先做分布轉換:

let $W= \frac{X-\mu}{\sigma}$ , 求出$f(w)$

$F(w)=P(W \le w)=P(\frac{X-\mu}{\sigma}\le w)=P(X \le w \sigma +\mu)$
$=\int_{- \infty}^{w \sigma +\mu} \frac{1}{2\sigma} e^{-|x-\mu|/\sigma}  \,dx$


\begin{array}{rcl}
    f(w) &=& \frac{d }{d w}F(w)=\frac{d }{d w}\int_{- \infty}^{w \sigma +\mu} \frac{1}{2\sigma}e^{-|x-\mu|/\sigma}  \,dx \\
&=&\sigma \frac{1}{2\sigma} e^{-|w \sigma +\mu-\mu|/\sigma} = \frac{1}{2} e^{-|w|}, -\infty<w<\infty
\end{array}


We know $X = \sigma w +\mu$, $X^2 =( \sigma w +\mu)^2$, therefore:  

- $\text{E}(X)= \sigma \text{E}(w) +\mu$

- $\text{E}(X^2)=\sigma^2 \text{E}(W^2) +\sigma \mu \text{E}(W) +\mu ^2$

 Then we need to find $\text{E}(W)$ and $\text{E}(W^2)$:  

 \begin{array}{rcll}
 \text{E}(w) &=& \int_{-\infty}^{\infty} w \frac{1}{2} e^{-|w|}\,dw & \\
             &=&0 & (\because w \frac{1}{2} e^{-|w|} \text{ is a odd function})
 \end{array}


<u>pf</u>

odd function def.:

$f(-y)= - f(y)$

let $f= w \frac{1}{2} e^{-|w|}$ 

$f(-y)= -y\frac{1}{2} e^{-|-y|}=-y\frac{1}{2} e^{-|y|}= f(y)$, 故得證


 \begin{array}{rcll}
 \text{E}(w^2) &=& \int_{-\infty}^{\infty} w^2 \frac{1}{2} e^{-|w|}\,dw & \\
             &=& 2 \int_{0}^{\infty} w^2 \frac{1}{2} e^{-|w|}\,dw & (\because w^2 \frac{1}{2} e^{-|w|} \text{ is a even function})\\
            &=&\int_{0}^{\infty} w^2  e^{-w}\,dw & \\
            &=&\Gamma (3) & (\text{by gamma funciton})\\
            &=&2
\end{array}


<u>pf</u>

even function def.:

$f(-y)= f(y)$

let $f= w^2 \frac{1}{2} e^{-|w|}$ 

$f(-y)= (-y)^2\frac{1}{2} e^{-|-y|}=y^2\frac{1}{2} e^{-|y|}= f(y)$, 故得證



$\text{E}(W)=0$ $\text{E}(W^2)=2$代入:  

- $\text{E}(X)=\sigma \times 0 +\mu=\mu$
- $\text{E}(X^2)=\sigma^2 \text{E}(W^2) +\sigma \mu \text{E}(W) +\mu ^2= 2\sigma^2  +\mu ^2$

$\text{Var}(X)= 2\sigma^2  +\mu ^2 -\mu ^2= 2\sigma^2$

### 常態分布
:::info
這裡打極座標積分
:::
由來: 需要極座標

source: https://chih-sheng-huang821.medium.com/%E7%B5%B1%E8%A8%88%E5%AD%B8-%E5%B8%B8%E6%85%8B%E5%88%86%E4%BD%88%E7%A9%8D%E5%88%86%E7%AD%89%E6%96%BC1-11e0a853c588
1. 簡單版

$\int_{-\infty}^{\infty}e^{x^2}$
$=\sqrt \pi$


$f_x= \frac{1} {\sqrt{2 \pi}\sigma}e^{\frac {-1}{2}\frac{\sum\limits^{n}(x_i- \mu)^2}{\sigma^2}}$

還是要練積分啦嗚嗚嗚，看起來都要用極座標
https://statproofbook.github.io/P/norm-mean.html#:~:text=Proof%3A%20Mean%20of%20the%20normal%20distribution&text=E(X)%3D%CE%BC.,X(x)dx.
期望值跟變異數耳熟能詳，這裡只打$M_x(t)$，過程from 陳鄰安老師的講義:
![](https://hackmd.io/_uploads/SyXbzPzs2.png)



$M_x(t)=e^{\mu t + \frac {\sigma^2 t^2}{2}}$

::: info
處理重點：把e提出來，剩下的東西可積成1
:::



### 卡方分配
> 因隨機變數初始撒下去會呈左峰態的分配，因而使用。
>長期下來(樣本數變多)，卡方分配會變回常態分配。

$X～χ^2(n)=X～Gamma(\alpha = \frac{n}{2},\beta = 2)$

$E(X)=\alpha \beta = \frac{n}{2}\times 2=n$
$Var(X)= \alpha \beta^2 = \frac{n}{2}\times 2^2 = 2n$
$M_x(t)=(\frac{1}{1-\beta t})^\alpha=(\frac{1}{1-2t})^{\frac {n}{2}}$

#### 卡方分配的性質+證明
##### 1. 若 $X～N(0,1)$，則$x^2～\chi^2(1)$
###### <u>pf.</u>: find $x^2$ joint pdf

##### 2. 若$X_1,...X_n  \overset{i.i.d}～N(0,1)$，則$Y=\sum\limits_{i=1}^{n}x_i^2～\chi^2(n)$
###### <u>pf.</u>: $use M_x(t)$
the $M_x(t)$ of 1 chi square  is $(\frac {1}{\lambda - t})^{n/2}$ 
$\prod\limits_{i=1}^{n}(\frac {1}{\lambda - t})^{n/2}$

##### 3. If $X_1～\chi^2(m),　X_2～\chi^2(n)$，則$Y=X_1+X_2～\chi^2(m+n)$
###### <u>pf.</u>:
the $M_x(t)$ of $X_1$ is $(\frac {1}{\lambda - t})^{m/2}$ 
the $M_x(t)$ of $X_2$ is $(\frac {1}{\lambda - t})^{n/2}$ 
依$M_{X+Y}(t)=M_X(t)M_Y(t)$:
$M_{X_1+X_2}(t)=(\frac {1}{\lambda - t})^{m/2}(\frac {1}{\lambda - t})^{n/2}$
$=(\frac {1}{\lambda - t})^{\frac {m+n}{2}}$

##### 4.1 if $X_1...X_n～N(\mu, \sigma^2)$，且$\mu$已知，則:$Y=\frac{\sum (x-\mu)^2}{\sigma^2}～\chi^2(n)$
##### 4.2 if $X_1...X_n～N(\mu, \sigma^2)$，且$\mu$未知，則:$Y=\frac{\sum (x-\bar x)^2}{\sigma^2}～\chi^2(n-1)$


##### 5. $n \frac {(\bar x - \mu)^2}{\sigma^2}～\chi^2(1)$


### Beta分配
::: info 
:information_source: beta function:
$\int_0^1t^{\alpha-1}(1-t)^{\beta -1}dt$
$=\frac {(\alpha -1)!(\beta -1)!}{(\alpha + \beta-1)!}$
$=\frac {Γ(α)Γ(β)}{Γ(α+β)}$
:::


$f_x=\frac {Γ(a+b)}{Γ(a)Γ(b)} x^{a-1}(1-x)^{b-1},　0<x<1$

#### ++E(X)++

\begin{array}{rcll}
\text{E}[X] &=& \frac {\Gamma (\alpha+\beta)}{\Gamma (\alpha)\Gamma(b)}\int_0^1 x^{\alpha} (1-x)^{\beta-1} \, dx &\\
&=&\frac {\Gamma (\alpha+\beta)}{\Gamma (\alpha)\Gamma(b)} \frac {\Gamma (\alpha +1)\Gamma(b)}{\Gamma (a+b+1)}& (\text{by beta function}) \\
&=&\frac{\alpha}{\alpha+\beta} &
\end{array}




#### ++VAR(X)++

\begin{array}{rcll}
    \text{E}[X^2] &=& \frac {\Gamma (\alpha+\beta)}{\Gamma (\alpha)\Gamma(b)}\int_0^1 x^{\alpha+1} (1-x)^{\beta-1} \, dx &\\
&=&\frac {\Gamma (\alpha+\beta)}{\Gamma (\alpha)\Gamma(b)} \frac {\Gamma(a+2)\Gamma(b)}{\Gamma (a+b+2)}& (\text{by beta function}) \\
&=& \frac{\alpha(\alpha +1)}{(\alpha+\beta)(\alpha+\beta+1)} &
\end{array}

$\text{Var}(X) = \frac{\alpha(\alpha +1)}{(\alpha+\beta)(\alpha+\beta+1)} - [\frac{\alpha}{\alpha+\beta}]^2= \frac{\alpha \beta}{(\alpha+\beta)^2 (\alpha+\beta+1)}.$


#### cdf(無聊再練習)
![](https://hackmd.io/_uploads/H1slS88q2.png)


### Weibull distribution
> 從exp轉換過來

$f_Y(y)= \frac{\gamma }{\beta } y^{\gamma -1}e^{-\frac{y^\gamma}{\beta}}$, $y>0, \gamma >0$



#### ++E(X)++



\begin{array}{lllcl}
    \text{E}(Y) &=&\int_{0}^{\infty} y\frac{\gamma }{\beta } y^{\gamma -1}e^{-\frac{y^\gamma}{\beta}} \,dy &u = \frac{y^\gamma}{\beta} , du = \gamma \frac{y^{\gamma -1}}{\beta} dy& y = (u\beta )^{\frac{1}{\beta}} \\
    &=& \int_{0}^{\infty} \frac{\beta }{\gamma }(u\beta )^{\frac{1}{\gamma }}\frac{\gamma}{\beta } e^{-\frac{u}{\beta}} \,du  & &\\
    &=& \int_{0}^{\infty} (u\beta )^{\frac{1 }{\gamma }}e^{u} \,du  & &\\
    &=& \beta^{\frac{1 }{\gamma }}e \int_{0}^{\infty} u^{\frac{1 }{\gamma }}e^{u} \,du  & &\\
    &= &\beta^{\frac{1 }{\gamma }} \Gamma (\frac{1 }{\gamma }+1) & (\text{by gamma function})& 
\end{array}




#### ++VAR(X)++


\begin{array}{lllcl}
    \text{E}(Y^2) &=&\int_{0}^{\infty} y^2\frac{\gamma }{\beta } y^{\gamma -1}e^{-\frac{y^\gamma}{\beta}} \,dy &u = \frac{y^\gamma}{\beta} , du = \gamma \frac{y^{\gamma -1}}{\beta} dy& y = (u\beta )^{\frac{1}{\beta}} \\
    &=& \int_{0}^{\infty} \frac{\beta }{\gamma }(u\beta )^{\frac{1}{\gamma }}\frac{\gamma}{\beta } e^{-\frac{u}{\beta}} \,du  & &\\
    &=& \int_{0}^{\infty} (u\beta )^{\frac{2 }{\gamma }}e^{-u} \,du  & &\\
    &=& \beta^{\frac{2 }{\gamma }}e \int_{0}^{\infty} u^{\frac{2 }{\gamma }}e^{-u} \,du  & &\\
    &=&\beta^{\frac{2 }{\gamma }} \Gamma (\frac{2 }{\gamma }+1) & (\text{by gamma function})& 
\end{array}

\begin{array}{rcl}
\text{Var}(Y)&=& \beta^{\frac{2 }{\gamma }} \Gamma (\frac{2 }{\gamma }+1) - [\beta^{\frac{1 }{\gamma }} \Gamma (\frac{1 }{\gamma }+1)]^2 \\
   &=& \beta^{\frac{2}{\gamma }} \{\Gamma (\frac{2 }{\gamma }+1) -[\Gamma (\frac{1 }{\gamma }+1)]^2 \}
\end{array}



## 分佈關係

### poission and exponentail

#### 基本差異
| 差異/分配名稱 | poission(λ)                        | exponentail(θ)                         |
| ------------- | ---------------------------------- | -------------------------------------- |
| scale meaning | 特定時間內發生多少次事件(=θ的倒數) | 平均每隔多少時間發生1次事件 (=λ的倒數) |
|      舉例： 某月30天發生120次交通意外     |   一天平均有4次交通意外，λ=4                                 |   每$\frac{1}{4}$天發生一次交通意外，$θ=\frac{1}{4}$                                  |

由前可知兩者的scalar有倒數關係，且一為離散，一為連續。因此關係為：
Let $X～Poi(\lambda)$, $Y ～Exp(\theta=\frac{1}{\lambda})$

$P(Y\le y)=P(X\ge 1)$




### gamma and poission
stat.infer DP126
因為Gramma跟Expexponentail有關係，所以跟piossion可以搭上邊，但要除以scalar參數。
Let $X～Poi(\frac{y}{\beta})$, $Y ～Γ(α,β)$

$P(Y\le y)=P(X\ge \alpha)$

**應用: 求piossion小樣本信賴區間**
