---
title: "Problem Set 3"
author: "Your name here"
date: "`r Sys.Date()`"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
```

*Put your name in the `author` field at the top, write your answers in the space under each question, then knit to HTML. Hand in both this `.Rmd` file and the knitted HTML on Canvas.*

## Question 1

When you show up to a bus stop without checking the schedule, your waiting time is can be thought of as a *uniform* random variable. Suppose buses to campus arrive exactly every 60 minutes, and you arrive at the stop at a completely random moment. Your waiting time $X$, measured in minutes, is then uniformly distributed between 0 and 60.

(a) Take a random sample of 50 waiting times. Plot the distribution of the population and your sample of 50. How close are they? Is that what you expected?

```{r}

```

(b) Taking advantage of the fact that I've given you information about the population, plot the sampling distribution of the sample mean for $n=50$. Confirm that this sampling distribution is correct by repeatedly sampling from this population, taking means, and plotting the density of those simulated means. The population is flat and looks nothing like a bell: what shape does the sampling distribution take, and why?

```{r}

```

(c) Calculate the probability that the mean waiting time in a sample of 50 people will be less than 28 minutes. Confirm your answer with the simulated results from (b).

```{r}

```


(d) Calculate the probability that the mean waiting time in a sample of 50 people will be between 28 and 32 minutes. Confirm your answer with the simulated results from (b).

```{r}

```


(e) What is the probability that a *single* person waits less than 28 minutes? What is the probability that a single person waits between 28 and 32 minutes? Give the answers, and then say in words why these answers are *not* the same as the answers for (c) and (d).

```{r}

```


(f) What size $n$ would you need to be 99\% certain that the mean waiting time in a sample will be between 28 and 32 minutes? Determine this answer and then repeatedly sample from the population with a sample of that size to show that 99\% of sample means do indeed fall within those bounds.

```{r}

```


## Question 2

Use the code below to load the data for this question. This file contains a single sample `x` from an unknown distribution.

```{r}
library(rio)
x <- import("https://github.com/marctrussler/IIS-Data/raw/main/Question2.RDS", trust=T)
```


(a) Plot the distribution of this sample and determine the mean and variance. Using your intuition: what do you expect the distribution that produced this sample might have looked like? (Ignore that I tell you more below, genuinely try to think about how you would answer this question if you didn't know.)

```{r}

```


(b) (Again ignoring that I tell you the population that this sample is drawn from below) Using only information contained in this one sample produce a 70\%, 90\% and 95\% confidence interval around the mean of this sample. For each, describe in words what the confidence interval is telling you.

```{r}

```


(c) A colleague claims the true population mean is 56. Without using the `t.test()` function, carry out the five-step hypothesis test of $H_0: \mu = 56$ against $H_1: \mu \neq 56$ (a two-tailed test). Do this at three significance levels: $\alpha = .30$, $\alpha = .10$, and $\alpha = .05$. For each $\alpha$ report the result of the hypothesis test. Then confirm that your decision at each $\alpha$ is the *same* as what you would conclude from the confidence intervals in (b).

```{r}

```


(d) Confirm your test statistics and p-values using `t.test(x, mu = 56, conf.level = xx)`.

```{r}

```


(e) This sample was produced by `rnorm(10,56,32)` (the true mean is, indeed, 56). Write a loop that repeatedly (i) draws a fresh sample of 10 from this population, (ii) builds 70\%, 90\% and 95\% confidence intervals, and (iii) runs your $\alpha = .30/.10/.05$ test of $H_0: \mu = 56$. Across many repetitions, show two things: that roughly 70\%, 90\% and 95\% of the intervals contain 56, and that your tests land in the rejection region (reject $H_0$) roughly 30\%, 10\% and 5\% of the time. Explain why "the percent of intervals that miss 56" and "the percent of tests that reject" are the same number, and why that number is $\alpha$

```{r}

```


