Need Greater Confidence in Your Confidence Intervals?

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

内容简介: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?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

编程大师访谈录

编程大师访谈录

Susan Lammers / 李琳骁、吴咏炜、张菁 / 人民邮电出版社 / 2012-1 / 59.00元

《编程大师访谈录》是对19位计算机行业先驱的采访实录,采访对象包括查尔斯•西蒙尼、比尔•盖茨、安迪•赫兹菲尔德、雷•奥奇、杰夫•拉斯金等。访谈涉及他们软件创造过程的灵感、技术、编程习惯、动机、反思,以及对未来软件的畅想等。问答中集结了这些计算机先驱的精辟言论,处处闪烁着智慧的火花。 《编程大师访谈录》适合IT从业人员阅读。一起来看看 《编程大师访谈录》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具