---
title: "ADA1: Class 14, Parameter estimation (one-sample)"
author: "Your Name Here"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: true
---
Include your answers in this document in the sections below the rubric.
# Rubric
Answer the questions with the data example.
---
# Sample the Globe example
How can we estimate the proportion of water on the globe using a beach ball?
## Questions to answer
1. (2 p) What is a good sampling strategy to pick points at random from a sphere?
2. (2 p) How can this strategy be used to estimate the proportion of the globe covered by water?
3. (1 p) Enter the data we collected in class and compute the confidence interval.
Let $n=$ total number of observations and let $x=$ the number of "successes"
(number of water observations, land is a "failure").
Enter these numbers into the `prop.test()` and `binom.test()` functions below.
```{R}
## notes for prop.test() and binom.test()
# x = number of "successes"
# n = total sample size
x = 21
n = 21 + 14
dat.globe <- data.frame(type = c("Water", "Land"), freq = c(x, n - x), prop = c(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. (2 p) Interpret the confidence interval for the proportion of water.
5. (3 p) Here's a gimme! Label the plot: the title, $x$-, 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.
```{R}
# 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 = subset(dat.globe, type == "Water"), aes(x = type, y = prop))
p <- p + geom_hline(yintercept = c(0, 1), alpha = 1/4)
p <- p + geom_bar(stat = "identity")
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)
```