STEP 10 / 14

效應量與樣本數計算

Cohen's d、Hedges' g、Power analysis——讓「顯著」變成「重要」。

Cohen's d, Hedges' g, power analysis — turning "significant" into "meaningful."

為什麼必須報告效應量?

樣本量夠大時,連 0.1% 的差異也會「顯著」。效應量 (effect size) 才告訴你差異有多大、是否值得在生物學上關心。Cohen (1988) 在 Statistical Power Analysis for the Behavioral Sciences 提出 d=0.2/0.5/0.8 為 small/medium/large,但 2024 年 Giner-Sorolla 等 (Personality Soc Psych Rev) 建議改用 SESOI (Smallest Effect Size of Interest)——由領域決定何謂「值得」的效應。

Power analysis 由 Faul et al. 2007 (Behav Res Methods) 的 G*Power 3 普及;R 的 pwr 與 Python 的 statsmodels/pingouin 提供等效功能。Post hoc power(用觀察效應量回算功效)被 Hoenig & Heisey 2001 嚴正反對——它與 p 值一一對應,沒有提供新資訊。

With large n, even a 0.1% difference becomes "significant." Effect size tells you how big the difference is and whether it matters biologically. Cohen (1988) proposed d=0.2/0.5/0.8 as small/medium/large; Giner-Sorolla et al. 2024 (Personality Soc Psych Rev) advocate the SESOI (Smallest Effect Size of Interest) — let the field decide what counts as "meaningful."

Power analysis was popularized by G*Power 3 (Faul et al. 2007, Behav Res Methods); R's pwr and Python's statsmodels/pingouin are equivalent. Post hoc power (computed from observed effect size) is rejected by Hoenig & Heisey 2001 — it's one-to-one with the p-value and adds nothing.

🚨
禁忌:在拿到「不顯著」結果後跑 post hoc power 自我安慰;應改做 sensitivity analysis(給定 n 與 α,最小可偵測效應量)。Forbidden: Computing post hoc power to console yourself after a non-significant result. Instead do sensitivity analysis (given n and α, what's the smallest detectable effect).

一、常用效應量速查

效應量適用公式慣例
Cohen's d兩組均值差(M₁−M₂)/SD_pooled0.2 / 0.5 / 0.8
Hedges' g小樣本d × (1 − 3/(4df−1))同 d
η² / partial η²ANOVASS_effect / SS_total0.01 / 0.06 / 0.14
Pearson r連續相關cov(X,Y)/(SD_X·SD_Y)0.1 / 0.3 / 0.5
OR / RR類別結果odds₁/odds₀ ; risk₁/risk₀領域決定
Cliff's δ無母數P(X>Y) − P(Y>X)0.147 / 0.33 / 0.474

a priori 樣本量計算器(兩組 t-test)

給定預期效應量 d 與目標功效 (1−β),計算每組需要的樣本量(兩側 α=0.05, equal n)。

Given an expected effect size d and target power (1−β), compute required per-group sample size (two-sided α=0.05, equal n).

不同 n 對應的 power

二、效應量與 Power 計算

library(pwr); library(effectsize)

# 1. 效應量計算(兩組)
cohens_d(value ~ group, data=df)         # Cohen's d
hedges_g(value ~ group, data=df)         # 小樣本校正
cliffs_delta(value ~ group, data=df)     # 無母數

# 2. a priori 樣本量計算(兩組 t-test)
pwr.t.test(d=0.5, power=0.8, sig.level=0.05, type="two.sample")

# 3. ANOVA 樣本量
pwr.anova.test(k=4, f=0.25, power=0.8, sig.level=0.05)

# 4. Sensitivity(最小可偵測效應;給定 n、α、power)
pwr.t.test(n=20, power=0.8, sig.level=0.05, type="two.sample")$d

# 5. Mixed-effect / repeated measure 用 simr 模擬
library(simr)
powerSim(fit_lmer, nsim=100)
import pingouin as pg
from statsmodels.stats.power import TTestIndPower, FTestAnovaPower

# 1. 效應量
print(pg.compute_effsize(df.A, df.B, eftype="cohen"))    # Cohen's d
print(pg.compute_effsize(df.A, df.B, eftype="hedges"))   # Hedges' g
print(pg.compute_effsize(df.A, df.B, eftype="CLES"))     # common language effect

# 2. a priori 樣本量(兩組 t-test)
analysis = TTestIndPower()
n = analysis.solve_power(effect_size=0.5, power=0.8, alpha=0.05)
print(f"每組需要 n ≈ {n:.0f}")

# 3. ANOVA 樣本量
anova_pow = FTestAnovaPower()
n_per = anova_pow.solve_power(effect_size=0.25, k_groups=4, power=0.8, alpha=0.05)

# 4. Sensitivity
d_min = analysis.solve_power(nobs1=20, power=0.8, alpha=0.05)
print(f"n=20 時可偵測最小 d = {d_min:.2f}")

三、最常見錯誤

Post hoc power 自慰

用觀察 effect size 算 power 與 p 一一對應,毫無新資訊。改做 sensitivity analysis 或 equivalence test。

Power computed from observed ES is 1-to-1 with p — uninformative. Do sensitivity analysis or equivalence testing instead.

效應量不附 CI

d = 0.5 (95% CI: 0.1 – 0.9) 與 d = 0.5 (95% CI: 0.48 – 0.52) 訊息天差地遠。永遠報告 CI。

d = 0.5 (95% CI 0.1–0.9) vs d = 0.5 (95% CI 0.48–0.52) carry very different information. Always report CIs.

盲套 Cohen 0.2/0.5/0.8

不同領域典型效應量差異極大。如老年學 Brydges 2019 重估 small/medium/large 應為 0.16/0.38/0.76。

Typical effects vary by field. Brydges 2019 re-estimated gerontology cutoffs as 0.16/0.38/0.76.

80% power 視為定律

80% 是慣例非定律。重大臨床試驗常用 ≥ 90%;探索性 pilot 可接受 60-70%。

80% is convention, not law. Pivotal trials often use ≥ 90%; exploratory pilots can accept 60–70%.

🎯 章末小測驗

1. n=10 t-test p=0.4 應做?

Post hoc power
Sensitivity analysis
刪 3 樣本重算
改無母數

2. 小樣本兩組比較最佳 ES?

Cohen's d
Hedges' g
η²
Pearson r

3. 效應量報告必附?

p value
95% confidence interval
SEM