近似の近道

R によるカテゴリカルデータの推測

Andrew Bray

Assistant Professor of Statistics at Reed College

信頼区間

SE
0.009998905
SE_small_n
0.03809731
SE_low_p
0.00547912

標準誤差が大きくなる条件

  • n が小さい
  • p が 0.5 に近い
R によるカテゴリカルデータの推測

近似の図1

R によるカテゴリカルデータの推測

近似の図2

R によるカテゴリカルデータの推測

正規分布

いわゆる「ベルカーブ」。

【もし】

  • 観測が独立
  • n が大きい

【なら】

  • $\hat{p}$ は正規分布に従う

正規曲線

R によるカテゴリカルデータの推測

標準偏差

$$\sqrt{\frac{ \hat{p} \times (1 - \hat{p})}{n}}$$

R によるカテゴリカルデータの推測

仮定の確認

「観測が独立」かはどう確認しますか?

  • 収集方法によります。

「n が大きい」とは?

  • $n \times \hat{p} \gt 10$
  • $n \times(1 - \hat{p}) \gt 10$
R によるカテゴリカルデータの推測

標準誤差の計算:近似

p_hat <- gss2016 %>%
  summarize(mean(happy == "HAPPY")) %>%
  pull()
n <- nrow(gss2016)
c(n * p_hat, n * (1 - p_hat))
116  35
SE_approx <- sqrt(p_hat * (1 - p_hat) / n)
SE_approx
0.03418468
R によるカテゴリカルデータの推測

標準誤差の計算:計算による推定

boot <- gss2016 %>%
  specify(response = happy, success = "HAPPY") %>%
  generate(reps = 500, type = "bootstrap") %>%
  calculate(stat = "prop")
SE_boot <- boot %>%
  summarize(sd(stat)) %>%
  pull()
SE_boot
0.03176741
R によるカテゴリカルデータの推測

標本分布

ggplot(boot, aes(x = stat)) +
  geom_density()

密度曲線

R によるカテゴリカルデータの推測

標本分布

ggplot(boot, aes(x = stat)) +
  geom_density() +
  stat_function(fun = dnorm, 
                color = "purple",
                args = 
                  list(mean = p_hat,
                       sd = SE_approx))

密度曲線と正規近似

R によるカテゴリカルデータの推測

標本分布

ggplot(boot, aes(x = stat)) +
  geom_density() +
  stat_function(fun = dnorm, 
                color = "purple",
                args = 
                  list(mean = p_hat,
                       sd = SE_approx))

密度曲線と正規近似

R によるカテゴリカルデータの推測

Ayo berlatih!

R によるカテゴリカルデータの推測

Preparing Video For Download...