点估计的相对误差

R 中的抽样

Richie Cotton

Data Evangelist at DataCamp

样本是行数

coffee_ratings %>% 
  slice_sample(n = 300) %>% 
  nrow()
300
coffee_ratings %>% 
  slice_sample(prop = 0.25) %>% 
  nrow()
334
R 中的抽样

不同样本量

coffee_ratings %>% 
  summarize(mean_points = mean(total_cup_points)) %>% 
  pull(mean_points)

82.15
coffee_ratings %>% 
  slice_sample(n = 10) %>% 
  summarize(mean_points = mean(total_cup_points)) %>% 
  pull(mean_points)
82.82
coffee_ratings %>% 
  slice_sample(n = 100) %>% 
  summarize(mean_points = mean(total_cup_points)) %>% 
  pull(mean_points)
82.02
coffee_ratings %>% 
  slice_sample(n = 1000) %>% 
  summarize(mean_points = mean(total_cup_points)) %>% 
  pull(mean_points)
82.16
R 中的抽样

相对误差

总体参数

population_mean <- coffee_ratings %>% 
  summarize(mean_points = mean(total_cup_points)) %>% 
  pull(mean_points)

点估计

sample_mean <- coffee_ratings %>% 
  slice_sample(n = sample_size) %>% 
  summarize(mean_points = mean(total_cup_points)) %>% 
  pull(mean_points)

相对误差(百分比)

100 * abs(population_mean - sample_mean) / population_mean
R 中的抽样

相对误差 vs. 样本量

ggplot(errors, aes(sample_size, relative_error)) +
  geom_line() +
  geom_smooth(method = "loess")

相对误差与样本量的散点图。

R 中的抽样

开始练习!

R 中的抽样

Preparing Video For Download...