---
title: "Project #5"
author: "Milica Cudina"
date: "`r Sys.Date()`"
output: pdf_document
urlcolor: blue
---
<!-- The author of this template is Dr. Gordan Zitkovic.-->
<!-- The code chunk below contains some settings that will  -->
<!-- make your R code look better in the output pdf file.  -->
<!-- If you are curious about what each option below does, -->
<!-- go to https://yihui.org/knitr/options/ -->
<!-- If not, feel free to disregard everything ...  -->
```{r echo=FALSE, warning=FALSE, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  fig.align="center",
  fig.pos="t",
  strip.white = TRUE
)
```
<!-- ... down to here. -->

---

## Problem #1 (10 points)
## \color{blue}{The "normal" temperature of the human body.}
The data set provided on the course website was obtained from the following article: *L. Shoemaker Allen (1996) What's Normal? – Temperature, Gender, and Heart Rate, Journal of Statistics Education, 4:2, DOI: 10.1080/10691898.1996.11910512*

**(2 points)** In this data set, the second column encodes the gender. In this data set, all the cases were either male or female. The males were represented by "1" while the females were represented by "2". Create an appropriate plot in `R` which will help you determine whether the distribution of the male humans' temperatures can be modelled as normal. 

**(5 points)** From previous studies, you know that the population standard deviation of body temperatures of human males is $0.70$. Create an 80\%-confidence interval for the mean body temperature of human males. 

**(3 points)** The "traditionally accepted" normal temperature of a human body is 98.6F. Set the hypotheses for a test of whether that value is the true population mean for human males. What is the $p-$value you obtain? Formulate a conclusion in accordance with the obtained $p-$value. 



## Problem #2 (20 points)
## \color{blue}{The operating characteristic curve: Power of a $z-$test.} 
  Consider the following test of a
  hypothesis about the mean consumption of sugar-sweetened beverages
  at your university based on a sample of size of $100$. In this case
  we’ll assume that the population distribution is normal and that the
  population standard deviation is given at $155$ calories. The
  hypotheses are

\begin{equation}%\label{}
    \nonumber 
    \begin{split}
      H_0: \mu = 286 \quad vs. \quad H_a: \mu < 286
    \end{split}
\end{equation}

\begin{itemize}
\item[(i)] ($12$ points) What is the {\em rejection region} under the
  above null hypothesis for a one-sided alternative with the significance level of $0.05$? Complete the
  following steps in {\bf R}:
\begin{enumerate}
\item[$\bullet$] ($3$ points) Draw the density of the {\bf sampling
    distribution} of the sample mean under the null hypothesis.
\item[$\bullet$] ($2$ points) Draw the vertical line indicating the
  {\bf mean} of the population distribution under the null hypothesis
  (preferably in a different color).
\item[$\bullet$] ($2$ points) Draw the vertical line indicating the {\bf upper
    bound} of the rejection region for a significance level of $0.05$
  (preferably in a different color).
\item[$\bullet$] ($5$ points) Using the `polygon` command (not any of the packages you may have found on the internet), shade the region below the normal
  density function to the left of the upper bound you found in the
  previous task.
\end{enumerate}
\item[(ii)] ($8$ points) What is the correspondence between the
  alternative values of the population mean and the power of the above
  test?
\begin{enumerate}
\item[$\bullet$] ($5$ points) Define a {\bf function} which will
  calculate (from first principles) the power of the above test as a
  function of the alternative population mean. 
\item[$\bullet$] ($3$ points) Draw the graph of the function you
  obtained in the previous task. 
\end{enumerate} 
\end{itemize}

## Problem #3 (14 points) 
## \color{blue}{Our logic survey.} 
**After** you have completed the surveys you received in an email, you can watch the following videos for fun. They are not necessary for the remainder of the problem, but they are entertaining and informative. 

[Video #1](https://www.youtube.com/watch?v=tO8d60nM5k4)

[Video #2](https://youtu.be/pTpBcxIg-9A)

[Video #3](https://www.youtube.com/watch?v=-iSxls2f0Qo)

**If you responded to the survey, you already have 2 points. **

\begin{itemize}
\item[(i)] Let us first figure out if there is a difference between the students in 2021 and 2022. 
  \begin{itemize}
    \item[$\bullet$] ($4$ points) ``Clean up'' the data in the spreadsheets so that you have the information that you need for the test. Then, summarize the results of our survey visually. 
    \item[$\bullet$] ($5$ points) Use {\bf R} to test
     \begin{equation}%\label{}
      \nonumber 
        \begin{split}
            H_0 : p_{2021} = p_{2022} \quad vs. \quad H_a: p_{2021} \ne p_{2022}
        \end{split}
     \end{equation}
     and report the $p-$value. 
{\em Note: Do {\bf not} use the built-in prop.test command here!} 
\end{itemize}

\item[(ii)] ($3$ points) The reported proportion of 20\% correct
  answers in the general population was what prompted the survey
  talked about in the above videos. One would assume that the students
  taking applied statistics are more capable of logical thought than
  the general population. So, for $p$ denoting the population proportion for applied statistics students, let us test the following hypothesis:

\begin{equation}%\label{}
    \nonumber 
    \begin{split}
      H_0: p = 0.20 \quad vs. \quad H_a: p > 0.20
    \end{split}
\end{equation}
and report the $p-$value. 
\end{itemize}


## Problem #4 (16 points) 
## \color{blue}{Pizza \& ice cream.}
Recently you were sent a link to a survey regarding pizza and ice-cream preferences. 

**If you responded to the survey, you already have 2 points. **

The results, as Google reports them are in
the spreadsheet you received as an attachment. To see if there is
any evidence of association between pizza and ice-cream preferences, please do the following:
\begin{enumerate}
\item[(i)] ($4$ points) ``Clean up'' the spreadsheet so that you have
  more manageable entries in the cells. You can do this in R or using
  some Excel-like software. Then, create and display a {\bf two-way
    table} summarizing the results of our survey. 
\item[(ii)] ($6$ points) Graph the data from the two-way table you
  obtained above. Creative data presentation will earn bonus
  points. Do not be afraid to download additional R libraries.
\item[(iii)] ($4$ points) Perform that $\chi^2-$test to see if there
  is an association between your subjects' preferences. 
\end{enumerate}

