---
title: "Math 151 - Probability Theory - Homework 1"
author: "your name here"
date: "Due: Friday, August 28, 5pm PDT"
output: pdf_document
---
## Important Note:
You should work to turn in assignments that are clear, communicative, and concise. Part of what you need to do is not print pages and pages of output. Additionally, you should remove these exact sentences and the information about HW scoring below.
Click on the *Knit to PDF* icon at the top of R Studio to run the R code and create a PDF document simultaneously. [PDF will only work if either (1) you are using R on the network, or (2) you have LaTeX installed on your computer. Lightweight LaTeX installation here: https://yihui.name/tinytex/]
> Either use the college's RStudio server (https://rstudio.pomona.edu/)
or install R and R Studio on to your personal computer.
See: https://research.pomona.edu/johardin/math151f20/ for resources.
```{r warning=FALSE, comment=FALSE, message=FALSE, echo = FALSE}
knitr::opts_chunk$set(message=FALSE, warning=FALSE, fig.height=3, fig.width=5,
fig.align = "center")
# install.packages("mosaic")
# Only install if you are not using the Rstudio server.
# Only ever use insall once, and always use it inside the console.
# The library command belongs in your markdown file, and you run it every time.
library(mosaic)
```
General notes on homework assignments (also see syllabus for policies and suggestions):
* please be neat and organized, this will help me, the grader, and you (in the future) to follow your work.
* be sure to include your name on your assignment
* it is strongly recommended that you start / write out the questions as soon as you get the assignment. This will help you to start thinking how to solve them!
* for R problems, it is required to use R Markdown
* in case of questions, or if you get stuck please don't hesitate to email me **and** use Discord for questions!!
**Homework assignments** will be graded out of 5 points, which are based on a combination of accuracy and effort. Below are rough guidelines for grading.
* **5** All problems completed with detailed solutions provided and 75\% or more of the problems are fully correct.
* **4** All problems completed with detailed solutions and 50-75\% correct; OR close to all problems completed and 75\%-100\% correct
* **3** Close to all problems completed with less than 75\% correct
* **2** More than half but fewer than all problems completed and > 75\% correct
* **1** More than half but fewer than all problems completed and < 75\% correct; OR less than half of problems completed
* **0** No work submitted, OR half or less than half of the problems submitted and without any detail/work shown to explain the solutions.
### Assignment
[Hint: To use this Markdown file, first remove all of the non-R code from above. Keep the R code for the `library` command(s). If you have LaTeX commands you will be able to compile using LaTeX. Either is great, but LaTeX is sometimes difficult to learn. Lightweight LaTeX installation here: https://yihui.name/tinytex/]
#### 1: PodQ
Describe one thing you learned from someone in your pod this week (it could be: content, logistical help, background material, R information, etc.) 1-3 sentences.
#### 2: R
In an upcoming national election for the President of the United States, a pollster plans to predict the winner of the popular vote by taking a random sample of 1000 voters and declaring that the winner will be the one obtaining the most votes in his sample. Suppose that 48 percent of the voters plan to vote for the Republican candidate and 52 percent plan to vote for the Democratic candidate. To get some idea of how reasonable the pollster's plan is,
(a) Write a program to make this prediction by simulation. Repeat the simulation at least 100 times and determine how often the pollster's prediction would come true. That is, use your simulation to answer the question *what is the probability that the pollster will correctly predict the election with 1000 observations?*
(b) Repeat your experiment, assuming now that 49 percent of the population plan to vote for the Republican candidate; first with a sample of 1000 and then with a sample of 3000. *what is the probability that the pollster will correctly predict the election with 3000 observations?*
n.b. The Gallup Poll uses about 3000. [Problem taken from Grinstead and Snell, Introduction to Probability]
The following R code will may help you complete the simulation. Try: `?rflip` to see how the function works.
```{r}
set.seed(47) # to set the randomness
n.flip = 20
p.heads = 0.5
n.reps = 3
myflips = rflip(n=n.flip, p=p.heads)
myflips
as.numeric(myflips) # convince yourself that you understand this line
myflips > n.flip/2 # convince yourself that you understand this line
manyflips = c() # initializing a vector to hold our results
for(i in 1:n.reps){
myflips = rflip(n=n.flip, p=p.heads)
manyflips = c(manyflips, as.numeric(myflips)) # concantenating the results from reps
}
manyflips > n.flip/2 # convince yourself that you understand this line
sum(manyflips > n.flip/2) # convince yourself that you understand this line
```
(c) Explain in your own words the general structure of the R program above.