跳至主要内容

Methods of finding confidence sets

Inverting tests

Idea: 當我們做假設檢定 H0:θ=θ0H_0:\theta=\theta_0 時,如果我們沒有拒絕 H0H_0,那麼我們可以說這組數據是“支持” θ=θ0\theta=\theta_0 的。因此,我們可以認為 θ0C(X~)\theta_0\in C(\utilde{X})。那麼我們對所有 θ0\theta_0 都作這樣的檢定,如果我們在資料 x~\utilde{x} 下沒有拒絕這個 H0H_0,我們就把這個 θ0\theta_0 放進 C(x~)C(\utilde{x})。這樣我們就得到了一個 confidence set。

EX X1,,XniidU(0,θ)X_1, \cdots, X_n\overset{\text{iid}}{\sim}U(0, \theta)

H0:θ=θ0vs.H1:θθ0H_0:\theta=\theta_0\quad\text{vs.}\quad H_1:\theta\neq\theta_0

    \implies UMP level α\alpha test is rejects H0H_0 if x(n)>θ0x_{(n)}>\theta_0 or x(n)<θ0α1nx_{(n)}<\theta_0\alpha^\frac{1}{n}

    \iff Note rejects H0H_0 if x(n)θ0x_{(n)}\le\theta_0 and x(n)θ0α1nx_{(n)}\ge\theta_0\alpha^\frac{1}{n}

Note.

Pθ0(rej. H0)=αθ0>0    Pθ0(Not rej. H0)=1αθ0>0    Pθ(X(n)θX(n)α1n)=1αθ>0\begin{align*} &P_{\theta_0}(\text{rej. }H_0) = \alpha \quad \forall\theta_0 > 0\\ \iff& P_{\theta_0}(\text{Not rej. }H_0)=1-\alpha \quad \forall\theta_0 > 0\\ \iff& P_{\theta}(X_{(n)}\le\theta\le X_{(n)}\alpha^{-\frac{1}{n}})=1-\alpha \quad \forall\theta > 0 \end{align*}

    [X(n),X(n)α1n]\implies [X_{(n)}, X_{(n)}\alpha^{-\frac{1}{n}}] is a 1α1-\alpha UMA confidence set for θ\theta.

  • 我們可以從 UMP α\alpha test 得到 UMA conf coef 1α1-\alpha 的 confidence set。
Definition

Inverting tests Method:

Let a non-randomized level α\alpha test

ϕ(X~)={1if X~B(θ0)= rejection region0if X~(B(θ0))cA(θ0)= acceptance region\phi(\utilde{X}) = \begin{cases} 1 & \text{if } \utilde{X}\in B(\theta_0)=\text{ rejection region}\\ 0 & \text{if } \utilde{X}\in (B(\theta_0))^c\triangleq A(\theta_0)=\text{ acceptance region} \end{cases}

Def C(X~)C(\utilde{X}) with X~A(θ0)    θ0C(X~)\utilde{X}\in A(\theta_0)\iff\theta_0\in C(\utilde{X}), then

θ0Pθ0(θ0C(X~))=Pθ0(X~A(θ0))=1Pθ0(X~B(θ0))=1α\begin{align*} \forall\theta_0\quad P_{\theta_0}(\theta_0\in C(\utilde{X})) &= P_{\theta_0}(\utilde{X}\in A(\theta_0))\\ &=1-P_{\theta_0}(\utilde{X}\in B(\theta_0))\\ &=1-\alpha \end{align*}

i.e. θPθ(θC(X~))=1α    C(X~)\forall\theta P_\theta(\theta\in C(\utilde{X}))=1-\alpha\implies C(\utilde{X}) is a 1α1-\alpha confidence set for θ\theta.

In fact, θ0C(X~)    X~A(θ0)\theta_0\in C(\utilde{X})\iff\utilde{X}\in A(\theta_0)。因此我們可以通過檢定的結果來得到 confidence set,也可以通過 confidence set 來得到檢定的結果。

也就是說,there is Duality(一體兩面) relationship between confidence sets and hypothesis tests. 它們問的是同一個問題,只是從不同的角度來看。假設檢定是給定 θ\theta,看數據是否支持這個 θ\theta;而 confidence set 是給定數據,看這個數據支持哪些 θ\theta

因此我們可以利用已知結果的檢定來得到 confidence set,並且

  • UMP     \implies UMA
  • UMPU     \implies UMAU

EX X1,,XniidU(0,θ)X_1,\cdots, X_n\overset{\text{iid}}{\sim}U(0, \theta). Find UMAU 1α1-\alpha conf lower bound for θ\theta (θL(X~)\theta\ge L(\utilde{X})).

    \implies UMP level α\alpha test for H0:θθ0H_0:\theta\le\theta_0 vs. H1:θ>θ0H_1:\theta>\theta_0 is rejects H0H_0 if x(n)θ0x_{(n)}\le\theta_0

i.e. Not reject H0H_0 if x(n)θ0(1α)1nx_{(n)}\le\theta_0(1-\alpha)^{\frac{1}{n}}

i.e. {x~:x(n)(1α)1nθ0}=A(θ0)\set{\utilde{x}:x_{(n)}(1-\alpha)^{-\frac{1}{n}}\le\theta_0}=A(\theta_0)

    C(X~)={θ0:X~A(θ0)}={θ0:θ0Xn(1α)1n}=[X(n)(1α)1n,)\implies C(\utilde{X})=\set{\theta_0:\utilde{X}\in A(\theta_0)}=\set{\theta_0:\theta_0\ge X_{n}(1-\alpha)^{-\frac{1}{n}}}=[X_{(n)}(1-\alpha)^{-\frac{1}{n}}, \infty)

is UMA(hence UMAU) 1α1-\alpha confidence set for θ\theta.

如果我們關注的是 upper bound,那麼我們同樣做鑒定,得到 reject H0H_0 if x(n)<θ0α1nx_{(n)}<\theta_0\alpha^{\frac{1}{n}}。而他的接受區域是 {x~:x(n)θ0α1n}\set{\utilde{x}:x_{(n)}\ge\theta_0\alpha^{\frac{1}{n}}}。因此我們可以得到 UMAU 1α1-\alpha confidence set for θ\theta is (,X(n)α1n](-\infty, X_{(n)}\alpha^{-\frac{1}{n}}]


EX

<X1,,XniidN(μ,σ2)Y1,,YmiidN(μ,σ2)\perp \Big< \begin{align*} &X_1, \cdots, X_n\overset{\text{iid}}{\sim}N(\mu, \sigma^2)\\ &Y_1, \cdots, Y_m\overset{\text{iid}}{\sim}N(\mu, \sigma^2) \end{align*}

C(X~,Y~)={λ:λL(X~,Y~)}C(\utilde{X}, \utilde{Y})=\set{\lambda:\lambda\ge L(\utilde{X}, \utilde{Y})} with θ=(μx,μy,σx2,σy2)\theta=(\mu_x, \mu_y, \sigma^2_x, \sigma^2_y)

    \implies UMAU lower bound 1α1-\alpha for λ=σx2σy2\lambda=\frac{\sigma^2_x}{\sigma^2_y}

    \implies UMPU level α\alpha for

H0:σx2σy2=λ=λ0vs.H1:σx2σy2=λ>λ0H_0:\frac{\sigma^2_x}{\sigma^2_y}=\lambda=\lambda_0\quad\text{vs.}\quad H_1:\frac{\sigma^2_x}{\sigma^2_y}=\lambda>\lambda_0

rejects H0H_0 if Sx2/σx2Sy2/σy2>Fn1,m1(α)    Sx2SY2>λ0Fn1,m1(α)\frac{S^2_x/\sigma^2_x}{S^2_y/\sigma^2_y}>F_{n-1, m-1}(\alpha)\iff \frac{S^2_x}{S^2_Y}>\lambda_0F_{n-1, m-1}(\alpha) where λ0=H0σx2σy2\lambda_0\overset{H_0}{=}\frac{\sigma^2_x}{\sigma^2_y}

i.e. Not reject H0H_0 if Sx2Sy2λ0Fn1,m1(α)    λC(X~,Y~)={λ:λSX2SY2Fn1,m1,α1}\frac{S^2_x}{S^2_y}\le\lambda_0F_{n-1, m-1}(\alpha)\implies\lambda\in C(\utilde{X}, \utilde{Y})=\set{\lambda:\lambda\le\frac{S^2_X}{S^2_Y}F_{n-1,m-1,\alpha}^{-1}}

i.e. [SX2SY21Fn1,m1,α,)[\frac{S^2_X}{S^2_Y}\frac{1}{F_{n-1,m-1,\alpha}},\infty) is 1α1-\alpha UMAU lower bound for λ=σx2σy2\lambda=\frac{\sigma^2_x}{\sigma^2_y}.

Pivot

Definition

A r.v. K(X~;θ)K(\utilde{X};\theta) is called a pivot     K(X~;θ)\iff K(\utilde{X};\theta) 's dist θ\perp\theta

EX X1,,XniidN(μ,σ2)X_1,\cdots, X_n\overset{\text{iid}}{\sim}N(\mu, \sigma^2),

n(Xˉμ)σN(0,1)μ,σ2\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\sim N(0, 1) \perp \mu, \sigma^2

If K(X~,θ)K(\utilde{X},\theta) is a pivot, then \forall set BB, P(K(X~,θ)B)θP(K(\utilde{X},\theta)\in B)\perp\theta

    \implies Given α(0,1),Bα\alpha\in(0, 1), \exist B_\alpha s.t. P(K(X~,θ)Bα)=1αP(K(\utilde{X},\theta)\in B_\alpha)=1-\alpha. i.e. infθP(KBα)=1α\inf_\theta P(K\in B_\alpha)=1-\alpha

Definition
C(X~)={θ:K(X~,θ)Bα}C(\utilde{X})=\set{\theta:K(\utilde{X},\theta)\in B_\alpha}

we have

θPθ(θC(X~))=P(K(X~,θ)Bα)=1α\forall\theta\quad P_\theta(\theta\in C(\utilde{X}))=P(K(\utilde{X},\theta)\in B_\alpha)=1-\alpha

    infθPθ(θC(X~))=1α\implies \inf_\theta P_\theta(\theta\in C(\utilde{X}))=1-\alpha, i.e. C(X~)C(\utilde{X}) is a 1α1-\alpha confidence set for θ\theta.

EX X1,,XniidN(μ,σ02)X_1,\cdots, X_n\overset{\text{iid}}{\sim}N(\mu, \sigma^2_0) with σ02\sigma^2_0 known. Given α(0,1)\alpha\in(0, 1), find 1α1-\alpha confidence set for μ\mu.

    n(Xˉμ)σ0N(0,1)μ\implies \frac{\sqrt{n}(\bar{X}-\mu)}{\sigma_0}\sim N(0, 1)\perp\mu

Let Bα=[Zα1,Zα2]B_\alpha=[-Z_{\alpha_1}, Z_{\alpha_2}] with α1+α2=α    P(n(Xˉμ)σ0Bα)=1α\alpha_1+\alpha_2=\alpha\implies P\left(\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma_0}\in B_\alpha\right)=1-\alpha

C(X~)={μ:Zα1n(Xˉμ)σ0Zα2}={μ:Xˉσ0Zα1nμXˉ+σ0Zα2n}=[Xˉσ0Zα1n,Xˉ+σ0Zα2n]\begin{align*} C(\utilde{X})&=\set{\mu:-Z_{\alpha_1}\le\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma_0}\le Z_{\alpha_2}}\\ &=\set{\mu:\bar{X}-\frac{\sigma_0Z_{\alpha_1}}{\sqrt{n}}\le\mu\le\bar{X}+\frac{\sigma_0Z_{\alpha_2}}{\sqrt{n}}}\\ &=\left[\bar{X}-\frac{\sigma_0Z_{\alpha_1}}{\sqrt{n}}, \bar{X}+\frac{\sigma_0Z_{\alpha_2}}{\sqrt{n}}\right] \end{align*}

所有 α1+α2=α\alpha_1+\alpha_2=\alpha 構建的 confidence set 都是 1α1-\alpha confidence set,但我們希望找到最好的 confidence set,也就是找到長度最短的 confidence set。

C(X~)C(\utilde{X}) 的長度 =σ0n(Zα2Zα1)=\frac{\sigma_0}{\sqrt{n}}(Z_{\alpha_2}-Z_{\alpha_1})。為了使它最短,並且保證 P(Zα1ZZα2)=1αP(Z_{\alpha_1}\le Z\le Z_{\alpha_2})=1-\alpha

    \iff min (Zα2Zα1)(Z_{\alpha_2}-Z_{\alpha_1}) s.t. Φ(Zα2)Φ(Zα1)=1α\Phi(Z_{\alpha_2})-\Phi(Z_{\alpha_1})=1-\alpha

我們可以使用 Largrange multiplier method 來求解這個問題。如果我們要使 h(a,b)h(a,b) 最小(或最大)並保證限製函數 g(a,b)=kg(a,b)=k,即找到 a,ba,b 使得

h(a,b)=λg(a,b)and g(a,b)=k\nabla h(a,b)=\lambda\nabla g(a,b)\quad \text{and } g(a,b)=k

這裡 h(a,b)=ba,g(a,b)=Φ(b)Φ(a),k=1αh(a,b)=b-a, g(a,b)=\Phi(b)-\Phi(a), k=1-\alpha

{a(ba)=λaΦ(a)b(ba)=λbΦ(b)Φ(b)Φ(a)=1α    {1=λϕ(a)1=λϕ(b)Φ(b)Φ(a)=1α\begin{cases} \frac{\partial}{\partial a}(b-a)=\lambda\frac{\partial}{\partial a}\Phi(a)\\ \frac{\partial}{\partial b}(b-a)=\lambda\frac{\partial}{\partial b}\Phi(b)\\ \Phi(b)-\Phi(a)=1-\alpha \end{cases}\implies\begin{cases} -1=-\lambda\phi(a)\\ 1=\lambda\phi(b)\\ \Phi(b)-\Phi(a)=1-\alpha \end{cases}     ϕ(a)=ϕ(b) and Φ(b)Φ(a)=1α    a=b\implies \phi(a)=\phi(b) \text{ and } \Phi(b)-\Phi(a)=1-\alpha \implies a=-b

i.e. Zα1=Zα2,Zα2=Z1α2    Z_{\alpha_1}=Z_{\frac{\alpha}{2}}, Z_{\alpha_2}=Z_{1-\frac{\alpha}{2}}\implies the best confidence set for μ\mu is [Xˉ±σ0nZα2]\left[\bar{X}\pm \frac{\sigma_0}{\sqrt{n}}Z_{\frac{\alpha}{2}}\right] with length 2σ0nZα2\frac{2\sigma_0}{\sqrt{n}}Z_{\frac{\alpha}{2}}

同樣,我們也可以用 X1μσ0\frac{X_1-\mu}{\sigma_0} 作為 pivot 來得到 confidence set [X1±σ0Zα2]\left[X_1\pm\sigma_0Z_{\frac{\alpha}{2}}\right],而長度為 2σ0Zα22\sigma_0Z_{\frac{\alpha}{2}}

比較兩個 confidence set 的長度,我們可以發現 Xˉ\bar{X} 的 confidence set 的長度比 X1X_1 的 confidence set 的長度要短。因此我們會選擇基於 Xˉ\bar{X} 的 confidence set。

Remark: 我們會使用基於 sufficient statistics 的 pivot 來構建 confidence set。

Note

  1. X1,,Xniidf(x;θ)=f(xθ)X_1, \cdots, X_n\overset{\text{iid}}{\sim}f(x;\theta)=f(x-\theta) called location family

    Let Yi=Xiθ    Xi=Yi+θY_i=X_i-\theta\iff X_i=Y_i+\theta

        fYi(y)=fXi(y+θ)ddy(y+θ)=f(y+θθ)=f(y)θ \implies f_{Y_i}(y)=f_{X_i}(y+\theta)\cdot |\frac{d}{dy}(y+\theta)|=f(y+\theta-\theta)=f(y) \perp \theta

        Y1,,Yniidf(y)\implies Y_1,\cdots,Y_n\overset{\text{iid}}{\sim} f(y) are pivots     h,h(Y1,,Yn)\implies\forall h, h(Y_1,\cdots, Y_n) are also pivots

  2. X1,,Xniidf(x;σ)=1σf(xσ)X_1, \cdots, X_n\overset{\text{iid}}{\sim}f(x;\sigma)=\frac{1}{\sigma}f(\frac{x}{\sigma}) called scale family

    Let Yi=Xiσ    Xi=YiσY_i=\frac{X_i}{\sigma}\iff X_i=Y_i\sigma

        fYi(y)=fXi(yσ)ddy(yσ)=1σf(yσσ)σ=f(y)σ\implies f_{Y_i}(y)=f_{X_i}(y\sigma)\cdot |\frac{d}{dy}(y\sigma)|=\frac{1}{\sigma}f(\frac{y\sigma}{\sigma})\cdot\sigma=f(y)\perp\sigma

        Y1,,Yniidf(y)\implies Y_1,\cdots,Y_n\overset{\text{iid}}{\sim}f(y) are pivots     h,h(Y1,,Yn)\implies\forall h, h(Y_1,\cdots, Y_n) are also pivots

  3. X1,,Xniidf(x;θ,σ)=1σf(xθσ)X_1, \cdots, X_n\overset{\text{iid}}{\sim}f(x;\theta, \sigma)=\frac{1}{\sigma}f(\frac{x-\theta}{\sigma}) called location-scale family

    Let Yi=Xiθσ    Xi=Yiσ+θY_i=\frac{X_i-\theta}{\sigma}\iff X_i=Y_i\sigma+\theta

    similar Y1,,Yniidf(y)Y_1,\cdots,Y_n\overset{\text{iid}}{\sim}f(y) are pivots     h,h(Y1,,Yn)\implies\forall h, h(Y_1,\cdots, Y_n) are also pivots


EX X1,,XniidN(μ,σ2)X_1, \cdots, X_n\overset{\text{iid}}{\sim}N(\mu, \sigma^2)

12πσe12σ2(xμ)2=1σϕ(xμσ) is a location-scale family\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{1}{2\sigma^2}(x-\mu)^2}=\frac{1}{\sigma}\phi(\frac{x-\mu}{\sigma}) \text{ is a location-scale family}

Note: (Xˉ,S2)(\bar{X},S^2) is complete sufficient for (μ,σ2)(\mu, \sigma^2)

對於 θ\theta 的信賴區間,我們用 n(Xˉθ)Stn1(θ,σ2)\frac{\sqrt{n}(\bar{X}-\theta)}{S}\sim t_{n-1}\perp (\theta, \sigma^2) 作為 pivot

a<b\forall a<b s.t.

1α=P(atn1b)=Pθ,σ2(an(Xˉθ)Sb)=Pθ,σ2(aSn(Xˉθ)bS)=Pθ,σ2(XˉbSnθXˉaSn)=Pθ,σ2(θCa,b(X~))\begin{align*} 1-\alpha&=P(a\le t_{n-1}\le b)\\ &=P_{\theta,\sigma^2}(a\le\frac{\sqrt{n}(\bar{X}-\theta)}{S}\le b)\\ &=P_{\theta,\sigma^2}(aS\le\sqrt{n}(\bar{X}-\theta)\le bS)\\ &=P_{\theta,\sigma^2}(\bar{X}-\frac{bS}{\sqrt{n}}\le\theta\le\bar{X}-\frac{aS}{\sqrt{n}})\\ &=P_{\theta,\sigma^2}(\theta\in C_{a,b}(\utilde{X}))\\ \end{align*}

with Ca,b(X~,S2)=[XˉbSn,Xˉ+aSn]C_{a,b}(\utilde{X},S^2)=[\bar{X}-\frac{bS}{\sqrt{n}}, \bar{X}+\frac{aS}{\sqrt{n}}] are 1α1-\alpha conf. int. for θ\theta.

To min (ba)(b-a) s.t. a<ba<b and G(b)G(a)=1αG(b)-G(a)=1-\alpha with GG: cdf of tn1t_{n-1}

{1=λ(g(a))1=λg(b)G(b)G(a)=1α    a=b=tn1,α2\begin{cases} -1=\lambda(-g(a))\\ 1=\lambda g(b)\\ G(b)-G(a)=1-\alpha \end{cases} \implies a=-b=t_{n-1,\frac{\alpha}{2}}

如果用 C(Xˉ,S2)=[XˉSntn1,Xˉ+Sntn1]C^*(\bar{X}, S^2)=[\bar{X}-\frac{S}{\sqrt{n}}t_{n-1}, \bar{X}+\frac{S}{\sqrt{n}}t_{n-1}] 做假設檢驗

H0:θ=θ0vs.H1:θθ0H_0:\theta=\theta_0\quad\text{vs.}\quad H_1:\theta\neq\theta_0

    \implies reject H0    θ0C(Xˉ,S2)    n(Xˉθ0)S>tn1,α2H_0\iff\theta_0\notin C^*(\bar{X}, S^2)\iff \left|\frac{\sqrt{n}(\bar{X}-\theta_0)}{S}\right|>t_{n-1,\frac{\alpha}{2}} is UMPU level α\alpha test for θ\theta.

    [Xˉ±Sntn1,α2]\implies [\bar{X}\pm \frac{S}{\sqrt{n}}t_{n-1,\frac{\alpha}{2}}] is 1α1-\alpha UMAU for θ\theta.

σ2\sigma^2 的信賴區間,我們會用 S2σ2\frac{S^2}{\sigma^2} 作為 pivot。因為 (n1)S2σ2χn12(θ,σ2)    0a<b\frac{(n-1)S^2}{\sigma^2}\sim \chi^2_{n-1}\perp(\theta, \sigma^2)\implies \forall 0\le a<b s.t.

1α=P(aχn12b)=Pθ,σ2(a(n1)S2σ2b)θ,σ2=Pθ,σ2((n1)S2bσ2(n1)S2a)=Pθ,σ2(σ2Ca,b(X~))\begin{align*} 1-\alpha&=P(a\le\chi^2_{n-1}\le b)\\ &=P_{\theta,\sigma^2}(a\le\frac{(n-1)S^2}{\sigma^2}\le b) \quad\forall\theta, \sigma^2\\ &=P_{\theta,\sigma^2}\left(\frac{(n-1)S^2}{b}\le\sigma^2\le\frac{(n-1)S^2}{a}\right)\\ &=P_{\theta,\sigma^2}(\sigma^2\in C_{a,b}(\utilde{X}))\\ \end{align*}

with Ca,b(X~,S2)=[(n1)S2b,(n1)S2a]C_{a,b}(\utilde{X}, S^2)=\left[\frac{(n-1)S^2}{b}, \frac{(n-1)S^2}{a}\right] are 1α1-\alpha conf. int. for σ2\sigma^2. (Note: χ2\chi^2 不是對稱的)

  1. a=0,b=χn1,α2    Ca,b(S2)=[(n1)S2χn1,α2,]a=0, b=\chi^2_{n-1,\alpha}\implies C_{a,b}(S^2)=\left[\frac{(n-1)S^2}{\chi^2_{n-1,\alpha}}, \infty\right] is 1α1-\alpha UMAU lower conf. bound for σ2\sigma^2.

  2. a=χn1,1α2,b=    Ca,b(S2)=(0,(n1)S2χn1,1α2]a=\chi^2_{n-1,1-\alpha}, b=\infty\implies C_{a,b}(S^2)=\left(0, \frac{(n-1)S^2}{\chi^2_{n-1,1-\alpha}}\right] is 1α1-\alpha UMAU upper conf. bound for σ2\sigma^2.

  3. Usually, used a=χn1,α22,b=χn1,1α22    Ca,b(S2)=[(n1)S2χn1,1α22,(n1)S2χn1,α22]a=\chi^2_{n-1,\frac{\alpha}{2}}, b=\chi^2_{n-1,1-\frac{\alpha}{2}}\implies C_{a,b}(S^2)=\left[\frac{(n-1)S^2}{\chi^2_{n-1,1-\frac{\alpha}{2}}}, \frac{(n-1)S^2}{\chi^2_{n-1,\frac{\alpha}{2}}}\right] for σ2\sigma^2.'

        \implies LRT, equal-tailed test for H0:σ2=σ02H_0:\sigma^2=\sigma^2_0 vs. H1:σ2σ02H_1:\sigma^2\neq\sigma^2_0 (not UMAU)

但對於最佳的 Ca,b(S2)C_{a,b}(S^2),我們同樣要使用 Largrange multiplier method 來解:min (1a1b)(\frac{1}{a}-\frac{1}{b}) s.t. G(b)G(a)=1αG(b)-G(a)=1-\alpha with GG: cdf of χn12\chi^2_{n-1}

    {1a2=λ(g(a))1b2=λg(b)G(b)G(a)=1α    {a2g(a)=b2g(b)G(b)G(a)=1α\implies\begin{cases} -\frac{1}{a^2}=\lambda(-g(a))\\ \frac{1}{b^2}=\lambda g(b)\\ G(b)-G(a)=1-\alpha \end{cases}\implies \begin{cases} a^2g(a)=b^2g(b)\\ G(b)-G(a)=1-\alpha \end{cases}

解出來的 a,ba, b 就就能得到 UMAU confidence set。但它只能用電腦得到數值解。

上面找的都是 σ2\sigma^2 的信賴區間,而對於 σ=σ2\sigma=\sqrt{\sigma^2}

1α=P(Aσ2B)=P(AσB)    1α=Pθ(θC(X~))=Pθ(h(θ)h(C(X~)))\begin{align*} 1-\alpha&=P(A\le\sigma^2\le B)\\ &=P(\sqrt{A}\le\sigma\le\sqrt{B})\\ \end{align*}\implies \begin{align*} 1-\alpha&=P_\theta(\theta\in C(\utilde{X}))\\ &=P_\theta(h(\theta)\in h(C(\utilde{X})))\\ \end{align*}

EX X1,,Xniide(xθ)X_1,\cdots, X_n\overset{\text{iid}}{\sim}e^{-(x-\theta)} with xθx\ge\theta is a location family     X(1)\implies X_{(1)} is suff for θ\theta。因此我們用 X(1)θX_{(1)}-\theta 構建 pivot。

Y=2n(X(1)θ)12ey2,y>0=dGamma(1,2)=dχ22θY=2n(X_{(1)}-\theta)\sim \frac{1}{2}e^{-\frac{y}{2}}, y>0\overset{d}{=}\text{Gamma}(1,2)\overset{d}{=}\chi^2_2\perp\theta

    0a<b\implies \forall 0\le a<b s.t.

1α=ab12ey2dy=P(aYb)=Pθ(a2n(X(1)θ)b)=Pθ(X(1)b2nθX(1)a2n)=Pθ(θCa,b(X(1)))\begin{align*} 1-\alpha&=\int_a^b\frac{1}{2}e^{-\frac{y}{2}}dy\\ &=P(a\le Y\le b)\\ &=P_{\theta}(a\le 2n(X_{(1)}-\theta)\le b)\\ &=P_{\theta}\left(X_{(1)}-\frac{b}{2n}\le\theta\le X_{(1)}-\frac{a}{2n}\right)\\ &=P_{\theta}\left(\theta\in C_{a,b}(X_{(1)})\right)\\ \end{align*}

with Ca,b(X(1))=[X(1)b2n,X(1)a2n]C_{a,b}(X_{(1)})=\left[X_{(1)}-\frac{b}{2n}, X_{(1)}-\frac{a}{2n}\right] are 1α1-\alpha conf. int. for θ\theta.

為了找到最短的 confidence set,我們要找到最小的 bab-a s.t. G(b)G(a)=1αG(b)-G(a)=1-\alpha with GG: cdf of χ22\chi^2_2

{1=λ(g(a))1=λg(b)G(b)G(a)=1α    g(a)=g(b)    a=b\begin{cases} -1=\lambda(-g(a))\\ 1=\lambda g(b)\\ G(b)-G(a)=1-\alpha \end{cases}\implies g(a)=g(b)\implies a=-b

但注意到 g(y)=12ey2g(y)=\frac{1}{2}e^{-\frac{y}{2}} 是單調遞減的。我們不可能在一個絕對遞減的函數中,得到兩個函數值相同但自變量不同的點。因此最小值發身在邊界點上,即 a=0,b=χ2,α2a=0, b=\chi^2_{2,\alpha}

0b12ey2dy=1α    1eb2=1α    b=2log(1α)\int_0^b \frac{1}{2}e^{-\frac{y}{2}}dy=1-\alpha\implies 1-e^{-\frac{b}{2}}=1-\alpha\implies b=-2\log(1-\alpha)

i.e. [X(1)+2log(1α)2n,X(1)][X_{(1)}+\frac{2\log(1-\alpha)}{2n}, X_{(1)}] is 1α1-\alpha conf. int. for θ\theta. 並且對於假設檢定 H0:θ=θ0H_0:\theta=\theta_0 vs. H1:θθ0H_1:\theta\neq\theta_0,我們會

reject H0    θ0Ca,b(X(1))    θ0<X(1)a2n or θ0>X(1)b2n\text{reject } H_0\iff\theta_0\notin C_{a,b}(X_{(1)})\iff \theta_0<X_{(1)}-\frac{a}{2n} \text{ or } \theta_0>X_{(1)}-\frac{b}{2n}

事實上這個檢定是 UMP,因此這個信賴區間是 UMA

危險

信賴區間的長度最短並不代表是 UMA 或 UMAU 的。

要說明一個信賴區間是 UMA 或 UMAU 的,我們需要通過檢定的結果來說明。

EX X1,,XniidU(0,θ)X_1, \cdots, X_n\overset{\text{iid}}{\sim}U(0, \theta). i.e. f(x;θ)=1θI(0xθ1)f(x;\theta)=\frac{1}{\theta}\cdot I(0\le\frac{x}{\theta}\le 1)

T=X(n)T=X_{(n)} is suff for θ    \theta\implies use W=X(n)θ[0,1]W=\frac{X_{(n)}}{\theta}\in[0,1] as pivot. Let 0a<b10\le a<b\le 1 s.t.

1α=P(aWb)=Pθ(aX(n)θb)=Pθ(aθX(n)bθ)=(bθθ)n(aθθ)n=bnan=Pθ(X(n)bθX(n)a)\begin{align*} 1-\alpha&=P(a\le W\le b)\\ &=P_\theta(a\le\frac{X_{(n)}}{\theta}\le b)\\ &=P_\theta(a\theta\le X_{(n)}\le b\theta)=\left(\frac{b\theta}{\theta}\right)^n-\left(\frac{a\theta}{\theta}\right)^n=b^n-a^n\\ &=P_\theta\left(\frac{X_{(n)}}{b}\le\theta\le\frac{X_{(n)}}{a}\right)\\ \end{align*}

Let Ca,b(X(n))=[X(n)b,X(n)a]    0a<b1C_{a,b}(X_{(n)})=[\frac{X_{(n)}}{b}, \frac{X_{(n)}}{a}]\implies \forall 0\le a<b\le 1 with bnan=1αb^n-a^n=1-\alpha, Ca,b(X(n))C_{a,b}(X_{(n)}) are 1α1-\alpha conf. int. for θ\theta.

接下來,為了得到最短的信賴區間,我們要最小化 1a1b\frac{1}{a}-\frac{1}{b} s.t. bnan=1αb^n-a^n=1-\alpha。而此時 Lagrange multiplier method 就不適用了。

bnan=1α    a=a(b)\because b^n-a^n=1-\alpha\implies a = a(b), let l(b)=1a(b)1bl(b)=\frac{1}{a(b)}-\frac{1}{b}

nbn1nan1a(b)=0a(b)=bn1an1    l(b)=a(b)a2+1b2=1a2bn1an1+1b2=an+1bn+1an+1b2<0\begin{align*} n\cdot b^{n-1}-n\cdot a^{n-1}\cdot a'(b)&=0\\ a'(b)&=\frac{b^{n-1}}{a^{n-1}}\\ \end{align*} \implies \begin{align*} l'(b)&=-\frac{a'(b)}{a^2}+\frac{1}{b^2}=-\frac{1}{a^2}\frac{b^{n-1}}{a^{n-1}}+\frac{1}{b^2}\\ &=\frac{a^{n+1}-b^{n+1}}{a^{n+1}b^2}<0 \end{align*}

    l(b)\implies l(b) \searrow in b1    l(b)b\le 1\implies l(b) is min when b=1    a=α1nb=1\implies a=\alpha^{\frac{1}{n}}. I.e, the shortest one is [X(n),X(n)α1n][X_{(n)}, X_{(n)}\alpha^{-\frac{1}{n}}].

For testing H0:θ=θ0H_0:\theta=\theta_0 vs. H1:θθ0H_1:\theta\neq\theta_0

    reject H0    θ0[X(n),X(n)α1n]    θ0<X(n) or θ0>X(n)α1n    X(n)>θ0 or X(n)<θ0α1n is UMP level α test\begin{align*} \implies\text{reject }H_0 &\iff \theta_0\notin [X_{(n)}, X_{(n)}\alpha^{-\frac{1}{n}}]\\ &\iff \theta_0<X_{(n)}\text{ or }\theta_0>X_{(n)}\alpha^{-\frac{1}{n}}\\ &\iff X_{(n)} > \theta_0 \text{ or } X_{(n)} < \theta_0\alpha^{\frac{1}{n}}\\ &\text{ is UMP level }\alpha\text{ test} \end{align*}

    [X(n),X(n)α1n]\implies [X_{(n)}, X_{(n)}\alpha^{-\frac{1}{n}}] is UMA 1α1-\alpha confidence set for θ\theta.


EX X1,,Xniid1λexλX_1, \cdots, X_n\overset{\text{iid}}{\sim}\frac{1}{\lambda}e^{-\frac{x}{\lambda}}\in scale family and Xi\sum X_i is suff for λ\lambda

Note that

i=1nXiGamma(n,λ)    2XiλGamma(n,2)=χ2n2λ\sum_{i=1}^n X_i \sim \text{Gamma}(n, \lambda)\implies \frac{2\sum X_i}{\lambda}\sim\text{Gamma}(n, 2)=\chi^2_{2n}\perp\lambda

    \implies Use 2Xiλχ2n2\frac{2\sum X_i}{\lambda}\sim \chi^2_{2n} as pivot.

    1α=Pλ(χ2n,1α222Xiλχ2n,α22)=Pλ(2Xiχ2n,α22λ2Xiχ2n,1α22)\begin{align*} \implies 1-\alpha&=P_\lambda(\chi^2_{2n, 1-\frac{\alpha}{2}}\le\frac{2\sum X_i}{\lambda}\le\chi^2_{2n, \frac{\alpha}{2}})\\ &=P_\lambda\left(\frac{2\sum X_i}{\chi^2_{2n,\frac{\alpha}{2}}}\le\lambda\le\frac{2\sum X_i}{\chi^2_{2n, 1-\frac{\alpha}{2}}}\right)\\ \end{align*}

    [2Xiχ2n,1α22,2Xiχ2n,α22]\implies \left[\frac{2\sum X_i}{\chi^2_{2n, 1-\frac{\alpha}{2}}}, \frac{2\sum X_i}{\chi^2_{2n, \frac{\alpha}{2}}}\right] is 1α1-\alpha conf. int. for λ\lambda.


EX

<X1,,Xniid1λexλ,x>0Y1,,Ymiid1θeyθ,y>0    <2Xiλχ2n2λ2Yiθχ2m2θ\perp\Big<\begin{align*} &X_1, \cdots, X_n\overset{\text{iid}}{\sim}\frac{1}{\lambda}e^{-\frac{x}{\lambda}}, x>0\\ &Y_1, \cdots, Y_m\overset{\text{iid}}{\sim}\frac{1}{\theta}e^{-\frac{y}{\theta}}, y>0 \end{align*} \quad\implies\quad \perp\Big<\begin{align*} &\frac{2\sum X_i}{\lambda}\sim\chi^2_{2n}\perp\lambda\\ &\frac{2\sum Y_i}{\theta}\sim\chi^2_{2m}\perp\theta \end{align*} 2Xiλ(2n)/2Yiθ(2m)F2n,2m=Xˉλ/Yˉθ=XˉYˉθλ\begin{align*} &\frac{2\sum X_i}{\lambda(2n)}\Bigg/\frac{2\sum Y_i}{\theta(2m)}\sim F_{2n, 2m}\\ =&\frac{\bar{X}}{\lambda}\bigg/\frac{\bar{Y}}{\theta}=\frac{\bar{X}}{\bar{Y}}\frac{\theta}{\lambda} \end{align*} 1α=P(F2n,2m,1α2F2n,2mF2n,2m,α2)=Pθ,λ(F2n,2m,1α2XˉYˉθλF2n,2m,α2)=Pθ,λ(YˉXˉF2n,2m,1α2θλYˉXˉF2n,2m,α2)\begin{align*} 1-\alpha&=P(F_{2n,2m,1-\frac{\alpha}{2}}\le F_{2n,2m}\le F_{2n,2m,\frac{\alpha}{2}})\\ &=P_{\theta,\lambda}\left(F_{2n,2m,1-\frac{\alpha}{2}}\le\frac{\bar{X}}{\bar{Y}}\frac{\theta}{\lambda}\le F_{2n,2m,\frac{\alpha}{2}}\right)\\ &=P_{\theta,\lambda}\left(\frac{\bar{Y}}{\bar{X}}F_{2n,2m,1-\frac{\alpha}{2}}\le\frac{\theta}{\lambda}\le\frac{\bar{Y}}{\bar{X}}F_{2n,2m,\frac{\alpha}{2}}\right)\\ \end{align*}

    [YˉXˉF2n,2m,1α2,YˉXˉF2n,2m,α2]\implies \left[\frac{\bar{Y}}{\bar{X}}F_{2n,2m,1-\frac{\alpha}{2}}, \frac{\bar{Y}}{\bar{X}}F_{2n,2m,\frac{\alpha}{2}}\right] is 1α1-\alpha conf. int. for θλ\frac{\theta}{\lambda}.

    \implies To test H0:λ=θH_0:\lambda=\theta v.s. H1:λθH_1:\lambda\neq\theta     \iff H0:θλ=1H_0:\frac{\theta}{\lambda}=1 v.s. H1:θλ1H_1:\frac{\theta}{\lambda}\neq 1

Reject H0H_0 if 1[YˉXˉF2n,2m,1α2,YˉXˉF2n,2m,α2]1\notin\left[\frac{\bar{Y}}{\bar{X}}F_{2n,2m,1-\frac{\alpha}{2}}, \frac{\bar{Y}}{\bar{X}}F_{2n,2m,\frac{\alpha}{2}}\right]


EX

<X1,,XniidN(μx,σ2)Y1,,YmiidN(μy,σ2)\Big < \begin{align*} &X_1, \cdots, X_n\overset{\text{iid}}{\sim}N(\mu_x, \sigma^2)\\ &Y_1, \cdots, Y_m\overset{\text{iid}}{\sim}N(\mu_y, \sigma^2) \end{align*}

Note that Sp2(n1)SX2+(m1)SY2n+m2S_p^2\triangleq\frac{(n-1)S^2_X+(m-1)S^2_Y}{n+m-2} is the best est for σ2\sigma^2 and

XˉYˉ(μxμy)(1n+1m)Sp2tn+m2(μ,σ2)\frac{\bar{X}-\bar{Y}-(\mu_x-\mu_y)}{\sqrt{(\frac{1}{n}+\frac{1}{m})S_p^2}}\sim t_{n+m-2}\perp(\mu, \sigma^2)

    [(XˉYˉ)±tn+m2,α2(1n+1m)Sp2]\implies [(\bar{X}-\bar{Y})\pm t_{n+m-2,\frac{\alpha}{2}}\sqrt{(\frac{1}{n}+\frac{1}{m})S_p^2}] is 1α1-\alpha conf. int. for μxμy\mu_x-\mu_y.

To test H0:μx=μyH_0:\mu_x=\mu_y vs. H1:μxμyH_1:\mu_x\neq\mu_y, reject H0H_0 if 0[(XˉYˉ)±tn+m2,α2(1n+1m)Sp2]0\notin\left[(\bar{X}-\bar{Y})\pm t_{n+m-2,\frac{\alpha}{2}}\sqrt{(\frac{1}{n}+\frac{1}{m})S_p^2}\right] is UMAP test.

    [(XˉYˉ)±tn+m2,α2(1n+1m)Sp2]\implies \left[(\bar{X}-\bar{Y})\pm t_{n+m-2,\frac{\alpha}{2}}\sqrt{(\frac{1}{n}+\frac{1}{m})S_p^2}\right] is UMAU 1α1-\alpha conf. int. for μxμy\mu_x-\mu_y.

Asymptotic

這個方法會讓 nn\to\infty,因此也稱為 Large Sample method

As nn\to\infty, if W(x~)θV(X~)DN(0,1)\frac{W(\utilde{x})-\theta}{V(\utilde{X})}\xrightarrow{D}N(0,1), i.e.

P(aW(X~)θV(X~)b)P(aZb)P\left(a\le\frac{W(\utilde{X})-\theta}{V(\utilde{X})}\le b\right)\approx P\left(a\le Z\le b\right) i.e. 1αPθ(Zα2W(X~)θV(X~)Zα2)=Pθ(W(X~)Zα2V(X~)θW(X~)+Zα2V(X~))=Pθ(θ[W(X~)±Zα2V(X~)])θ\begin{align*} \text{i.e. }1-\alpha&\approx P_\theta\left(-Z_{\frac{\alpha}{2}}\le\frac{W(\utilde{X})-\theta}{V(\utilde{X})}\le Z_{\frac{\alpha}{2}}\right)\\ &=P_\theta\left(W(\utilde{X})-Z_{\frac{\alpha}{2}}V(\utilde{X})\le\theta\le W(\utilde{X})+Z_{\frac{\alpha}{2}}V(\utilde{X})\right)\\ &=P_\theta\left(\theta\in [W(\utilde{X})\pm Z_{\frac{\alpha}{2}}V(\utilde{X})]\right)\quad \forall\theta \end{align*}

    [W(X~)±Zα2V(X~)]\implies [W(\utilde{X})\pm Z_{\frac{\alpha}{2}}V(\utilde{X})] is approximated 1α1-\alpha conf. int. for θ\theta.

Remark: 當有確定的樣本數時,永遠都是推導精確的信賴區間。只有當被要求時,才用 approximated 的信賴區間。

Theorem

C.L.T(中央極限定理)

X1,,XnX_1,\cdots,X_n are iid with E(Xi)=μ,Var(Xi)(0,)E(X_i)=\mu, Var(X_i)\in(0, \infty), let Xˉ=1ni=1nXi\bar{X}=\frac{1}{n}\sum_{i=1}^n X_i, then

n(Xˉμ)σnDN(0,1)\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\xrightarrow[n\to\infty]{D}N(0,1)i.e. P(n(Xˉμ)σt)Φ(t)t for large enough n\text{i.e. }P\left(\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\le t\right)\approx\Phi(t) \quad \forall t\text{ for large enough } n
     if σ2 known    P(Zα2n(Xˉμ)σZα2)1α    Pμ(μ[XˉσnZα2,Xˉ+σnZα2])1αμ\begin{align*} &\implies \text{ if }\sigma^2\text{ known}\\ &\implies P\left(-Z_{\frac{\alpha}{2}}\le\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\le Z_{\frac{\alpha}{2}}\right)\approx 1-\alpha\\ &\iff P_\mu\left(\mu\in[\bar{X}-\frac{\sigma}{\sqrt{n}}Z_{\frac{\alpha}{2}}, \bar{X}+\frac{\sigma}{\sqrt{n}}Z_{\frac{\alpha}{2}}]\right)\approx 1-\alpha\quad\forall\mu \end{align*}

i.e. [Xˉ±σnZα2][\bar{X}\pm\frac{\sigma}{\sqrt{n}}Z_{\frac{\alpha}{2}}] is approximated 1α1-\alpha conf. int. for μ\mu

Also Pμ(n(Xˉμ)σZα)=Pμ(μXˉσnZα)P(ZZα)=1αμ\begin{align*} \text{Also } &P_\mu\left(\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\le Z_{\alpha}\right)=P_\mu\left(\mu\ge\bar{X}-\frac{\sigma}{\sqrt{n}}Z_{\alpha}\right)\\ \approx& P(Z\le Z_{\alpha})=1-\alpha\quad\forall\mu \end{align*}

i.e. [XˉσnZα,)[\bar{X}-\frac{\sigma}{\sqrt{n}}Z_{\alpha}, \infty) is approximated 1α1-\alpha conf lower bound for μ\mu.

但以上結論都是在 σ2\sigma^2 已知的情況下。如果 σ2\sigma^2 未知,上面的結論就是錯的。

Theorem

Slutsky's Theorem

  1. r.v.'s YnnDWY_n\xrightarrow[n\to\infty]{D}W : r.v., i.e. P(Ynt)nP(Wt)P(Y_n\le t)\xrightarrow[n\to\infty]{}P(W\le t) t\forall t with FwF_w: conti at tt.
  2. r.v. TnnPcT_n\xrightarrow[n\to\infty]{P}c : const
    TnYnnDcW\implies T_nY_n\xrightarrow[n\to\infty]{D}cW

EX X1,,XnX_1,\cdots, X_n are iid with E(Xi)=μ,Var(Xi)=σ2(0,)E(X_i)=\mu, Var(X_i)=\sigma^2\in(0, \infty)

If σ2\sigma^2 unknown

n(Xˉμ)S=n(Xˉμ)σDN(0,1)SσP1DN(0,1)\frac{\sqrt{n}(\bar{X}-\mu)}{S}=\frac{\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\xrightarrow{D}N(0,1)}{\frac{S}{\sigma}\xrightarrow{P}1} \xrightarrow{D}N(0,1)

i.e. If σ2\sigma^2 unknown

  • [Xˉ±SnZα2][\bar{X}\pm\frac{S}{\sqrt{n}}Z_{\frac{\alpha}{2}}] is approximated 1α1-\alpha conf. int. for μ\mu
  • [XˉSnZα,)[\bar{X}-\frac{S}{\sqrt{n}}Z_{\alpha}, \infty) is approximated 1α1-\alpha conf lower bound for μ\mu

EX X1,,XniidB(1,p)X_1, \cdots, X_n\overset{\text{iid}}{\sim}B(1, p) with E(Xi)=p,Var(Xi)=p(1p)E(X_i)=p, Var(X_i)=p(1-p)

By C.L.Tn(Xˉp)p(1p)DN(0,1)\text{By C.L.T}\qquad\frac{\sqrt{n}(\bar{X}-p)}{\sqrt{p(1-p)}}\xrightarrow{D}N(0,1)

但其中分母部分有 pp,這難以湊成 [L(X~),U(X~)][L(\utilde{X}),U(\utilde{X})]

L.L.N XˉPp    XˉPp    Xˉ(1Xˉ)Pp(1p)\text{L.L.N }\bar{X}\xrightarrow{P}p\implies\bar{X}\xrightarrow{P}p\implies\sqrt{\bar{X}(1-\bar{X})}\xrightarrow{P}\sqrt{p(1-p)}

    [Xˉ±Zα2Xˉ(1Xˉ)/n]\implies \left[\bar{X}\pm Z_{\frac{\alpha}{2}}\sqrt{\bar{X}(1-\bar{X})}/\sqrt{n}\right] is approximated 1α1-\alpha conf. int. for pp.

Recall: an1,bn0\forall a_n\to 1, b_n\to 0, anXˉ+bnPpa_n\bar{X}+b_n\xrightarrow{P}p , i.e. 答案並不唯一。

S2=1n1i=1n(XiXˉ)2=1n1i=1nXi2nn1Xˉ2=1n1i=1nXinn1Xˉ2Xi{0,1} in Bernoulli=nn1Xˉnn1Xˉ2=nn1Xˉ(1Xˉ)\begin{align*} S^2&=\frac{1}{n-1}\sum_{i=1}^n(X_i-\bar{X})^2\\ &=\frac{1}{n-1}\sum_{i=1}^nX_i^2-\frac{n}{n-1}\bar{X}^2\\ &=\frac{1}{n-1}\sum_{i=1}^nX_i-\frac{n}{n-1}\bar{X}^2\quad X_i\in\{0,1\}\text{ in Bernoulli}\\ &=\frac{n}{n-1}\bar{X}-\frac{n}{n-1}\bar{X}^2\\ &=\frac{n}{n-1}\bar{X}(1-\bar{X})\\ \end{align*}

    [Xˉ±Xˉ(1Xˉ)n1Zα2]\implies\left[\bar{X}\pm \frac{\sqrt{\bar{X}(1-\bar{X})}}{\sqrt{n-1}}Z_{\frac{\alpha}{2}}\right] is also approximated 1α1-\alpha conf. int. for pp.

Remark: 如果 Xˉ=1\bar{X}=1 or 00 時,按照以上方法計算出的信賴區間會只有單點。在實際應用中,可能會偏離正確的信賴區間。


EX X1,,XniidP(λ)X_1, \cdots, X_n\overset{\text{iid}}{\sim}P(\lambda) with E(Xi)=λ=Var(Xi)E(X_i)=\lambda=Var(X_i). 我們可以用 Xˉ\bar{X}S2S^2 來估計 λ\lambda

    [Xˉ±Zα2Xˉ or S2n]\implies \left[\bar{X}\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{\bar{X}\text{ or }S^2}{n}}\right] are approximated 1α1-\alpha conf. int. for λ\lambda.

我們還可以直接假設區間 C(X~)={λ:Zα2n(Xˉλ)λZα2}C(\utilde{X})=\set{\lambda: -Z_{\frac{\alpha}{2}}\le\frac{\sqrt{n}(\bar{X}-\lambda)}{\sqrt{\lambda}}\le Z_{\frac{\alpha}{2}}},然後分別解出左右兩個不等式。這個區間相比於上面的區間更精確,因為少了一個 λ\lambda 的估計。

δ\delta-method

如果我們關注參數 μ\mu ,可以利用 C.L.T 得到 n(Xˉμ)σDN(0,1),SPσ\frac{\sqrt{n}(\bar{X}-\mu)}{\sigma}\xrightarrow{D}N(0,1), S\xrightarrow{P}\sigma,進而得到 μ\mu 的信賴區間。但如果我們關注的是 g(μ)g(\mu) ,我們則會使用 δ\delta-method。

Theorem

δ\delta-method: As nn\to\infty, g\forall g with gg' exists and g(μ)0g'(\mu)\neq 0

If n(Tnμ)DN(0,σ2)\sqrt{n}(T_n-\mu)\xrightarrow{D}N(0, \sigma^2)

then n(g(Tn)g(μ))DN(0,σ2[g(μ)]2)\sqrt{n}(g(T_n)-g(\mu))\xrightarrow{D}N(0, \sigma^2\cdot[g'(\mu)]^2)

EX X1,,XniidB(1,p)X_1,\cdots, X_n\overset{\text{iid}}{\sim}B(1,p)

我們關心 p1p\frac{p}{1-p}。(如果 pp 是遊戲的勝率,那麼 p1p\frac{p}{1-p} 就是勝算(odds))

Let g(p)=log(p1p)logit(p)=log(p)log(1p)\begin{align*} \text{Let }g(p)&=\log\left(\frac{p}{1-p}\right)\triangleq \text{logit}(p)\\ &=\log(p)-\log(1-p)\\ \end{align*}     g(p)=1p11p=1p(1p)\implies g'(p)=\frac{1}{p}-\frac{1}{1-p}=\frac{1}{p(1-p)} n(Xˉp)p(1p)DN(0,1)    n(Xˉp)DN(0,p(1p))δ-methpd with g(p)=log(p1p)    n(g(Xˉ)g(p))DN(0,[p(1p)][1p(1p)]2)\begin{align*} \frac{\sqrt{n}(\bar{X}-p)}{\sqrt{p(1-p)}}\xrightarrow{D}N(0,1) &\iff\sqrt{n}(\bar{X}-p)\xrightarrow{D}N(0, p(1-p))\\ \delta\text{-methpd with }g(p)=\log(\frac{p}{1-p})&\implies \sqrt{n}(g(\bar{X})-g(p))\xrightarrow{D}N(0, [p(1-p)]\cdot[\frac{1}{p(1-p)}]^2)\\ \end{align*} i.e.n(log(TnT)log(p1p))DN(0,1)with T=Xi    n(log(TnT)log(p1p))1p(1p)DN(0,1)    log(TnT)log(p1p)1n(1p+11p)DN(0,1)\begin{align*} \text{i.e.} &\sqrt{n}\left(\log\left(\frac{T}{n-T}\right)-\log\left(\frac{p}{1-p}\right)\right)\xrightarrow{D}N(0, 1)\qquad\text{with }T=\sum X_i\\ \iff &\frac{\sqrt{n}\left(\log\left(\frac{T}{n-T}\right)-\log\left(\frac{p}{1-p}\right)\right)}{\sqrt{\frac{1}{p(1-p)}}}\xrightarrow{D}N(0, 1)\\ \iff &\frac{\log\left(\frac{T}{n-T}\right)-\log\left(\frac{p}{1-p}\right)}{\sqrt{\frac{1}{n}\left(\frac{1}{p}+\frac{1}{1-p}\right)}}\xrightarrow{D}N(0, 1)\\ \end{align*}

分母部分仍有 pp,我們可以用 Xˉ\bar{X} 來估計 pp,並且因為 Slutsky's Theorem,收斂性不會受到影響。

    log(TnT)log(p1p)1n(nT+nnT)DN(0,1)    Pp(log(p1p)[log(TnT)±Zα21T+1nT])1α\begin{align*} \implies& \frac{\log\left(\frac{T}{n-T}\right)-\log\left(\frac{p}{1-p}\right)}{\sqrt{\frac{1}{\cancel{n}}\left(\frac{\cancel{n}}{T}+\frac{\cancel{n}}{n-T}\right)}}\xrightarrow{D}N(0, 1)\\ \implies& P_p\left(\log\left(\frac{p}{1-p}\right)\in\left[\log\left(\frac{T}{n-T}\right)\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{T}+\frac{1}{n-T}}\right]\right)\approx 1-\alpha \end{align*}

    \implies [log(TnT)±Zα21T+1nT][\log\left(\frac{T}{n-T}\right)\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{T}+\frac{1}{n-T}}] is approximated 1α1-\alpha conf. int. for log(p1p)\log\left(\frac{p}{1-p}\right)

    \implies [exp(log(TnT)±Zα21T+1nT)]\left[\exp\left(\log\left(\frac{T}{n-T}\right)\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{T}+\frac{1}{n-T}}\right)\right] is approximated 1α1-\alpha conf. int. for p1p\frac{p}{1-p}

因為在 B(1,p)B(1,p) 中,Xi=T\sum X_i=T 就会是成功的次数,nTn-T 则是失败的次数。因此 TnT\frac{T}{n-T} 就是成功的次数与失败的次数的比值,即 p1p\frac{p}{1-p}


for large nn

log(TxnTx)log(p11p1)1Tx+1nTxZ1log(TymTy)log(p21p2)1Ty+1mTyZ2with Z1,Z2N(0,1) iid\begin{align*} &\log\left(\frac{T_x}{n-T_x}\right)-\log\left(\frac{p_1}{1-p_1}\right)\approx \sqrt{\frac{1}{T_x}+\frac{1}{n-T_x}}Z_1\\ &\log\left(\frac{T_y}{m-T_y}\right)-\log\left(\frac{p_2}{1-p_2}\right)\approx \sqrt{\frac{1}{T_y}+\frac{1}{m-T_y}}Z_2 \end{align*}\qquad\text{with }Z_1, Z_2\sim N(0,1) \text{ iid} log(TxnTxmTyTy)log(p11p1p21p2)1Tx+1nTxZ1+1Ty+1mTyZ2=N(0,1Tx+1nTx+1Ty+1mTy)\begin{align*} \log\left(\frac{T_x}{n-T_x}\frac{m-T_y}{T_y}\right)-\log\left(\frac{p_1}{1-p_1}\frac{p_2}{1-p_2}\right)&\approx \sqrt{\frac{1}{T_x}+\frac{1}{n-T_x}}Z_1+\sqrt{\frac{1}{T_y}+\frac{1}{m-T_y}}Z_2\\ &=N(0,\frac{1}{T_x}+\frac{1}{n-T_x}+\frac{1}{T_y}+\frac{1}{m-T_y}) \end{align*}

如果我們關注的是勝算比(odds ratio)p11p1/p21p2θ\frac{p_1}{1-p_1}\big/\frac{p_2}{1-p_2}\triangleq\theta

    Pp1,p2(log(θ)[log(TxnTxmTyTy)±Zα21Tx+1nTx+1Ty+1mTy])1α\implies P_{p_1,p_2}\left(\log(\theta)\in\left[\log\left(\frac{T_x}{n-T_x}\frac{m-T_y}{T_y}\right)\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{T_x}+\frac{1}{n-T_x}+\frac{1}{T_y}+\frac{1}{m-T_y}}\right]\right)\approx 1-\alpha
正面反面總和
XTxT_xnTxn-T_xn
YTyT_ymTym-T_ym

EX:對於阿司匹林是否能預防心臟病這一問題收集到以下數據:

是否有心臟病沒有
阿司匹林10410933
安慰劑18910845

我們關心 odds ratio θ=p11p1/p21p2\theta=\frac{p_1}{1-p_1}\big/\frac{p_2}{1-p_2},其中 p2p_2 是阿司匹林組的心臟病發生率,p1p_1 是安慰劑組的心臟病發生率。

    [ln(189×1093310845×104)±1.961189+110845+1104+110933]=[0.365,0.846] is 95% conf. int. for ln(θ)    [e0.365,e0.846]=[1.44,2.33] is 95% conf. int. for θ\begin{align*} &\implies \left[\ln\left(\frac{189\times 10933}{10845\times 104}\right)\pm 1.96\sqrt{\frac{1}{189}+\frac{1}{10845}+\frac{1}{104}+\frac{1}{10933}} \right]=[0.365, 0.846]\text{ is } 95\%\text{ conf. int. for }\ln(\theta)\\ &\implies \left[e^{0.365}, e^{0.846}\right]=[1.44, 2.33]\text{ is } 95\%\text{ conf. int. for }\theta \end{align*}

如果阿司匹林明顯有預防心臟病的效果,那麼 p2p_2 應該顯著小於 p1p_1;如果沒有效果,那麼吃阿司匹林或安慰劑的產生心臟病的幾率應該相同。因此做檢定:

H0:p1=p2 vs. H1:p1>p2    H0:θ=1 vs. H1:θ>1\begin{align*} & H_0: p_1=p_2\text{ vs. }H_1: p_1>p_2\\ \iff& H_0: \theta=1\text{ vs. }H_1: \theta>1\\ \end{align*}

1[1.44,2.33]    1\notin [1.44, 2.33]\implies reject H0H_0 at 5%5\% level. I.e. 阿司匹林在預防心臟病方面有顯著效果。


EX:

<XB(n,p)YB(m,p)θ=p1(1p2)(1p1)p2\perp\Big<\begin{align*} &X\sim B(n,p)\\ &Y\sim B(m,p) \end{align*}\qquad\theta=\frac{p_1(1-p_2)}{(1-p_1)p_2}

將獲得的 Binomal 數據整理成以下 2×22\times 2 列聯表(contingency table)

DataSFTotal
xp1x_{p_1}nx(1p1)n-x_{(1-p_1)}n
yp2y_{p_2}mx(1p2)m-x_{(1-p_2)}m
lnθ[ln(x(my)y(nx)±Zα21x+1nx+1y+1my)]=[A,B] with conf 1α    θ[eA,eB] with conf 1α\begin{align*} &\ln\theta\in \left[\ln\left(\frac{x(m-y)}{y(n-x)}\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{x}+\frac{1}{n-x}+\frac{1}{y}+\frac{1}{m-y}} \right)\right]=[A,B] \text{ with conf }\approx 1-\alpha\\ \implies& \theta\in [e^A, e^B] \text{ with conf }\approx 1-\alpha \end{align*}

Remark:這個結論對於從 multinomial / Poisson 獲得樣本所組成的列聯表也是成立的。


EX:

收集到以下數據。A, B 是關心的兩個不同的事件(e.g. 天氣、路口),中間表格則是交集事件發生的次數,以及發生幾率。這組數據服從 multinomial distribution。

B1B_1B2B_2
A1A_1X11,P11X_{11}, P_{11}X12,P12X_{12}, P_{12}
A2A_2X21,P21X_{21}, P_{21}X22,P22X_{22}, P_{22}

i=12j=12Xij=ni=12j=12Pij=1\sum_{i=1}^2\sum_{j=1}^2 X_{ij}=n\quad \sum_{i=1}^2\sum_{j=1}^2 P_{ij}=1

X~=(X11,X12,X21,X22)P~=(P11,P12,P21,P22)Multinomialn(k,P~)k= col × row =4\begin{align*} &\utilde{X}=(X_{11}, X_{12}, X_{21}, X_{22})\\ &\utilde{P}=(P_{11}, P_{12}, P_{21}, P_{22}) \end{align*}\sim \text{Multinomial}_n(k, \utilde{P})\quad k=\text{ col }\times \text{ row }=4 θP11P22P12P21: odds ratio\theta\triangleq \frac{P_{11}P_{22}}{P_{12}P_{21}}: \text{ odds ratio}

如果 ABA\perp B,那麼不管在 A1A_1A2A_2 條件下,B1B_1B2B_2 的發生概率應該是不變的。因此

H0:AB    H0:P11P12=P21P22    H0:P11P22P12P21=θ=1    H0:lnθ=0\begin{align*} & H_0: A\perp B\\ \iff& H_0: \frac{P_{11}}{P_{12}}=\frac{P_{21}}{P_{22}}\\ \iff& H_0: \frac{P_{11}P_{22}}{P_{12}P_{21}}=\theta=1\\ \iff& H_0: \ln\theta=0 \end{align*}     lnθ[ln(X11X22X12X21)±Zα21X11+1X12+1X21+1X22]=[A,B] with conf 1α    θ[eA,eB] with conf 1α\begin{align*} &\implies \ln\theta\in \left[\ln\left(\frac{X_{11}X_{22}}{X_{12}X_{21}}\right)\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{X_{11}}+\frac{1}{X_{12}}+\frac{1}{X_{21}}+\frac{1}{X_{22}}}\right]=[A,B] \text{ with conf }\approx 1-\alpha\\ &\implies \theta\in [e^A, e^B] \text{ with conf }\approx 1-\alpha \end{align*}

廣泛來說,X~Multinomialn(k,P~)\utilde{X}\sim \text{Multinomial}_n(k,\utilde{P}) with k=I×Jk=I\times J 可以做成一張 I×JI\times J 的列聯表

A\BB1B_1B2B_2\cdotsBJB_J
A1A_1X11X_{11}X12X_{12}\cdotsX1JX_{1J}
A2A_2X21X_{21}X22X_{22}\cdotsX2JX_{2J}
\vdots\vdots\vdots\ddots\vdots
AIA_IXI1X_{I1}XI2X_{I2}\cdotsXIJX_{IJ}

而關注的問題通常是 H0:ABH_0:A\perp B v.s. H1:A⊥̸BH_1:A\not\perp B。進一步可能會關注關鍵的地方在哪,因此會在 A, B 中各挑選 2 個事件組成 2×22\times 2 的列聯表,並計算 odds ratio 的信賴區間。

Multivariate

C.L.T

X~1,,X~n iid with E(X~i)=θ~,Var(X~i)=Σ~\utilde{X}_1, \cdots, \utilde{X}_n \text{ iid with } E(\utilde{X}_i)=\utilde{\theta}, Var(\utilde{X}_i)=\bcancel{\utilde{\Sigma}}

如果每個隨機向量 X~i\utilde{X}_i 的維度都是 mm,那麼 Xˉ=1nX~i\bar{X}=\frac{1}{n}\sum\utilde{X}_i 也會是一個 mm 維的隨機向量。

    n(Xˉθ~)nDNm(0~,Σ~)\implies \sqrt{n}(\bar{X}-\utilde{\theta})\xrightarrow[n\to\infty]{D}N_m(\utilde{0}, \bcancel{\utilde{\Sigma}})

EX: Y~Multinomialn(k,P~)\utilde{Y}\sim \text{Multinomial}_n(k,\utilde{P})

12\cdotsktotal
dataY1Y_1Y2Y_2\cdotsYkY_kn
w) probP1P_1P2P_2\cdotsPkP_k1

    \implies est PjP_j by Yjn\frac{Y_j}{n}, i.e. P^~=Y~n\utilde{\hat{P}}=\frac{\utilde{Y}}{n}

如果令 X~i\utilde{X}_i 是第 ii 次丟一個球的結果。因為一個球只能進一個籃子裡,所以每個 X~i\utilde{X}_i 向量中只有一個元素是 1,其他都是 0。

如果單看 X~i\utilde{X}_i 中的每個 XijX_{ij},那麼 XijB(1,Pj)X_{ij}\sim B(1,P_j) with E[XijXij]=0Var(Xij)=Pj(1Pj)    jjCov(Xij,Xij)=PjPjE[X_{ij}\cdot X_{ij'}]=0\quad Var(X_{ij})=P_j(1-P_j)\implies\forall j\neq j'\quad Cov(X_{ij},X_{ij'})=-P_jP_{j'}

I.e. X~iMultinomial1(k,P~)\utilde{X}_i\sim \text{Multinomial}_1(k, \utilde{P}) with

E(Xi)=P~σ2{X~i}=[P1(1P1)P1P2P1PkP2P1P2(1P2)P2PkPkP1PkP2Pk(1Pk)]=diag(P~)P~P~t=Σ\begin{align*} E(X_i)=\utilde{P}\quad \sigma^2\set{\utilde{X}_i}&=\begin{bmatrix} P_1(1-P_1) & -P_1P_2 & \cdots & -P_1P_k\\ -P_2P_1 & P_2(1-P_2) & \cdots & -P_2P_k\\ \vdots & \vdots & \ddots & \vdots\\ -P_kP_1 & -P_kP_2 & \cdots & P_k(1-P_k) \end{bmatrix}\\ &=\text{diag}(\utilde{P})-\utilde{P}\utilde{P}^t=\bcancel{\Sigma} \end{align*}     Y~=X~i    P^~=Y~n=Xˉ\implies \utilde{Y}=\sum \utilde{X}_i\implies \utilde{\hat{P}}=\frac{\utilde{Y}}{n}=\bar{X} C.L.Tn(P^~P~)DNm(0~,Σ)\xRightarrow{\text{C.L.T}} \sqrt{n}(\utilde{\hat{P}}-\utilde{P})\xrightarrow{D}N_m(\utilde{0}, \bcancel{\Sigma})

δ\delta-method

n(Xˉθ~)DNm(0~,Σ)    n(g(Xˉ)g(θ~))DNm(0~,g(θ~)tΣg(θ~))\begin{align*} &\sqrt{n}(\bar{X}-\utilde{\theta})\xrightarrow{D}N_m(\utilde{0}, \bcancel{\Sigma})\\ \implies& \sqrt{n}(g(\bar{X})-g(\utilde{\theta}))\xrightarrow{D}N_m(\utilde{0},\nabla g(\utilde{\theta})^t\bcancel{\Sigma}\nabla g(\utilde{\theta})) \end{align*} g:RmRwith g(θ~)=(gθ1(θ~)gθm(θ~)) exists and 0~\forall g:\R^m\to \R \quad\text{with } \nabla g(\utilde{\theta})=\begin{pmatrix} \frac{\partial g}{\partial \theta_1}(\utilde{\theta})\\ \vdots\\ \frac{\partial g}{\partial \theta_m}(\utilde{\theta}) \end{pmatrix}\text{ exists and }\neq \utilde{0}
k4n(P^~P~)DNk(0~,Σ)Σ=diag(P~)P~P~tk\ge 4\quad \sqrt{n}(\utilde{\hat{P}}-\utilde{P})\xrightarrow{D}N_k(\utilde{0}, \bcancel{\Sigma})\quad \bcancel{\Sigma}=\text{diag}(\utilde{P})-\utilde{P}\utilde{P}^t Takeg(P~)=ln(P1P2P3P4)=ln(P1)+ln(P2)ln(P3)ln(P4)    g(P~)=(1P1,1P2,1P3,1P4,0,,0)t:k×1\begin{align*} \text{Take}&\quad g(\utilde{P})=\ln\left(\frac{P_1P_2}{P_3P_4}\right)=\ln(P_1) + \ln(P_2) - \ln(P_3) - \ln(P_4)\\ \implies& \nabla g(\utilde{P})=(\frac{1}{P_1}, \frac{1}{P_2}, -\frac{1}{P_3}, -\frac{1}{P_4}, 0, \cdots, 0)^t: k\times 1 \end{align*} (g(P~))tΣg(P~)=(g(P~))t(diag(P~)P~P~t)g(P~)=(g(P~))tdiag(P~)g(P~)(g(P~))tP~P~tg(P~)=i=1kPi(g(P~))i2[(g(P~))tP~]2=1P1+1P2+1P3+1P4(1+111+0++0)2=1P1+1P2+1P3+1P4\begin{align*} &(\nabla g(\utilde{P}))^t\bcancel{\Sigma}\nabla g(\utilde{P})\\ =&(\nabla g(\utilde{P}))^t\left(\text{diag}(\utilde{P})-\utilde{P}\utilde{P}^t\right)\nabla g(\utilde{P})\\ =&(\nabla g(\utilde{P}))^t\text{diag}(\utilde{P})\nabla g(\utilde{P}) - (\nabla g(\utilde{P}))^t\utilde{P}\utilde{P}^t\nabla g(\utilde{P})\\ =&\sum_{i=1}^kP_i(\nabla g(\utilde{P}))_i^2 - \left[(\nabla g(\utilde{P}))^t \utilde{P} \right]^2\\ =&\frac{1}{P_1} + \frac{1}{P_2} + \frac{1}{P_3} + \frac{1}{P_4} - (1+1-1-1+0+\cdots+0)^2\\ =&\frac{1}{P_1} + \frac{1}{P_2} + \frac{1}{P_3} + \frac{1}{P_4} \end{align*} δ-methodn(g(P^~)g(P~))DN(0,1P1+1P2+1P3+1P4)    g(P^~)g(P~)1n(1P1+1P2+1P3+1P4)DN(0,1)slutskyg(P^~)g(P~)1Y1+1Y2+1Y3+1Y4DN(0,1)P^j=Yjn    ln(Y1Y2Y3Y4)ln(P1P2P3P4)1n(1P1+1P2+1P3+1P4)DN(0,1)\begin{align*} \xRightarrow{\delta\text{-method}}& \sqrt{n}(g(\utilde{\hat{P}})-g(\utilde{P}))\xrightarrow{D}N\left(0, \frac{1}{P_1} + \frac{1}{P_2} + \frac{1}{P_3} + \frac{1}{P_4}\right)\\ \implies& \frac{g(\utilde{\hat{P}})-g(\utilde{P})}{\sqrt{\frac{1}{n}\left(\frac{1}{P_1}+\frac{1}{P_2}+\frac{1}{P_3}+\frac{1}{P_4} \right)}} \xrightarrow{D}N(0,1)\\ \xRightarrow{\text{slutsky}}& \frac{g(\utilde{\hat{P}})-g(\utilde{P})}{\sqrt{\frac{1}{Y_1}+\frac{1}{Y_2}+\frac{1}{Y_3}+\frac{1}{Y_4}}} \xrightarrow{D}N(0,1)\quad \hat{P}_j=\frac{Y_j}{n}\\ \implies& \frac{\ln\left(\frac{Y_1Y_2}{Y_3Y_4} \right)-\ln\left(\frac{P_1P_2}{P_3P_4} \right)}{\sqrt{\frac{1}{n}\left(\frac{1}{P_1}+\frac{1}{P_2}+\frac{1}{P_3}+\frac{1}{P_4} \right)}} \xrightarrow{D}N(0,1) \end{align*}

因此如果 θ=lnP1P2P3P4\theta=\ln\frac{P_1P_2}{P_3P_4} 是我們關心的參數

P(θ[ln(Y1Y2Y3Y4)±Zα21Y1+1Y2+1Y3+1Y4])1αfor large enough nP\left(\theta\in\left[\ln\left(\frac{Y_1Y_2}{Y_3Y_4} \right)\pm Z_{\frac{\alpha}{2}}\sqrt{\frac{1}{Y_1}+\frac{1}{Y_2}+\frac{1}{Y_3}+\frac{1}{Y_4}} \right] \right)\approx 1-\alpha\quad\text{for large enough }n

Sample size determination with Binomial sample

我們通常會在收集資料之前就定下目標,然後為了驗證目標而收集資料。因此我們會需要知道需要多少樣本才能驗證是否達到目標。而不是收集資料後發現樣本數不夠達到足夠的信心水平。

X1,,XniidB(1,p)X_1,\cdots, X_n\overset{\text{iid}}{\sim}B(1,p)

C.L.Tp[Xˉ±Xˉ(1Xˉ)nZα2] with conf 1α\xRightarrow{\text{C.L.T}} p\in \left[\bar{X}\pm \frac{\sqrt{\bar{X}(1-\bar{X})}}{\sqrt{n}}Z_{\frac{\alpha}{2}} \right] \text{ with conf }\approx 1-\alpha i.e. p(0,1)1αPp(XˉXˉ(1Xˉ)nZα2pXˉ+Xˉ(1Xˉ)nZα2)=Pp(XˉpXˉ(1Xˉ)nZα2)\begin{align*} \text{i.e. }\forall p\in(0,1)\quad 1-\alpha&\approx P_p\left(\bar{X}-\frac{\sqrt{\bar{X}(1-\bar{X})}}{\sqrt{n}}Z_{\frac{\alpha}{2}}\le p\le\bar{X}+\frac{\sqrt{\bar{X}(1-\bar{X})}}{\sqrt{n}}Z_{\frac{\alpha}{2}} \right)\\ &=P_p\left(|\bar{X}-p|\le\frac{\sqrt{\bar{X}(1-\bar{X})}}{\sqrt{n}}Z_{\frac{\alpha}{2}} \right) \end{align*}

其中 Xˉ\bar{X}pp 的估計。意思是在 1α1-\alpha 的信心水平下,我們需要確保 Xˉ\bar{X}pp 的誤差不超過某個範圍 EE

因為這是在收集數據之前確定要收集的樣本量,因此我們還不知道 Xˉ\bar{X} 的值。但我們知道 Xˉ[0,1]\bar{X}\in[0,1] 並且 Xˉ(1Xˉ)12\sqrt{\bar{X}(1-\bar{X})}\le \frac{1}{2}。因此我們可以用這個上界來計算一個保守的樣本量。

Xˉ(1Xˉ)nZα212Zα2=E    n=12EZα2    n=(12EZα2)2\begin{align*} &\sqrt{\frac{\bar{X}(1-\bar{X})}{n}} Z_{\frac{\alpha}{2}}\le \frac{1}{2}Z_{\frac{\alpha}{2}}=E\\ \iff& \sqrt{n}=\frac{1}{2E}Z_{\frac{\alpha}{2}}\\ \iff& n=\left(\frac{1}{2E}Z_{\frac{\alpha}{2}}\right)^2 \end{align*}

e.g. α=0.05,E=0.03    n(1.96)24(0.03)2=1068\alpha=0.05, E=0.03\implies n\ge \frac{(1.96)^2}{4\cdot(0.03)^2}=1068