替代方法:卡方分配

R 中的類別資料推論

Andrew Bray

Assistant Professor of Statistics at Reed College

近似分配:常態

  • 統計量:$\hat{p}, \hat{p}_{1} - \hat{p}_{2}$

常態曲線

R 中的類別資料推論

近似分配:卡方

  • 統計量:$\hat{x}^{2}$
  • 形狀由自由度決定
  • $df = (nrows - 1) \times (ncols - 1)$

卡方曲線

R 中的類別資料推論

以近似進行 H 檢定

null_spac <- gss_party %>%
  specify(natspac ~ party) %>%
  hypothesize(null = "independence") %>%
  generate(reps = 100, type = "permute") %>%
  calculate(stat = "Chisq")
ggplot(null_spac, aes(x = stat)) +
  geom_density() +
  stat_function(
    fun = dchisq, 
    args = list(df = 4), 
    color = "blue"
  ) +
  geom_vline(xintercept = chi_obs_spac, color = "red")

近似檢定示意圖

R 中的類別資料推論

以近似進行 H 檢定

gss_party %>%
  select(natarms, party) %>%
  table()
             party
natarms        D  I  R
  TOO LITTLE  17 20 24
  ABOUT RIGHT 14 28  8
  TOO MUCH    12 24  2
pchisq(chi_obs_spac, df = 4)
X-squared 
0.1430612
1 - pchisq(chi_obs_spac, df = 4)
X-squared 
0.8569388

近似檢定示意圖

R 中的類別資料推論

卡方分配

在下列情況下近似良好:

  • $expected\_count >= 5$
  • $df >= 2$

卡方曲線

R 中的類別資料推論

一起來練習吧!

R 中的類別資料推論

Preparing Video For Download...