---
title: "Worksheet 8"
output:
  pdf_document: default
  html_notebook: default
---



## Author: Enter name of the author here

## Discussants: Enter the names of other people who you discussed this problem set with




$\\$




The goal of this worksheet is to gain practice running hypothesis tests for a single proportion. Some functions that could be useful for completing the worksheet are: rbinom(), dbinom(), sum(), and pbinom(). The following symbols might also be useful:  $H_0$,  $H_A$ , $\pi$ and $\hat{p}$. As always, the worksheet is due on midnight on Sunday. 




$\\$




<!-- This R chunk sets some parameters that will be used in the rest of the document. -->
```{r message=FALSE, warning=FALSE, tidy=TRUE, echo = FALSE}
 library(knitr)
 # makes sure the code is wrapped to fit when it creats a pdf
 opts_chunk$set(tidy.opts=list(width.cutoff=60)) 
 set.seed(1)  # set the random number generator to always give the same sequence of random numbers

```





**Question 1a**:  Orangutans at Hogle Zoo in Utah have been predicting the winners of the superbowl for the last 10 years. Out of these 10 predictions, the animals have made the correct prediction 8 times (Tuah, a 27-month-old orangutan unfortunately made the wrong prediction in the last two [years](http://www.sltrib.com/home/4896047-155/video-hogle-zoo-orangutans-make-super).  Let us test the hypothesis that the orangutans from this zoo are psychic. To start this hypothesis test, first state the null and alternative hypotheses using both words and symbols (hint: the $\pi$ symbol might be useful). 



**Answer:** 






$\\$




**Exercise 1b**: Now write down the observed statistic (number of correct predictions) as a proportion $\hat{p}$. 

**Answer:** 




$\\$







**Exercise 1c**:  Next create a null distribution of the number of games expected to be correctly predicted if the null hypothesis was true by 'flipping coins' in R. This null distribution will contain simulations of getting k correct predictions out of 10 if the animals were guessing. To create this null distribution, flip 10 coins, and repeat this process 10,000 times (hint: the rbinom(x = num.repeats, size = n, prob = pi) function will be very helpful here!). Describe what each of the 10 coin flip represents here. Also describe what the value of each of the 10,000 points in the null distribution represents. 


Show the R code that you used to answer the question...
```{r message=FALSE, warning=FALSE, tidy=TRUE}


# create a null distribution by simulating 10 guesses and repeating this process 10,000 times

 


```


**Answer:** 






$\\$





**Exercise 1d**: Now calculate the p-value which is the proportion of values in the null distribution that is greater than or equal to the observed number of correct guess. Does this p-value give evidence that the orangutans are psychic?  
 
 
```{r message=FALSE, warning=FALSE, tidy=TRUE} 



```



**Answer:**  






$\\$




**Exercise 1e**:  We could also create a null distribution based on the binomial distribution. Repeat the process using a null distribution based on the binomial distribution and report the p-value. Do the results change? 


```{r message=FALSE, warning=FALSE, tidy=TRUE}


```



**Answer:**  





$\\$






**Question 2a**: There were 2430 Major League Baseball (MLB) games in 2009, and the home team won 54.9% of the games. Let's test the hypothesis that there is a home field advantage - i.e., that the proportion of games won at home is greater than the proportion of games won away, for all seasons, not just the 2009 season. To start testing this, first state the null and alternative hypotheses in both symbols and in words. 



**Answer:** 






$\\$





**Exercise 2b**: Write down the observed statistic (games won at home) as a proportion $\hat{p}$ and as the actual number of games that were won at home in 2009 (note: this number might be slightly off due to rounding on percentage of games won at home). 



**Answer:** 





$\\$







**Exercise 2c**:  Next create a null distribution of the number of games expected to be won at home if the null hypothesis was true by 'flipping coins' in R. This null distribution will contain simulations of winning k games out of 2430 if there was no home field advantage. To create this null distribution, flip 2430 coin flips, and repeat this process 10,000 times (again, the rbinom(x = num.repeats, size = n, prob = pi) function will be very helpful here). Describe what each of the 2,430 coin flip represents here. Also describe what the value of each of the 10,000 points in the null distribution represents. 


Show the R code that you used to answer the question...
```{r message=FALSE, warning=FALSE, tidy=TRUE}


# create a null distribution by simulating 2430 games and repeating this process 10,000 times

 


```



**Answer:** 







$\\$





**Exercise 2d**: Now calculate the p-value which is the proportion of values in the null distribution that is greater than the observed number of games won. Does this p-value give evidence that there is a home field advantage?  
 
 
```{r message=FALSE, warning=FALSE, tidy=TRUE} 




```



**Answer:**  





$\\$






**Exercise 2e**:  We could also create a null distribution based on the binomial distribution. Repeat the process using a null distribution based on the binomial distribution and report the p-value. Do the results change? 


```{r message=FALSE, warning=FALSE, tidy=TRUE}




```



**Answer:**    






$\\$







**Exercise 3a**: A telephone survey of 1,000 randomly selected US adults found that 31% of them say they believe in ghosts. Does this provide evidence that more than 1 in 4 US adults believe in ghosts? 

Start by stating the null and alternative hypotheses in words and symbols (i.e., use the symbol $\pi$).



**Answer:**  





$\\$







**Exercise 3b**: Write down the observed statistic of interest as a proportion $\hat{p}$, and as a count variable. 


**Answer:**  





$\\$







**Exercise 3c**:  Now create a null distribution by 'flipping coins' in R. This null distribution will contain the probability that k people (out of 1,000 surveyed) would say they believed in ghosts if the null hypothesis was true. To create this null distribution, flip 1,000 coin flips, and repeat this process 10,000 times (again, the rbinom(x = num.repeats, size = n, prob = pi) function will be very helpful). Describe what each of the 1,000 coin flip represents here. Also describe what the value of each of the 10,000 points in the null distribution represents. 


Show the R code that you used to answer the question...
```{r message=FALSE, warning=FALSE, tidy=TRUE}


# create a null distribution by simulated asking 1000 people whether they believe in ghosts and repeating this 10,000 times




```




**Answer:** 





$\\$








**Exercise 3d**: Now calculate the p-value which is the proportion of values in the null distribution that is greater than the observed number of people who believe in ghosts. Does this p-value give evidence that more than 25% of Americans believe in ghosts?  
 
 
```{r message=FALSE, warning=FALSE, tidy=TRUE} 



```




**Answer:** 






$\\$






**Exercise 3e**:  We could also create a null distribution based on the binomial distribution. Repeat the process using a null distribution based on the binomial distribution and report the p-value. Do the results change? 


```{r message=FALSE, warning=FALSE, tidy=TRUE}




```



**Answer:**  





$\\$





**Exercise 3f**: Finally, suppose only 100 people had been asked in the survey. Would this change our ability to say whether more than 25% of Americans believe in ghosts? Repeat this process assuming only 100 people had been asked. What is the p-value that you get? Would you draw the same conclusing? 


```{r message=FALSE, warning=FALSE, tidy=TRUE}




```



**Answer:** 






$\\$






![normal vs paranormal](https://i2.wp.com/flowingdata.com/wp-content/uploads/2014/06/Paranormal-distribution-smaller.png?w=400)


