---
title: "Problem Set 2"
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

Solve the following questions about the specified Binomial ($B$), Uniform ($U$) and Normal ($N$) random variables:

$Y \sim B(n=500, \pi=.45)$

(a) $E[Y]$

```{r}

```

(b) $V[Y]$

```{r}

```


(c) $P(Y=150)=$?

```{r}

```

(d) $P(Y \leq 200)=$?

```{r}

```

(e) $P(200<Y<223)=$?

```{r}

```

(f) $P(200\leq Y \leq 223)=$?

```{r}

```

$Q \sim U(min=10, max=200)$

(g) $E[Q]$

```{r}

```

(h) $V[Q]$

```{r}

```

(i) $P(Q=12)=$? 

```{r}

```

(j) $P(12<Q<20)=$?

```{r}

```

(k) $P(12\leq Q \leq20)=$?

```{r}

```

$X \sim N(\mu=26, \sigma^2=49)$ 

(l) $p(X>30) =$ ?

```{r}

```

(m) $p(24 < X < 30) =$ ?

```{r}

```

(n) Solve for $i$ where $p(X<i)=.75$

```{r}

```

(o) Solve for $i,j$ where $p(i<X<j)=.85$

```{r}

```

(p) Solve for $c$ such that $p(X < 45) = p(Z < c)$, where $Z \sim N(0, 1)$

```{r}

```


## Question 2


**Here are two tables you would find in the back of a stats textbook.** 

[A Standard Normal (Z) Table (analogous to the `pnorm` function)](https://github.com/marctrussler/IIS-Data/raw/refs/heads/main/ZTable.pdf)

[An Inverse Standard Normal (Z) Table (analogous to the `qnorm` function)](https://github.com/marctrussler/IIS-Data/raw/refs/heads/main/InverseZTable.pdf)

**Answer the following question using these tables and without using R (you can use it as a calculator but can't use the `norm` functions).** 

**(a) Women's height is normally distributed with mean of 64 and a standard deviation of 3. What is the approximate probability a woman has a height between 63 and 66 inches? In a few sentences describe how you got your answer.** 


**(b) What height does a woman have to be such that only 2.5% of women are taller than her? Again, briefly describe how you reached that answer.** 

## Question 3

**(a) `month.pmf` is a PMF of a random variable representing the probability that you are born in each month of the year, where January is month 1, February is month 2 etc. Using the equations discussed in class, mathematically determine the expected value and variance of this random variable.**

```{r}
month.pmf <- rio::import("https://github.com/marctrussler/IIS-Data/raw/refs/heads/main/MTQ1A.Rds", trust=T)
```


**(b) On December 1, 1969 a lottery was held to determine which American men would be drafted to fight in the Vietnam War. All birthdays (including leap day, February 29th) were placed in a large bin and selected one at a time and the order was recorded. The first birthday drawn was September 1st, so men born on September 1st between 1944 and 1950 were the first drafted. The second birthday drawn was April 24th, so men born on that day between 1944 and 1950 were the second group drafted. Ultimately, men from the first 195 numbers drawn were drafted for the war.** 

**The file "VietnamDraft.Rds" contains the actual results of the 1969 draft.** 

```{r}
vietnam.draft <- rio::import("https://github.com/marctrussler/IIS-Data/raw/refs/heads/main/MTQ1B.Rds", trust=T)
head(vietnam.draft)
```

**In the data `month` and `day` describes each day in the year. `drafted` is a boolean variable that tells you if people born on a particular day were drafted, or not.**

**Using these data and the conditional probability formula, determine $P(M=12 | Drafted=T)$: the probability of having a  December birthday conditional on being drafted. Compare this to the unconditional probability of $P(M=12)$ (the probability of having a December birthday contained in `month.pmf`). Based on this: is being born in December and being drafted independent events?**


**(c) Maybe the difference you found in (b) was just due to random chance. We can perform a simulation of a "fair" draft by drawing a sample of size 195 from the random variable `month.pmf` using the `sample` command. (i.e. we want to draw 195 birthdays that would be selected in the draft. We just care about what month people were born in, so we are going to draw, say, 12 December birthdays, and 8 April birthdays, 9 May birthdays, etc.) **

**Use the `sample` command  and a `for()` loop to simulate a fair draft 1000 times. In each of these simulations, determine the proportion of draft days that are in December. The result should be a vector of length 1000 where each entry is the probability of being born in December conditional on being drafted. Compare the distribution of these simulations to the conditional probability from the real draft you calculated in (b). Describe what you see, and what it means in real-world terms.**

**(d) Calculate $P(M=m|Drafted=T)$ `for` each month, make a graph comparing each of these values to the unconditional probabilities of being born in each month to see if the issues with the draft were limited to December.**




