Confidence Interval

Definition

Confidence Interval
Let X1,X2,⋯,Xn be a sample on a random variable X, where X has PDF f(x;θ), θ∈Ω.
Let L=L(X1,⋯,Xn) and U=U(X1,⋯,Xn) be 2 statistics.
Given a level α∈(0,1), if

P{L(X1,⋯,Xn)≤θ≤U(X1,⋯,Xn)}=1−α

Then, (L,U) is a (1−α)100% confidence interval for θ.
The confidence coefficient of the interval is the probability that the interval includes θ is 1−α.

一个通俗版本的理解

If P{θ^1≤θ≤θ^2}=1−α,
Then, [θ^1,θ^2] is the confidence interval of θ with confidence coefficient 1−α.

CI for Mean μ

Case 1: Normal Distribution (σ2 known)

Xi∼N(μ,σ2) and σ2 is known.

X¯∼N(μ,σ2n)Z=X¯−μσn∼N(0,1)P(−zα2≤X¯−μσn≤zα2)=1−αP{−zα2≤n(X¯−μ)σ≤zα2}=1−αP{−σzα2≤n(X¯−μ)≤σzα2}=1−αP{−σzα2n≤X¯−μ≤σzα2n}=1−αP{X¯+σzα2n≥μ≥X¯−σzα2n}=1−αP{μ∈[X¯±σzα2n]}=1−α

(1−α) CI: [L(X1,⋯,Xn),U(X1,⋯,Xn)] is random
Once the sample is observed,we can compute the sample mean x¯

Note

TLDR: x¯ 是随机变量 X¯ 的一次观测值
X¯ 是随机变量,所以 interval 是随机的;
一旦样本观测完,把 X¯ 换成具体数字 x¯,interval 就固定了

The computed interval, x¯±σzα2n is 100(1−α)% , is confidence interval of μ

Note

我们使用 q1−α2 和 qα2 是为了让置信区间(Confidence Interval)左右对称。
这样不仅能最公平地分配误差,而且能让这个区间在数轴上变得最短,从而提高估计的精度。
q1−34α,qα4 虽然覆盖的面积是对的,但会导致区间“歪”向一边,不够精准。
CI.png

Fixed Change Width
α,σ n↑ ↓
σ,n α↓ ↑
α,n σ↑ ↑

Example

Let X be the length of lifetime of a light bulb and assume X∼N(μ,1296).
There are random sample of n=27 with x¯=1478.
What is the 95% confidence interval?

1−α=0.95α=0.05X¯∼N(μ,129627)∼N(μ,48)Z=X¯−μ48∼N(0,1)P{−z0.052≤X¯−μ48≤z0.052}=0.95P{z0.02548+X¯≥μ≥X¯−z0.02548}=0.95P{X¯−z0.02548≤μ≤X¯+z0.02548}=0.95P{X¯−1.9648≤μ≤X¯+1.9648}=0.95The confidence interval for μ=[x¯−13.579,13.579+x¯]=[1478−13.579,13.579+1478]=[1464.42,1491.58]

Estimation Error

Estimation error E:=|x¯−μ|

Note

If it is normal distribution and σ2 is known,
then

E≤zα2σn

One Sided (1−α) CI

Example 1: Lower bound
P{θ≥L(X1,⋯,Xn)}=1−αP{h(X1,⋯,Xn;θ)≤qα}=1−αh(X1,⋯,Xn;θ)∼N(0,1)P{n(X¯−μ)σ≤zα}=1−αP{X¯−μ≤σzαn}=1−αP{μ≥X¯−zασn}=1−α

The confidence interval is [x¯−zασn,+∞)

Example 2: Upper bound
P{θ≤U(X1,⋯,Xn)}=1−αP{h(X1,⋯,Xn;θ)≥q1−α}=1−αh(X1,⋯,Xn;θ)∼N(0,1)P{n(X¯−μ)σ≥−zα}=1−αP{X¯−μ≥−σnzα}=1−αP{X¯+zασn≥μ}=1−α

Hence, confidence interval is (−∞,X¯+zασn]
One-sided CI.png

Case 2: Non-Normal Distribution (σ2 Known)

X1,⋯,Xn are i.i.d. with mean μ=E(X1) and variance σ2=Var(X1), which is known.
By Central Limit Theorem, for large n,

X¯−μσn∼approxN(0,1)

Thus,

P(X¯−zα2σn≤μ≤X¯+zα2σn)≈1−α

The asymptotic / approximate two-sided 100(1−α)% CI is

x¯±zα2(σn)

Example

Let X be amount of orange juice consumed by an American per day
Given σ=96,n=576,x¯=133
What is the approximate 90% confidence interval for μ

1−α=0.9α=0.1By CLT, X¯−μ96576∼approxN(0,1)X¯−μ4∼approxN(0,1)P{−zα2≤X¯−μ4≤zα2}=0.9P{4z0.05+X¯≥μ≥X¯−4z0.05}=0.9P{X¯−4z0.05≤μ≤X¯+4z0.05}=0.9The confidence interval for μ=[x¯±4z0.05]=[133±4×1.645]=[126.42,139.58]
Tip

Case 1 和 Case 2 做法几乎一样 ——
Substitute given variables and find the interval

x¯±zα2(σn)

Case 3: Normal Distribution (σ2 Unknown)

X1,⋯,Xn∼N(μ,σ2) and σ2 is unknown
In #Case 1 Normal Distribution ($ sigma 2$ known), x¯±zα2(σn) depends on σ.
As σ is unknown, we cannot use x¯±zα2(σn) to find the interval.
Hence, we need to use sample variance S2 and Student's theorem

Sample variance: S2=1n−1∑i=1n(Xi−X¯)2Student’s theorem: X¯−μSn∼t(n−1)

Hence, we need to use ±tα2(n−1) as upper and lower bound.

P{−tα2(n−1)≤X¯−μSn≤tα2(n−1)}=1−αP{−S⋅tα2(n−1)n≤X¯−μ≤S⋅tα2(n−1)n}=1−αP{X¯−S⋅tα2(n−1)n≤μ≤X¯+S⋅tα2(n−1)n}=1−α

The 100(1−α)% CI of μ is

[x¯−s⋅tα2(n−1)n,x¯+s⋅tα2(n−1)n]
Note

S 和 s 的区别跟 X 和 x 的区别一样 ——
即 S 是 random variable,而 s 是 observed value

Example

Let X∼N(μ,σ2), and both μ and σ2 are unknown
Given n=20,x¯=507.5,s=89.75,t0.05(19)=1.729.
What is 90% CI for μ?

1−α=0.9α=0.1X¯−μS20∼t(19)P{−t0.12(19)≤X¯−μS20≤t0.12(19)}=0.9P{−S⋅t0.05(19)20≤X¯−μ≤S⋅t0.05(19)20}=0.9P{X¯−S⋅t0.05(19)20≤μ≤X¯+S⋅t0.05(19)20}=0.9The confidence interval for μ=[x¯±s⋅t0.05(19)20]=[507.5±89.75×1.72920]=[472.80,542.20]

Case 4: Non-Normal Distribution (σ2 Unknown)

X1,⋯,Xn are i.i.d. with mean μ=E(X1) and variance σ2=Var(X1), which is unknown.
If n is large enough / each Xi is approximately normal, then

X¯−μSn∼approxt(n−1)

Approximate two-sided 100(1−α)% CI of μ is

[x¯−s⋅tα2(n−1)n,x¯+s⋅tα2(n−1)n]
Important

If n is large enough, then

tα2(n−1)≈zα2

Hence, the approximate two-sided 100(1−α)% CI for μ is

[x¯−zα2(sn),x¯+zα2(sn)]
Distribution of Xi Distribution Two-sided 1−α CI
N(μ,σ2), σ2 known X¯−μσ/n∼N(0,1) x¯±σ⋅zα/2n
Any distribution with large n, σ2 known X¯−μσ/n∼approxN(0,1) x¯±σ⋅zα/2n
N(μ,σ2), σ2 unknown X¯−μS/n∼t(n−1) x¯±s⋅tα/2(n−1)n
Any distribution with large n, σ2 unknown X¯−μS/n∼approxt(n−1) x¯±s⋅tα/2(n−1)n

CI for the Difference of 2 Means

For

X1,⋯,Xn∼N(μX,σX2)Y1,⋯,Ym∼N(μY,σY2)

To construct confidence intervals for μX−μY, we need to consider 3 cases

Case 1: Pooled t-interval

Let X1,⋯,Xn∼N(μX,σ2) and Y1,⋯,Ym∼N(μY,σ2) be independent random variables.
Then, 100(1−α)% CI for μX−μY is

X¯−Y¯±tα2(n+m−2)Sp1n+1m

Sp2 is pooled estimator of σ2, which is unbiased estimator of σ2

Sp2=(n−1)SX2+(m−1)SY2n+m−2=∑i=1n(Xi−X¯)2+∑i=1m(Yi−Y¯)2n+m−2

Example

Let X∼N(μx,σ2) be the score on a standardized test in a large high school.
Let Y∼N(μY,σ2) be the score on a standardized test in a small high school.
Given:
n=9,x¯=81.31,sx2=60.76
m=15,y¯=78.61,sy2=48.24
What is 95% confidence interval for μx−μy

1−α=0.95α=0.05n+m−2=22t1−0.952(22)=2.074t0.025(22)=2.074sp2=8(60.76)+14(48.24)22sp=486.08+675.3622Confidence interval for μX−μY=81.31−78.61±2.074(486.08+675.3622)(19+115)=[−3.65,9.05]

Case 2: Welch's t-interval

Let X1,⋯,Xn∼N(μX,σX2),Y1,⋯,Ym∼N(μY,σY2) be independent
Approximate 100(1−α)% CI for μX−μY is

X¯−Y¯±tα2(r)SX2n+SY2m

where

r=⌊(SX2n+SY2m)21n−1(SX2n)2+1m−1(SY2m)2⌋
Note

⌊x⌋ is floor function (round down)
i.e. ⌊3.4⌋=⌊3.9⌋=3

Note

  • Welch 公式算出来的自由度 r 通常不是整数(比如 19.8),但 t 分布表只有整数自由度,必须取一个整数去查表
  • 而「向下取整」比「向上取整/四舍五入」更保守、更安全--它让区间更宽,绝不会把真实置信水平说低

Example

Assume σX2≠σY2
Scenario is same as #^fd6a48

α=0.05r=⌊(60.769+48.2415)218(60.769)2+114(48.2415)2⌋=15t0.025(15)=2.131Welch’s t-interval for μX−μY=81.31−78.61±2.131(60.769+48.2415)=[−4.0278,9.4278]

Compared to pooled t-interval [−3.65,9.05], Welch's t-interval is wider than pooled t-interval.

Case 3: Paired t-interval

Definition

Paired samples
Each data point in the first sample is matched & related to a unique data point in the second sample
paired_sample.png

Let (X1,Y1),⋯,(Xn,Yn) be n pairs of dependent measures.
Let Di=Xi−Yi.
Suppose D1,⋯,Dn∼N(μD,σD2) with μD=μX−μY.
Then, 100(1−α)% CI for μX−μY is

D¯±tα2(n−1)SDn

where

D¯=1n∑i=1nDiSD2=1n−1∑i=1n(Di−D¯)2
Note

配对的目的是“消掉个体之间的差异”
以减肥药为例 —— 有人天生体重就高(比如 90 kg),有人天生低(比如 50 kg)。
如果我用"服药后组 vs 服药前组"来比,即使药完全无效,两组的个体构成稍有不同(比如高体重的人恰好多分了几个到"服药后"组),均值就会差出好几公斤。
这个"个体差异"造成的噪声,把真正的药效完全盖住了。

配对的做法是同一个人自己和自己比:Di=服药后i−服药前i。
这个差值里,"这个人天生体重多少"被减掉了 —— 它同时出现在 Xi 和 Yi 里,一减就没了。
剩下的 Di 只包含"药效 + 这一次测量的随机误差"。

Example

An experiment was conducted to compare people's reaction times to a red light versus green light.
When signaled with either red or green light, the subject was asked to hit a switch to turn off the light
When the switch was hit, a clock was turned off and the reaction time was recorded

Given n=8,d¯=−0.062,sd=0.0765
What is the 95% CI for μX−μY?

Subject Red (x) Green (y) d=x−y
1 0.30 0.43 −0.13
2 0.23 0.32 −0.09
3 0.41 0.58 −0.17
4 0.53 0.46 0.07
5 0.24 0.27 −0.03
6 0.36 0.41 −0.05
7 0.38 0.38 0.00
8 0.51 0.61 −0.10
−0.0625±t0.025(7)(0.07658)=[−0.1265,0.0015]

Using pooled and Welch's t-interval to calculate CI,
Given that x¯=0.3700,y¯=0.4325,sX=0.1124,sY=0.1173.
Pooled t-interval

95%CI=0.3700−0.4325±t0.025(14)7(0.1124)2+7(0.1173)21428=[−0.1857,0.0607]

Welch's t-interval

r=⌊(0.112428+0.117328)217(0.112428)2+17(0.117328)2⌋=1395%CI=0.3700−0.4325±t0.025(13)0.112428+0.117328=[−0.1865,0.0615]

With same center d¯=x¯−y¯, CI widths are different
In general, CI width: Pair t-interval < Pool t-interval < Welch's t-interval

Note

When sX2 is closed to sY2, widths of pooled t-interval and Welch's t-interval are similar.

CI for Proportions

Example

In a political campaign survey, we collect a sample of n=351 voters.
y=185 out of them favor candidate A and remaining favour candidate B.
Let p be the supporting rate in the population.
How to build a CI for the supporting rate?

Let Xi={1,favour candidate A0,favour candidate BX1,⋯,Xn∼Bernoulli(p)Denote Y=∑i=1nXi∼Bin(n,p)By CLT ,Y−npnp(1−p)∼approxN(0,1)By MLE,L(p)=∏i=1npXi(1−p)1−Xi=p∑i=1nXi(1−p)n−∑i=1nXi=pY(1−p)n−Yℓ(p)=Yln⁡p+(n−Y)ln⁡(1−p)ℓ′(p)=0Yp−n−Y1−p=0Yp=Y−np−1Y(p−1)=p(Y−n)Yp−Y=pY−pnp^=Yn=185351≈0.527Y=np^P{−zα2≤Y−npnp(1−p)≤zα2}≈1−αP{−zα2≤n(p^−p)np(1−p)≤zα2}≈1−αP{−zα2≤n(p^−p)p(1−p)≤zα2}≈1−αP{−zα2≤p^−pp(1−p)n≤zα2}≈1−αP{−zα2p(1−p)n≤p^−p≤zα2p(1−p)n}≈1−αP{p^−zα2p(1−p)n≤p≤p^+zα2p(1−p)n}≈1−α

By Law of Large Number, p^→p.
Hence, we can use p^ to approximate p when n is large.
Then, the approximate 100(1−α)% CI is

p^±zα2p^(1−p^)n

Therefore,

p^≈0.527z0.025=1.96Approximate 95% CI for p=0.527±1.960.527(1−0.527)351=[0.475,0.579]

To measure the difference in proportions between 2 independent populations,

pi: Proportion in population i with a characteristic (Yini)
Yi: No. of successes in sample from population i
ni: Sample size in population i

E(Yini)=piVar(Yini)=pi(1−pi)ni

Hence,

E(Y1n1−Y2n2)=p1−p2Var(Y1n1−Y2n2)=p1(1−p1)n1+p2(1−p2)n2

When n1 and n2 is large, by CLT,

p^1−p^2∼N(p1−p2,p1(1−p1)n1+p2(1−p2)n2)(p^1−p^2)−(p1−p2)p1(1−p1)n1+p2(1−p2)n2∼N(0,1)P{−zα2≤(p^1−p^2)−(p1−p2)p1(1−p1)n1+p2(1−p2)n2≤zα2}≈1−α

By Law of Large Number, we can approximate pi by p^.
Hence, the approximate 100(1−α)% CI for p1−p2 is

p^1−p^2±zα2p^1(1−p^1)n1+p^2(1−p^2)n2

Example

Let p1 be the proportion of male students into gaming, and p2 be the proportion of female students into gaming.
Suppose p^1=0.6,p^2=0.4.
When n1=2000,n2=2200, please construct approximate 95% CI for p1−p2.

The approximated 95% CI for p1−p2 is given by

0.6−0.4±z0.0250.6(1−0.6)2000+0.4(1−0.4)2200=0.2±1.960.6(0.4)2000+0.4(0.6)2200=[0.17,0.23]

Sample Size Determination

动机: 由于样本量多会增加成本,而样本量少会影响预测的准确度。因此我们需要找出在指定精度下,最少的样本量是多少。

Normal Distribution (σ2 Known)

For X1,⋯,Xn∼N(μ,σ2) and σ2 is known, the 100(1−α)% CI for μ is

x¯±zα2σn

zα2σn is called half-width, as well as margin of error or max. error of the estimate

Note

The smaller the half-width zα2σn, the more accurate the estimate.

We requires the half-width must be less than a given tolerance ϵ in precision

zα2σn≤ϵn≥zα22σ2ϵ2

Example

A psychology study uses standardized memory tests with known standard deviation σ=12.
Find the minimum sample size n needed for a 95% confidence interval with a margin of error at most 2.

n≥z0.0252(12)222n≥138.3

Hence, the minimum sample size is 139 students.

Normal Distribution (σ2 Unknown)

When σ2 is unknown, the 100(1−α)% CI is

x¯±tα2(n−1)sn

tα2(n−1)sn is the half-width.
Hence,

tα2(n−1)sn≤ϵn≥tα22(n−1)s2ϵ2

However, there are 2 issues

n≥zα22(sp2)ϵ2

Proportion

The approximate CI for proportion p is

p^±zα2p^(1−p^)n

Let the required precision be ϵ.

zα2p^(1−p^)n≤ϵn≥zα22 p^(1−p^)ϵ2

However, p^ depends on n
Since p^ is unknown, we have 2 approach to approximate p^

n≥zα22 p∗(1−p∗)ϵ2 n≥zα2212(1−12)ϵ2≥zα224ϵ2
Proof

Prove p(1−p)≤14 by completing square.

p(1−p)=p−p2,p∈[0,1]=−(p2−p+14)+14=−(p−12)2+14∴p(1−p) attains its maximum at (12,14)

Example

A particular area contains 8000 apartment units.
In a preliminary survey, 12% of the respondents said they planned to sell their apartments within the next year.
We want to estimate the interval for the total number of owners planning to sell.
Suppose that a 95% confidence interval with the half-width less than 200 is desired. How many owners do we need to survey.

From now, we have

8000(z0.025p^(1−p^)n)≤200

Approximate p^ by p∗

8000(1.960.12(1−0.12)n)≤2001.960.1056n≤0.025n≥649.077

Hence, we need to survey at least 650 apartment owners