ggplot(us_adults, aes(x = climate_change_affects)) +geom_bar() +labs(x ="", y ="",title ="Do you think climate change is affecting your local community?" ) +coord_flip()
#Summary statistics
us_adults %>%count(climate_change_affects) %>%mutate(p = n /sum(n))
# A tibble: 2 × 3
climate_change_affects n p
<chr> <int> <dbl>
1 No 38000 0.38
2 Yes 62000 0.62
#Start with sample of size 60
n <-60samp <- us_adults %>%sample_n(size = n)
##1 What percent of the adults in your sample think climate change affects their local community?
samp %>%count(climate_change_affects) %>%mutate(p = n /sum(n))
# A tibble: 2 × 3
climate_change_affects n p
<chr> <int> <dbl>
1 No 29 0.483
2 Yes 31 0.517
#51.2% of the adults in this sample believe that climate change affects their local community.
##2 Would you expect another student’s sample proportion to be identical to yours? Would you expect it to be similar? Why or why not?
I would not expect another student’s sample proportion to be identical to mine as we are taking different samples from a much wider population so it would be very unlikely that we would have the exact same sample proportion. I would expect it to be somewhat similar to mine though, as we are assuming the true population proportion is 62% so it is more likely to be around this percentage.
In the interpretation above, we used the phrase “95% confident”. What does “95% confidence” mean?
This means that 95% of the time the true proportion will be contained in the sample.
##Does your confidence interval capture the true population proportion of US adults who think climate change affects their local community? # Yes it does as 62% is between 40% and 65%.
##Each student should have gotten a slightly different confidence interval. What proportion of those intervals would you expect to capture the true population mean? Why? # I would expect 95% to capture the true population mean as that is the confidence that we all chose, so 95% of the time it should contain the true population proportion.
##Given a sample size of 60, 1000 bootstrap samples for each interval, and 50 confidence intervals constructed (the default values for the above app), what proportion of your confidence intervals include the true population proportion? Is this proportion exactly equal to the confidence level? If not, explain why. Make sure to include your plot in your answer.
# 5 out of 50 of the samples did not contain the true population proportion. This is not exactly equal to the confidence level as there is only 50 samples which were used so it is less reliable and more likely to not perfectly match the confidence interval.
##More Practice
##Choose a different confidence level than 95%. Would you expect a confidence interval at this level to be wider or narrower than the confidence interval you calculated at the 95% confidence level? Explain your reasoning # I choose 90%. I expect it to be narrower than the confidence level at 95% as it contains less samples within the 90%. There are less samples in the 90% than in 95%.
##Using code from the infer package and data from the one sample you have (samp), find a confidence interval for the proportion of US Adults who think climate change is affecting their local community with a confidence level of your choosing (other than 95%) and interpret it.
There is 90% confident that the true proportion of US adults who think climate change affects their local community is between 41.7% and 63.3%.
##Using the app, calculate 50 confidence intervals at the confidence level you chose in the previous question, and plot all intervals on one plot, and calculate the proportion of intervals that include the true population proportion. How does this percentage compare to the confidence level selected for the intervals? #9 out of 50 of the intervals did not include the true population proportion. 82% of the samples included the true population proportion. This is lower than the confidence level selected for the intervals.
##Lastly, try one more (different) confidence level. First, state how you expect the width of this interval to compare to previous ones you calculated. Then, calculate the bounds of the interval using the infer package and data from samp and interpret it. Finally, use the app to generate many intervals and calculate the proportion of intervals that are capture the true population proportion.
I am chosing 98% confidence. This interval should be wider than the previous 2.
#There is 98% confident that the true proportion of US adults who think climate change affects their local community is between 36.7% and 66.7%.
##Using the app, experiment with different sample sizes and comment on how the widths of intervals change as sample size changes (increases and decreases). # As confidence increases, widths increase. As confidence decreases, widths decrease.
Finally, given a sample size (say, 60), how does the width of the interval change as you increase the number of bootstrap samples. Hint: Does changing the number of bootstrap samples affect the standard error?
The width of the interval does not change as you increase the number of samples, but you are more likely to have closer to the confidence interval of the percentage of samples containing the true population proportion.