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

查看所有标签

猜你喜欢:

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

离散数学及其应用(英文版·第5版)

离散数学及其应用(英文版·第5版)

Kenneth H.Rosen / 机械工业出版社 / 2003 / 79.00元

本书第4版是全球500多所大学的指之一教材,获得了极大的成功。中文版也已被国内大学广泛有用为教材。第5版在前四版的基础上做了大量的改进,使其成为更有效的教学工具。   本书可作为1至2个学期的离散数学课入门教材,适用于数学、计算机科学、工程等专业的学生。一起来看看 《离散数学及其应用(英文版·第5版)》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

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

在线XML、JSON转换工具