跳至主要内容

LRT 的應用

H0:θω0vs.H1:θω1H_0:\theta\in \omega_0\quad\text{vs.}\quad H_1:\theta\in \omega_1 λ(x~)supθω0L(θ;x~)supθωL(θ;x~)[0,1]\lambda(\utilde{x})\triangleq \frac{\sup_{\theta\in\omega_0}L(\theta;\utilde{x})}{\sup_{\theta\in\omega}L(\theta;\utilde{x})}\in[0,1]

LRT reject H0H_0     λ(x~)<k\iff\lambda(\utilde{x})<k

Contingency table's Chi-square test

Note: LRT reject H0H_0     λ(x~)<k    2lnλ(x~)>c\iff\lambda(\utilde{x})<k\iff-2\ln \lambda(\utilde{x})>c

Theorem

As nn\to\infty, 在一些條件下

2lnλ(x~)dχdf2θω0-2\ln\lambda(\utilde{x})\xrightarrow{d}\chi^2_{\text{df}}\quad\forall\theta\in \underbar{$\omega_0$}
  • ω0\underbar{$\omega_0$} : 在 H0H_0 下發生 "==" 的 θ\theta 的集合
  • df = dim(Ω)dim(ω0)\dim(\Omega)-\dim(\underbar{$\omega_0$})dim\dim 指未知參數的數量

    \implies Reject H0    2lnλ(x~)>χdf,α2H_0\iff -2\ln\lambda(\utilde{x})>\chi^2_{\text{df},\alpha}

X~Multinomialn(k,P~)with k=I×J\utilde{X}\sim\text{Multinomial}_n(k,\utilde{P}) \quad\text{with } k= I\times J

我們關心 H0:ABH_0:A\perp B vs. H1:A⊥̸BH_1:A\not\perp B,並且收集到以下數據

A\B12\cdotsj\cdotsJ
1X11X_{11}X12X_{12}\cdotsX1jX_{1j}\cdotsX1JX_{1J}
2X21X_{21}X22X_{22}\cdotsX2jX_{2j}\cdotsX2JX_{2J}
\vdots\vdots\vdots\ddots\vdots\ddots\vdots
iXi1X_{i1}Xi2X_{i2}\cdotsXijX_{ij}\cdotsXiJX_{iJ}
\vdots\vdots\vdots\ddots\vdots\ddots\vdots
IXI1X_{I1}XI2X_{I2}\cdotsXIjX_{Ij}\cdotsXIJX_{IJ}
nn
pij=P(A=i,B=j)=prob of being classified to (i,j) cell\begin{align*} p_{ij}&=P(A=i,B=j)\\ &=\text{prob of being classified to } (i,j) \text{ cell}\\ \end{align*}

i.e. XijB(n,pij)i,j    p^=XijnX_{ij}\sim B(n,p_{ij})\quad\forall i,j\implies\hat{p}=\frac{X_{ij}}{n}

    Ω={p~RI×J:i,jpij[0,1],ijpij=1}    dim(Ω)=I×J1(知道之前的數據,最後一個數據也能知道)\begin{align*} &\implies \Omega=\set{\utilde{p}\in\R^{I\times J}:\forall i,j\quad p_{ij}\in[0,1], \quad\sum_i\sum_j p_{ij}=1}\\ &\implies \dim(\Omega)=I\times J-1\quad\text{(知道之前的數據,最後一個數據也能知道)} \\ \end{align*} H0:AB    pij=pipji,j=P(A=i)P(B=j)=j=1Jpiji=1Ipijpipj\begin{align*} H_0:A\perp B\iff p_{ij}&=p_{i\cdot}p_{\cdot j}\quad\forall i,j\\ &=P(A=i)\cdot P(B=j)\\ &=\sum_{j=1}^J p_{ij}\cdot\sum_{i=1}^I p_{ij}\\ &\triangleq p_i\cdot p_j \end{align*} i.e.ω0=ω0={p~Ω:i,jpij=pipj,i=1Ipi=1,j=1Jpj=1}\text{i.e.}\quad \underbar{$\omega_0$}=\omega_0=\set{\utilde{p}\in\Omega:\forall i,j\quad p_{ij}=p_i\cdot p_j,\quad \sum_{i=1}^I p_i=1,\quad \sum_{j=1}^J p_j=1}     dim(ω0)=I1+J1=I+J2    df=dim(Ω)dim(ω0)=IJ1(I+J2)=(I1)(J1)\begin{align*} &\implies \dim(\omega_0)=I-1+J-1=I+J-2\\ &\implies \text{df}=\dim(\Omega)-\dim(\underbar{$\omega_0$})=IJ-1-(I+J-2)=(I-1)(J-1) \end{align*} Under Ω:pij^Ω=Xijn    (i,j) cell 的 期望值為 npij^Ω\begin{align*} \text{Under } \Omega:&\quad\widehat{p_{ij}}_\Omega=\frac{X_{ij}}{n}\\ &\implies (i,j) \text{ cell 的 期望值為 } n\cdot\widehat{p_{ij}}_\Omega \end{align*} Under ω0:piω0^=Xin,pjω0^=Xjn    pijω0^=piω0^pjω0^    (i,j) cell 的 期望值為 npijω0^=XiXjnEij\begin{align*} \text{Under }\omega_0:&\quad\widehat{p_{i\omega_0}}=\frac{X_i}{n},\quad \widehat{p_{j\omega_0}}=\frac{X_j}{n}\implies \widehat{p_{ij\omega_0}}=\widehat{p_{i\omega_0}}\cdot \widehat{p_{j\omega_0}}\\ &\implies (i,j) \text{ cell 的 期望值為 } n\cdot\widehat{p_{ij\omega_0}} =\frac{X_i\cdot X_j}{n}\triangleq E_{ij} \end{align*} L(p~;X~)=n!X11!XIJ!i=1Ij=1JpijXijL(\utilde{p};\utilde{X})=\frac{n!}{X_{11}!\cdots X_{IJ}!}\prod_{i=1}^I\prod_{j=1}^J p_{ij}^{X_{ij}}     λ(X~)=L(pijω0^;X~)L(pijΩ^;X~)=i,j(XiXjnXijn)Xij=i,j(XiXjXij)Xij\begin{align*} \implies\lambda(\utilde{X})&=\frac{L(\widehat{p_{ij\omega_0}};\utilde{X})}{L(\widehat{p_{ij\Omega}};\utilde{X})}\\ &=\prod_{i,j}\left(\frac{\frac{X_i\cdot X_j}{\cancel{n}}}{\frac{X_ij}{\cancel{n}}}\right)^{X_{ij}}\\ &=\prod_{i,j}\left(\frac{X_i\cdot X_j}{X_{ij}}\right)^{X_{ij}}\\ \end{align*}

更具一些泰勒展開的計算,可以得到以下結論

2lnλ(X~)i=1Ij=1J(XijEij)2Eijχ2with Eij=XiXjn -2\ln\lambda(\utilde{X})\approx \sum_{i=1}^I\sum_{j=1}^J\frac{(X_{ij}-E_{ij})^2}{E_{ij}}\triangleq\chi^2 \quad\text{with } E_{ij}=\frac{X_i\cdot X_j}{n}

    \implies Reject H0H_0 at level α    χ2>χ(I1)(J1),α2\alpha\iff \chi^2>\chi^2_{(I-1)(J-1),\alpha}


EX:對於“全職與兼職對於退休金計劃的選擇”得到以下數據

類型\退休金計劃123
全職16014040340
兼職406060160
200200100500

可以計算 EijE_{ij}

EijE_{ij}123
113613668
2646432
    χ2=(160136)2136+(140136)2136++(3232)232=49.63>5.99=χ(21)(31),0.052\begin{align*} \implies \chi^2&=\frac{(160-136)2}{136}+\frac{(140-136)2}{136}+\cdots+\frac{(32-32)2}{32}\\ &=49.63>5.99=\chi^2_{(2-1)(3-1),0.05} \end{align*}

    H0\implies H_0 is rejected at level 0.05. I.e. 全職與兼職對於退休金計劃的選擇不獨立。


EX:對於“某門課的成績與統計能力”是否有關,得到以下數據

stat. grade\OR gradeABCother
A256171361
B171615654
C184181050
other108112049
70346149214
    χ2=(2519.95)219.95+(69.69)29.69+=25.5>21.67=χ(41)(41),0.012    H0 is rejected at level 0.01.\begin{align*} &\implies \chi^2=\frac{(25-19.95)^2}{19.95}+\frac{(6-9.69)^2}{9.69}+\cdots=25.5>21.67=\chi^2_{(4-1)(4-1),0.01}\\ &\implies H_0 \text{ is rejected at level 0.01.} \end{align*}

I.e. 這門課的成績與統計能力有顯著關係。

Goodness-of-fit test

在分析資料時,我們都會先假設資料符合某種分佈,然後去估計分佈的參數。但我們還需要先檢驗,我們假設的分佈是否適合這些資料。

X~Multinomialn(k,P~)\utilde{X}\sim \text{Multinomial}_n(k,\utilde{P})
12\cdotsktotal
X1P1X_1\mid P_1X2P2X_2\mid P_2\cdotsXkPkX_k\mid P_kn1n\mid 1

given ci[0,1]c_i\in[0,1] and ci=1    H0:Pi=ci,i\sum c_i=1\implies H_0:P_i=c_i, \forall i\quad vs. H1:PiciH_1:P_i\neq c_i for some ii

    Ω={P~:Pi[0,1],Pi=1}dim(Ω)=k1\implies \Omega=\set{\utilde{P}:P_i\in[0,1], \sum P_i=1}\quad\dim(\Omega)=k-1

    ω0={P~:Oi=ci,i}dim(ω0)=0\implies \underbar{$\omega_0$}=\set{\utilde{P}:O_i=c_i, \forall i}\quad \dim(\underbar{$\omega_0$})=0

Ei=nci,iE_i=n\cdot c_i,\forall i

    χ2=i=1k(XiEi)2Eidχk12\implies \chi^2=\sum_{i=1}^k\frac{(X_i-E_i)^2}{E_i}\xrightarrow{d}\chi^2_{k-1}

    \implies Reject H0H_0 at level α    χ2>χk1,α2\alpha\iff \chi^2>\chi^2_{k-1,\alpha}


EX:用一個骰子得到以下數據

123456total
1009410389110104600

H0:H_0: 骰子是公平的     H0:p~=(16,,16)\iff H_0:\utilde{p}=(\frac{1}{6},\cdots,\frac{1}{6})

在 null hypothesis 下,Ei=60016=100E_i=600\cdot\frac{1}{6}=100

    χ2=02+62+32+112+102+42100=2.829.236=χ61,0.12\implies \chi^2=\frac{0^2+6^2+3^2+11^2+10^2+4^2}{100}=2.82\not > 9.236=\chi^2_{6-1,0.1}

    H0\implies H_0 is not rejected at level 0.1. I.e. 沒有足夠證據認為這個骰子不公平。


Y1,YnYY_1\cdots,Y_n\sim YH0:Yf(y;θ)H_0: Y\sim f(y;\theta) vs. H1:Y≁f(y;θ)H_1: Y\not\sim f(y;\theta),其中 θ\theta 可能是未知的。

如果 YY 是連續分佈,我們可以將 fyf_y 分割成 kk 個區間,然後計算數據落在每個區間的數量,從而轉變成 Multinomial 分佈的問題。其中每個區間的幾率可以用積分來計算。

區間I1I_1I2I_2\cdotsIkI_kn
probP1P_1P2P_2\cdotsPkP_k1
數量X1X_1X2X_2\cdotsXkX_kn
Xi=j=1nI(YjIi)Xin=Pθ(YIi)=PiPi=Iif(y;θ)dyX_i=\sum_{j=1}^n I(Y_j\in I_i)\quad\frac{X_i}{n}=P_\theta(Y\in I_i)=P_i\quad P_i=\int_{I_i}f(y;\theta)dy

假設檢定就轉變為 XMultinomialn(k,p~)X\sim \text{Multinomial}_n(k,\utilde{p})

H0:p~=P~ v.s. H1:p~Ω , with Ω={P~:Pi[0,1],Pi=1}H_0:\utilde{p}=\utilde{P} \text{ v.s. } H_1:\utilde{p}\in\Omega \text{ , with }\Omega=\set{\utilde{P}:P_i\in[0,1],\sum P_i=1}     Ei=nP^i=nIif(y;θ^MLE)dy\implies E_i=n\cdot \hat{P}_i=n\int_{I_i}f(y;\hat{\theta}_\text{MLE})dy

    \implies Reject H0H_0 at level α    χ2>χdf,α2\alpha\iff \chi^2>\chi^2_{\text{df},\alpha} with χ2=i=1k(XiEi)2Ei\chi^2=\sum_{i=1}^k\frac{(X_i-E_i)^2}{E_i} and df=dim(Ω)dim(ω0)=k1m\dim(\Omega)-\dim(\underbar{$\omega_0$})=k-1-m,其中 mmθ\theta 的未知參數數量。

e.g.

  • H0:YN(60,100)    χk12H_0: Y\sim N(60,100)\implies \chi^2_{k-1}
  • H0:YN(μ,100)    χk112H_0: Y\sim N(\mu,100)\implies\chi^2_{k-1-1}
  • H0:YN(μ,σ2)    χk122H_0: Y\sim N(\mu,\sigma^2)\implies \chi^2_{k-1-2}
  • H0:YBeta(θ,2)    χ2k11H_0: Y\sim \text{Beta}(\theta,2)\implies \chi^2{k-1-1}
備註

因為 χ2\chi^2\to\infty as Ei0E_i\to 0,如果 EiE_i 足夠接近 0,那麼幾乎可以確定 H0H_0 會被拒絕。並且這個方法是建立在 nn\to\infty 的假設下的,需要足夠多的數據。因此在設置分割數 kk 時,有以下原則:

  • k1m1    km+1k-1-m\ge 1\iff k\ge m+1
  • Ei5E_i\ge 5