別法:カイ二乗分布

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...