COM6005 Statistical Modeling · Module 3
Confidence Interval & Hypothesis Testing: Concepts
COM6005 · Module 3 · Source: M3_CI_HT_Concepts_v2_L02_complete.pdf (24 slides,by Carlin Chu)
Contents · 12 sections
🎯 本講重點 (Learning outcomes)
- 分清 point estimate 同 interval estimate;理解 unbiasedness 。
- 由 sampling distribution(Central Limit Theorem)推導 Confidence Interval,並正確解讀 95% 嘅意思。
- 識計 Z-based 同 t-based CI,識查 critical value(1.645 / 1.96 / 2.576)。
- 理解 Hypothesis testing 嘅邏輯:、significance level 、p-value、rejection region、one-tailed vs two-tailed。
- Type I error ()、Type II error ()、Power ();statistical vs practical significance。
- CI 同 Hypothesis test 係「同一個銀幣嘅兩面」。
⭐ 考試必溫 Top-5
- CI 公式:( known)或 ,同埋 slide 11 嘅推導。
- 95% CI 嘅正確解讀:重複呢個 procedure 好多次,95% 嘅 interval 會 cover 真正 (唔係「 有 95% 機會喺呢個 interval」)。
- p-value 定義:假設 成立,得到 equal to or more extreme 結果嘅 conditional probability; → reject 。
- Type I / Type II error / Power 表, = Type I error = significance level。
- One-tailed vs two-tailed 嘅 寫法同 rejection region;95% CI 唔包 ⇔ two-tailed test 。
1. 乜嘢係 Confidence Interval?(Candy Jar)
Slide 2:老師帶咗一大罐朱古力入課室,問「入面有幾多粒?」
- The Exact Guess (Not a CI):你估「500」。要 100% 啱好難——真數係 501 你都錯。
- The Confidence Interval (Range Guess):「我有 95% 信心粒數喺 450 至 550 之間。」
- The Interval:450 至 550 呢個 range estimate。
- The Confidence Level:95% 即係如果你用同一種聰明方法估 100 個唔同嘅罐,大約有 95 次個 range 會估啱。
科學家數唔晒全世界,就測試一小組(sample),再為所有人(population)俾一個「安全 range」。
2. Point estimate 同 Unbiasedness
Inferential statistical process(slide 3):
- Point estimate:sample statistic → population parameter,即 。
- Inductive reasoning:用 sample 去總結 population 嘅特徵。
- Point estimator 常見嘅性質:Unbiasedness ——「好多個」sample mean 嘅平均 = 真正 population mean。每個 sample 只會俾一個特定嘅 point estimate。
Slide 4 “Which one is ‘correct’??”:三個 sample 分別得到 ,如果只信 point estimate,就會分別得出「population mean 係 12 / 10 / 13」——三個答案互相矛盾,冇一個肯定啱。
3. 點解需要 Confidence Interval?
Slide 5:
- 實務上通常只有一個 sample,結果幾乎肯定(almost surely)同真值唔同。
- 點樣更好咁估 population parameter?→ Interval estimate。
- Interval estimate 建基於 sampling distribution 嘅統計性質,例如 Central Limit Theorem:sample mean is normally distributed。
- Meaning of C.I.:95% of the results from the C.I. procedure will contain the true population mean → the C.I. procedure is good to be used。
就算原始數據唔係 normal,只要 n 夠大, 嘅 sampling distribution 都近似 。 叫 standard error:n 越大, 越集中喺 附近,CI 越窄。
3.1 Notation(slide 6)
| Mean | Standard deviation | |
|---|---|---|
| Population | mu () | Sigma () or |
| Sample | x-bar () | or |
4. Interval estimate 公式
Slide 7 嘅 t-based interval( 未知,用 sample SD s):
各部分(slide 7 標註): = sample mean; = sample SD; = sample size; = distribution value(critical value)。Slide 7 用三個 sample()各自砌出一個 interval(例如 10–14、7.5–12.5、12–14),表示「95% of chance that the population mean falls in the interval」——每個 sample 嘅 interval 都唔同,有啲 cover 到真 、有啲 cover 唔到。
4.1 Boundary、alpha 同 tails(slides 8–10)
- Slide 8:standard normal 曲線下面積 = probability,例如 (左尾陰影)同 (其餘部分);兩者加埋 = 1。
- Slide 9(Two tail case): 分喺左尾同右尾兩邊,中間係 。
- Slide 10(Empirical rule):
- 約 68.3% 數據喺 之內
- 約 95.5% 喺 之內
- 約 99.7% 喺 之內
“What is alpha for 6 sigma?”(即 至 ,總闊度 )→ 0.3%。
每段面積: 至 各 34.1%; 至 各 13.6%; 至 各 2.1%; 以外各 0.1%。
4.2 由 sampling distribution 推導 CI(slide 11)
假設 normally distributed 而 已知:
- 由 standard normal 開始:中間面積 。
- 代入 。
- 乘 ,再減 。
- 乘 −1(不等號反轉)。
- 整理成 。
| Confidence level | (two-sided) | (one-sided) | |
|---|---|---|---|
| 90% | 0.10 | 1.645 | 1.282 |
| 95% | 0.05 | 1.96 | 1.645 |
| 99% | 0.01 | 2.576 | 2.326 |
(呢啲數就係 t-table 最底 ∞ 嗰行;Python:stats.norm.ppf(0.975) = 1.96。)
4.3 Worked example:計 CI
。求 嘅 95% 同 99% CI。
- Standard error:( 大,用 z 近似)
- 95%: → margin of error = 1.96 × 0.1732 = 0.3395
- 95% CI = 13 ± 0.3395 = (12.66, 13.34)
- 99%:2.576 × 0.1732 = 0.4462 → 99% CI = (12.55, 13.45)(confidence 越高,interval 越闊)
,,。求 95% CI。
- ;查 t-table (two-sided 95%)→
- Margin = 2.262 × 0.8381 = 1.896
- 95% CI = 1.74 ± 1.896 = (−0.156, 3.636)
4.4 正確解讀 CI(slide 12)
Given a set of random sample, you can follow the above procedure to construct an interval to ‘cover’ the true underlying parameter. If the procedure is repeated for hundreds of times, ()% of the constructed intervals will cover the true value.
係一個固定(但未知)嘅數,唔係 random;random 嘅係 interval。所以嚴格嚟講唔應該話「 有 95% 機會喺 (12.66, 13.34) 入面」,而應該話「用呢個 procedure 砌出嚟嘅 interval,長遠有 95% 會 cover 」。
5. Hypothesis Testing 嘅推理(Coin Toss Challenge)
Slide 14:朋友擲硬幣連續 5 次 Heads,你懷疑個硬幣有古惑。
- (Null Hypothesis,Boring Idea):硬幣完全正常,佢只係好彩。
- (Alternative Hypothesis,Detective Idea):硬幣被做咗手腳,傾向出 Heads。
- The Math Check:假設公平硬幣 ,。
- The Decision:3% 對「純粹好彩」嚟講太低 → reject ,硬幣好大機會有古惑。但即使 其實啱,都有機會判錯(have risk even is correct)。
- Pre-specified acceptable level of risk = significance level ;0.03125 < 0.05 → reject。
Hypothesis testing 就係一個正式、逐步嘅方法去問:「呢個證據夠唔夠強去支持新理論,定只係巧合?」
5.1 Hypothesis 同 probability(slide 15)
- Population characteristic 嘅可能狀態叫 hypothesis,例如 ;。
- Hypothesis testing 嘅「probability」係 conditional probability:假設 null 為真,得到 equal to or more extreme 結果嘅機率。
- 佢 NOT 係 發生嘅機率。要計「某個 state 發生嘅機率」要用 Bayesian approach(out of scope)。
5.2 Logic of Hypothesis testing(slide 16)
- 根據 sampling distribution 作「induced judgement」:observed sample statistic → population parameter;observed values → 或 。
- 假設 為真,有幾大機會見到咁嘅結果?如果機會低過預先指定嘅 significance level ,就 reject null,改為接受 alternative。→ 有機會作出錯誤結論。
- 研究者通常將佢嘅「hope」放喺 alternative hypothesis;reject null 時 hope 就得到支持。
- Significance level = Type I error。
6. Type I、Type II error 同 Power
| Test result \ Actual situation | is false( 真) | is true |
|---|---|---|
| Reject (+ve) | TP:Power () ✔ | FP:Type I error () ✘ |
| Do not reject (−ve) | FN:Type II error () ✘ | TN:() ✔ |
- Type I () error:Incorrect rejection of a true null hypothesis. 。
- Type II () error:Fail to reject a false null hypothesis. 。
- Power ():Correctly reject the null when it is wrong. 。
= 被告無罪。Type I error = 冤枉好人(判有罪但其實無罪);Type II error = 放走犯人。 係我哋願意承受冤枉好人嘅風險,所以要定得細(0.05 / 0.01)。降低 通常會令 上升;增加 sample size 可以同時降低兩者(提升 power)。
Slide 17 嘅表用咗 classification 嘅 TP/FP/FN/TN 標籤,「positive」= reject 。原 slide 欄位標題寫法有啲反轉(“True ( is wrong)” / “False ( is correct)”),記住核心: 啱但 reject = Type I; 錯但唔 reject = Type II。
COM6004 Classification 嘅 confusion matrix:FP rate 對應 ,FN rate 對應 ,Recall / Sensitivity (TP rate) 對應 Power。同一個 2×2 結構!
7. Statistical vs Practical significance
Slide 18:
- Reject 時,我哋話 subject of interest 係 statistically significant。
- Statistical significance:表示個 effect 唔係由 chance 造成。
- Statistical significance ≠ practical significance:一個好細嘅 coefficient,practical significance 好細,但如果 sample size 好大,都可以 highly statistically significant。
一個新教學法令考試平均分高 0.3 分(滿分 100)。如果 ,standard error 極細,p-value 可以 < 0.001(statistically significant),但 0.3 分喺實際上冇乜意義(practically insignificant)。
8. p-value、significance level 同 rejection region
p-value = (conditional) probability of obtaining a (any) result which is ‘equal to or more extreme’ than what was actually observed, when the null hypothesis is true.
Slide 例子::Population mean ;observed ; = 另一組新 random data 嘅結果:
p-value 可以用嚟作判斷:p-value 落喺某範圍(significance level)就 reject null → Regions of Rejection and Non-rejection。
Slide 20:
- Significance level (= 0.05, 0.1):假設 正確,出現嗰啲極端值嘅機率;亦即我哋願意承受作出「錯誤」決定(Type I error)嘅 risk—— 正確但我哋結論佢錯。
- p-value:假設 正確,數據出現比目前 sample 更極端值(圖中右手邊)嘅機率。
- Slide 20 嘅圖:sampling distribution of , 嘅 critical line,p-value = 0.011(右尾橙色面積)。p-value 細過 → is rejected。
- 係接受錯誤結論( 啱都 reject)嘅 risk;p-value 細過 ,即呢個 risk 可以接受 → reject 。
- State hypotheses:;(right-tailed)。
- Significance level:。
- Test statistic:。
- Critical value / p-value:right-tailed → ;p-value = 。
- Decision & conclusion:17.32 > 1.645(或 )→ reject 。有充分證據顯示 population mean 大於 10。
8.1 One-tailed vs Two-tailed(slide 21)
| Test Type | Hypotheses | Rejection Region | Critical value(, Z) |
|---|---|---|---|
| Two-Tailed | ; | 兩邊尾,每邊 | |
| Right-Tailed | ; | 右尾 | |
| Left-Tailed | ; | 左尾 |
規則:等號永遠喺 ; 嘅方向(、、)決定 rejection region 喺邊。
- 將「hope」放咗喺 :例如想證明新藥有效, 先係「有效」。
- Two-tailed 用錯 critical value: two-tailed 要查 (1.96),唔係 1.645。
- 結論寫「accept 」:應寫「do not reject / fail to reject 」——冇足夠證據唔等於證明 啱。
9. Confidence Interval vs Hypothesis Testing
Slides 22–24(provided by Google AI):
| Confidence interval | Hypothesis testing |
|---|---|
| gives a range of plausible values for an unknown population parameter | decides whether a specific claim about a population is supported by sample data |
- A 95% confidence interval corresponds to an significance test.
- If a 95% CI excludes the null hypothesis value, the two-tailed test will yield (statistically significant, reject ).
- If the CI includes the null value, (fail to reject ).
例:slide 19 數據嘅 95% CI = (12.66, 13.34),唔包 10 → two-tailed test 會 reject()。如果 ,13 喺 CI 入面 → do not reject。
10. 總結:Hypothesis testing 5-step procedure
- State and (mutually exclusive、collectively exhaustive;等號喺 ;判斷 one- / two-tailed)。
- Choose significance level (通常 0.05 或 0.01)。
- Compute the test statistic(z、t、、F)。
- Find the critical value from the table(或計 p-value)。
- Decision & conclusion in context:test statistic 落 rejection region(或 )→ reject ;否則 do not reject 。用題目語境寫結論。
自我測驗 Self-test
Q1. ,,(known)。求 嘅 95% CI。
;margin = 1.96 × 1 = 1.96;95% CI = (50.04, 53.96)。
Q2. 同上,如果要 90% CI 呢?比較兩者闊度。
→ 52 ± 1.645 = (50.355, 53.645)。90% CI 較窄:confidence 低啲,interval 窄啲。
Q3. 有人話「95% CI (50.04, 53.96) 代表 有 95% 機率喺 50.04 同 53.96 之間」。啱唔啱?
嚴格嚟講唔啱。 係固定值;正確講法:如果重複抽樣並用同一 procedure 砌好多個 interval,約 95% 嘅 interval 會 cover 真正 (slide 12)。
Q4. 解釋 Type I error、Type II error、Power,並講 同邊個有關。
Type I: 真但 reject(機率 = significance level)。Type II: 假但冇 reject(機率 )。Power = : 假時正確 reject。
Q5. 某廠聲稱電池平均壽命至少 500 小時,你想證明佢誇大。寫 同 ,係咩 tail?
;。Left-tailed test。
Q6. 一個 two-tailed test 得 p-value = 0.03。 同 時結論各係咩?對應 95% / 99% CI 會唔會包 ?
:0.03 < 0.05 → reject ;95% CI 唔包 。:0.03 > 0.01 → do not reject;99% CI 包 。
Q7. 擲硬幣 5 次全部 Heads。假設公平,p-value 係幾多(one-sided)? 結論?
p-value = → reject ,結論硬幣傾向出 Heads(但有 嘅 Type I 風險)。
Q8. 「,回歸係數 0.0001,」。點評?
Statistically significant 但 practical significance 可能好細:sample size 極大時,極細嘅 effect 都會顯著(slide 18)。
Q9. 「6 sigma」嘅 係幾多?點解?
(闊 )包含約 99.7% 數據,所以 。
一頁總結 Cheat sheet
- Point estimate:;unbiased:。
- CLT:,。
- CI:; 未知 → 。z:90% 1.645|95% 1.96|99% 2.576。
- 解讀:重複 procedure,() 嘅 interval cover 真值。
- 68.3–95.5–99.7 rule;6 sigma 。
- = boring idea(有等號); = researcher's hope。
- p-value = P(結果 ≥ 觀察值咁極端 | 真);唔係 P( 真)。 → reject 。
- Type I = reject 真 ();Type II = 唔 reject 假 ();Power = 。
- Two-tailed:,;Right:,;Left:,()。
- Statistical ≠ practical significance(大 n 令細 effect 都顯著)。
- 95% CI 唔包 ⇔ two-tailed ⇔ reject 。
- 5 steps: → → test statistic → critical value / p-value → decision + conclusion。