近似捷径

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 中的分类数据推断

近似示意图一

R 中的分类数据推断

近似示意图二

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