---
title: "ADA1: Class 16, Parameter estimation (one-sample)"
author: "Your Name Here"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: true
---
# Rubric
Answer the questions in this document, compile to html, print to pdf, and submit to UNM Learn.
__Do not__ add this to your "ALL" `.Rmd` document.
---
# Sample the Globe example
How can we estimate the proportion of water on the globe using a beach ball?
## Questions to answer
1. (0 p) What is a good sampling strategy to pick points at random from a sphere?
In previous classes we brainstorm a strategy as we look at a beachball of the globe.
* Suggestions
1. Some suggest sampling latitude and longitudes, but those are not uniformly distributed on the earth
and the poles would be sampled more densely than the equator.
2. Some suggest cutting the ball into pieces and measuring how much water is on each piece.
3. Finally, I suggest that we toss the ball around the room and when you catch it,
look at your right pointer finger and determine if it's on water or land;
tossing randomizes the orientation of the ball, and catching samples a point on the ball.
2. (3 p) How can this strategy be used to estimate the proportion of the globe covered by water?
Assuming we use Strategy 3, ... __[answer here]__
3. (0 p) Below are the data that we collected in class from a previous year.
Compute the confidence interval for the true proportion of water on the ball.
Let $n=$ the total number of observations and let $x=$ the number of "successes"
(number of water observations, land is a "failure").
These numbers are entered into the `prop.test()` and `binom.test()` functions below.
```{R}
library(tidyverse)
## notes for prop.test() and binom.test()
# x = number of "successes"
# n = total sample size
x = 21
n = 21 + 14
dat_globe <-
tribble(
~type , ~freq , ~prop
, "Water" , x , x / n
, "Land" , n - x , (n - x) / n
)
dat_globe
# prop.test() is an asymptotic (approximate) test for a binomial random variable
p_summary <- prop.test(x = x, n = n, conf.level = 0.95)
p_summary
# binom.test() is an exact test for a binomial random variable
b_summary <- binom.test(x = x, n = n, conf.level = 0.95)
b_summary
```
4. (4 p) Interpret the confidence interval for the proportion of water.
__[answer here]__
5. (3 p) Here's a gimme! Label the plot: the title, $x$-axis, and $y$-axis.
Note how to add error bars using `geom_errorbar()`.
First determine the CI bounds from the `binom.test()` previously,
then set those as limits.
__[answer in plot]__
```{R, fig.height = 4, fig.width = 4}
# get names of objects in b_summary
names(b_summary)
# here's the confidence interval bounds (the attribute tells us this is a 95% interval)
b_summary$conf.int
b_summary$conf.int[1]
b_summary$conf.int[2]
library(ggplot2)
p <- ggplot(data = dat_globe %>% filter(type == "Water"), aes(x = type, y = prop))
p <- p + geom_hline(yintercept = c(0, 1), alpha = 1/4)
p <- p + geom_bar(stat = "identity", fill = "gray60")
p <- p + geom_errorbar(aes(min = b_summary$conf.int[1], max = b_summary$conf.int[2]), width=0.25)
p <- p + scale_y_continuous(limits = c(0, 1))
print(p)
```