STEP 7 / 14

假設檢定

t-test、ANOVA、無母數——選對檢定、解對 p 值、超越「p < 0.05」的二元思維。

t-test, ANOVA, non-parametric — picking the right test, reading the right p, beyond binary "p < 0.05" thinking.

為什麼還要學假設檢定?

ASA 在 2016 年發表「The ASA's Statement on p-Values」(Wasserstein & Lazar, Am Stat),明確指出 6 大原則,包括「p 值不能衡量假設為真的機率」、「p < 0.05 不等於重要」。2019 年補充聲明 (Am Stat) 建議「不要再以 p < 0.05 作為唯一決策依據」。

同年 Delacre, Lakens & Leys (2017, Int Rev Soc Psychol) 指出「預設用 Welch's t-test」優於 Student's t-test,因為 Welch 不假設等變異數,且在等變異時功效幾乎相同。Bootstrap 與 permutation tests 在小樣本與非常態下提供穩健替代。

The ASA's 2016 Statement on p-Values (Wasserstein & Lazar, Am Stat) laid out six principles, including "p-values are not the probability the hypothesis is true" and "p < 0.05 ≠ important." A 2019 follow-up urged: "stop using p < 0.05 as a sole decision rule."

The same year, Delacre, Lakens & Leys (2017, Int Rev Soc Psychol) showed that Welch's t-test should be the default over Student's — it doesn't assume equal variances and matches Student's power when variances are equal. Bootstrap and permutation tests give robust alternatives for small / non-normal samples.

⚠️
不要做的事:看到 p=0.06 稱「marginally significant」;把「p > 0.05」當作「沒差異」;用 p 值比較「顯著與不顯著」的差異(互動效應需另做測試)。Don'ts: Call p=0.06 "marginally significant"; treat p > 0.05 as "no difference"; compare "significant vs not significant" claims to infer interaction (test the interaction directly).

一、如何選對檢定

兩組比較

Q1.

三組以上比較

Q.

類別資料

三者之間的舞蹈

調整效應量與樣本量,觀察 p 值變化。關鍵:大樣本下,幾乎所有非零的真實差異都會「顯著」;報告效應量與 CI 比 p 值更有意義。

Adjust effect size and n — watch p change. Key: at large n, any non-zero real difference becomes "significant"; effect size + CI matters more than p.

二、R / Python 程式碼對照

# 預設 Welch's t-test(不假設等變異)
t.test(value ~ group, data=df)               # var.equal=FALSE 為預設

# 配對 t-test
t.test(df$post, df$pre, paired=TRUE)

# 無母數
wilcox.test(value ~ group, data=df)          # Mann-Whitney U
wilcox.test(df$post, df$pre, paired=TRUE)    # Wilcoxon signed-rank

# ANOVA + post-hoc
fit <- aov(value ~ group, data=df)
summary(fit)
TukeyHSD(fit)
kruskal.test(value ~ group, data=df)          # 無母數版
library(FSA); dunnTest(value ~ group, data=df, method="bh")

# 類別資料
chisq.test(table(df$group, df$outcome))
fisher.test(table(df$group, df$outcome))      # 小樣本

# Bootstrap 95% CI of mean difference
library(boot)
diff_fn <- function(d, i) mean(d$value[i & d$group=="A"]) - mean(d$value[i & d$group=="B"])
b <- boot(df, diff_fn, R=5000)
boot.ci(b, type="bca")
import pingouin as pg, scipy.stats as stats

# Welch's t-test — pingouin 一行給效應量 + BF
print(pg.ttest(df.value[df.group=="A"], df.value[df.group=="B"], correction=True))

# 配對
print(pg.ttest(df.post, df.pre, paired=True))

# 無母數
stats.mannwhitneyu(df.value[df.group=="A"], df.value[df.group=="B"])
stats.wilcoxon(df.post, df.pre)

# ANOVA + post-hoc
print(pg.anova(data=df, dv="value", between="group"))
print(pg.pairwise_tukey(data=df, dv="value", between="group"))
stats.kruskal(*[g.value for _,g in df.groupby("group")])

# 類別
stats.chi2_contingency(pd.crosstab(df.group, df.outcome))
stats.fisher_exact([[a,b],[c,d]])

# Bootstrap 95% CI
import numpy as np
diffs = [np.mean(np.random.choice(A,len(A),replace=True))-
         np.mean(np.random.choice(B,len(B),replace=True))
         for _ in range(5000)]
np.percentile(diffs,[2.5,97.5])

三、p 值不是什麼

#原則
1可指示資料與模型的不相容程度
2不是「假設為真」的機率
3不應只用閾值決策
4需完整報告與透明
5不衡量效應/重要性
6不是充分證據

🎯 章末小測驗

1. 兩組獨立樣本預設檢定?

Student's t-test
Welch's t-test
Paired t-test
Wilcoxon signed-rank

2. ASA 2016 的核心訊息?

廢除 p 值
不可作唯一決策
只能 Bayesian
取代效應量

3. 2×2 期望次數 < 5 用?

Chi-square test
Fisher's exact test
Two-sample t-test
ANOVA