OpenIntroStat / oilabs-tidy

👩🏿‍💻 OpenIntro Labs in R using the tidyverse design philosophy, grammar, and data structures
http://openintrostat.github.io/oilabs-tidy/
Creative Commons Attribution Share Alike 4.0 International
66 stars 85 forks source link

Lab 05a_sampling_distributions: replicates filtered out in sample_props_small #107

Open mamcisaac opened 2 years ago

mamcisaac commented 2 years ago

sample_props_small often has fewer than the requested 25 elements.

The call to filter(scientist_work == "Doesn't benefit") is filtering out any replicates where there are no "Doesn't benefit"s in the small sample. As a result any replicates with p_hat=0 are filtered out and are not displayed.

This issue is caused by using a small sample size and a true proportion close to 0 (p=.2).

mamcisaac commented 2 years ago

The code throughout should be like the following to avoid this edge case of filtering out times when p_hat=0:

sample_prop_small <- global_monitor %>%

                    rep_sample_n(size = 10, reps = 25, replace = TRUE) %>%

                    group_by(replicate)%>%

                    summarize(p_hat = mean(scientist_work=="Doesn't benefit"))