Sampling in R
Richie Cotton
Data Evangelist at DataCamp
ggplot(coffee_boot_distn, aes(resample_mean)) +
geom_histogram(binwidth = 0.002)
coffee_boot_distn %>%
summarize(
mean_resample_mean = mean(resample_mean)
)
# A tibble: 1 x 1
mean_resample_mean
<dbl>
1 7.5263
coffee_boot_distn %>%
summarize(
mean_resample_mean = mean(resample_mean),
mean_minus_1sd = mean_resample_mean - sd(resample_mean),
mean_plus_1sd = mean_resample_mean + sd(resample_mean)
)
# A tibble: 1 x 3
mean_resample_mean mean_plus_1sd mean_minus_1sd
<dbl> <dbl> <dbl>
1 7.5263 7.5355 7.5171
coffee_boot_distn %>%
summarize(
lower = quantile(resample_mean, 0.025),
upper = quantile(resample_mean, 0.975)
)
# A tibble: 1 x 2
lower upper
<dbl> <dbl>
1 7.5087 7.5447
normal_inv_cdf <- tibble(
p = seq(-0.001, 0.999, 0.001),
inv_cdf = qnorm(p)
)
ggplot(normal_inv_cdf, aes(p, inv_cdf)) +
geom_line()
coffee_boot_distn %>% summarize( point_estimate = mean(resample_mean), std_error = sd(resample_mean),
lower = qnorm(0.025, point_estimate, std_error), upper = qnorm(0.975, point_estimate, std_error)
)
# A tibble: 1 x 4
point_estimate std_error lower upper
<dbl> <dbl> <dbl> <dbl>
1 7.5263 0.0091815 7.5083 7.5443
Sampling in R