内容简介: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
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()
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?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
颠覆者:周鸿祎自传
周鸿祎、范海涛 / 北京联合出版公司 / 2017-11 / 49.80元
周鸿祎,一个在中国互联网历史上举足轻重的名字。他被认为是奠定当今中国互联网格局的人之一。 作为第一代互联网人,中国互联网行业最好的产品经理、创业者,他每时每刻都以自己的实践,为互联网的发展贡献自己的力量。 在很长一段时间内,他没有在公共场合发声,甚至有粉丝对当前死水一潭的互联网现状不满意,发出了“人民想念周鸿祎”的呼声。 但周鸿祎在小时候,却是一个踢天弄井,动不动就大闹天宫的超级......一起来看看 《颠覆者:周鸿祎自传》 这本书的介绍吧!