便利抽样

R 中的抽样

Richie Cotton

Data Evangelist at DataCamp

《Literary Digest》的选举预测

1936 年《Literary Digest》头版,标题为选举预测。预计兰登获 130 万票,罗斯福略低于 100 万票。

  • 预测:兰登 57%;罗斯福 43%
  • 实际:兰登 38%;罗斯福 62%
  • 样本不代表总体,导致样本偏差。
  • 以最省事的方法收集数据称为便利抽样。
R 中的抽样

估计法国人的平均年龄

巴黎迪士尼乐园的照片。

  • 在巴黎迪士尼调查 10 人。
  • 其平均年龄为 24.6 岁。
  • 这能很好地估计全法国吗?
1 图片:Sean MacEntee
R 中的抽样

这次调查有多准确?

年份 法国平均年龄
1975 31.6
1985 33.6
1995 36.2
2005 38.9
2015 41.2
  • 24.6 岁是个很差的估计。
  • 去迪士尼的人不代表整体人口。
R 中的抽样

便利抽样:咖啡评分

coffee_ratings %>% 
  summarize(mean_cup_points = mean(total_cup_points))
  mean_cup_points
1           82.09
coffee_ratings_first10 <- coffee_ratings %>% 
  slice_head(n = 10)
coffee_ratings_first10 %>% 
  summarize(mean_cup_points = mean(total_cup_points))
  mean_cup_points
1            89.1
R 中的抽样

可视化选择偏差

coffee_ratings %>%
  ggplot(aes(x = total_cup_points)) +
  geom_histogram(binwidth = 2)

总体杯分的直方图。

coffee_ratings_first10 %>%
  ggplot(aes(x = total_cup_points)) +
  geom_histogram(binwidth = 2) +
  xlim(59, 91)

样本杯分的直方图。

R 中的抽样

可视化选择偏差 2

coffee_ratings %>%
  ggplot(aes(x = total_cup_points)) +
  geom_histogram(binwidth = 2) 

总体杯分的直方图。

coffee_ratings %>%
  slice_sample(n = 10) %>% 
  ggplot(aes(x = total_cup_points)) +
  geom_histogram(binwidth = 2) +
  xlim(59, 91)

随机样本的杯分直方图。

R 中的抽样

Passons à la pratique !

R 中的抽样

Preparing Video For Download...