Need Greater Confidence in Your Confidence Intervals?

栏目: IT技术 · 发布时间: 4年前

内容简介:For those catching up here, bootstrap sampling refers to the process of sampling a given dataset ‘with replacement’… And this is where most people get lost. You take many samples and build a distribution to mark your confidence interval.Let’s take a quick

What is Bootstrap Replication Anyway?

Apr 27 ·3min read

Need Greater Confidence in Your Confidence Intervals?

by Peter H on Pixabay.com

What is Bootstrap Replication?

For those catching up here, bootstrap sampling refers to the process of sampling a given dataset ‘with replacement’… And this is where most people get lost. You take many samples and build a distribution to mark your confidence interval.

Let’s take a quick example.

Crypto at College

Let’s say that you want to find out how the general population at a college feels about cryptocurrency; well, you likely won’t be able to gather responses from everybody in the school; what will probably happen is that you’ll distribute some survey and you’ll get back a handful of responses that you hope are indicative of the general populous’ opinion, good or bad.

While you have a clear idea about the distribution among your respondents, you want to generate a realistic confidence interval that would be more indicative of the entire school. This is where boostrap replication comes in!

Sampling with Replacement

So far we know that bootstrap replication is a sampling approach. The main idea here being that when one sample is selected, it can be selected over and over again. This serves the purpose of re-creating the random re-occurrence of a respondent type that may actually be due to random chance.

Each bootstrap sample is called a replication. In this case, lets assume 1000 replications.

Once we have our 1000 replicates or samples, we now have 1000 values for the sample mean.

From this distribution, we’ll get our actual confidence interval.

Let’s say we want a confidence interval of 95%; we would get this by looking at our bootstrap distribution and taking the 2.5th value and the 97.5th value the act as our interval.

Let's Look at Some Code!

library(infer) 
replicates <- crypto_opinions %>% 
    specify(response = opinion, success = "positive") %>% 
    generate(reps = 1, type = "bootstrap")replicates %>% 
    summarize(prop_high = mean(response == 'positive')) %>% 
    pull()

We use specify to isolate the response variable we care about and what the variable value determines 'success'. From there we use generate to create our first bootstrap replicate. You'll also notice that we specify the type as bootstrap . We then use summarize and pull to generate a proportion of the specified level 'positive'.

replicates <- crypto_opinions %>% 
    specify(response = opinion, success = "positive") %>%        generate(reps = 1000, type = "bootstrap")%>% calculate(stat = "prop")

Similar to the former code block, we’ve expanded our repetitions to 1000 and are now chaining in the calculate function. The calculate function creates a data frame with one record for each replicate "stat" that corresponded to that replicate.

ggplot(replicates, aes(stat)) +
   geom_density()

Need Greater Confidence in Your Confidence Intervals?

The above chart shows you the density chart or distribution of the average outcome per each replicate.

From here it’s just a simple matter of calculating, the standard deviation and using that to identify the top and bottom of your range!

Lower_bound <- mean(replicates$stat) - sd(replicates$stat) * 2 upper_bound <- mean(replicates$stat) + sd(replicates$stat) * 2

Conclusion

I hope you’ve enjoyed this post and that it saves you some time! Please share whatever works and whatever doesn’t!

Feel free to check out some of my other posts at datasciencelessons.com

Happy Data Science-ing!


以上所述就是小编给大家介绍的《Need Greater Confidence in Your Confidence Intervals?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

JavaScript and Ajax for the Web, Sixth Edition

JavaScript and Ajax for the Web, Sixth Edition

Tom Negrino、Dori Smith / Peachpit Press / August 28, 2006 / $24.99

Book Description Need to learn JavaScript fast? This best-selling reference’s visual format and step-by-step, task-based instructions will have you up and running with JavaScript in no time. In thi......一起来看看 《JavaScript and Ajax for the Web, Sixth Edition》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具