---
title: "PA 8.2: Instrument Con"
subtitle: "Distributions + Simulation"
format: 
  html:
    code-tools: true
    toc: true
editor: source
execute: 
  error: true
  echo: true
  message: false
  warning: false
---

```{r setup}
#| include: false
library(purrr)
```

[Download starter .qmd template](../student-versions/pas/pa8-2.qmd)

Professor Harold Hill wanders into your small town. He claims to be selling top-quality instruments for a marching band. He begins selling his instruments to all the children in town.

You are suspicious of Professor Hill, and think that perhaps he is selling instruments made of sub-par materials to scam the townsfolk.

You do some research on the weights of properly crafted brass instruments, and you learn the following facts:

+ Trombone weights are normally distributed, with a mean weight of 4.6 lbs and a standard deviation of 0.8 lbs.

+ Trumpet weights are uniformly distributed between 1.5 and 3.5 lbs.

+ Reed instruments (like clarinets, bassoons, and saxophones) have weights that are Chi-square distributed with 4 degrees of freedom.

::: callout-tip
# Remember

**Four Types of Calculations**

+ `p` -- stands for probability (left tail area for a given value of $x$).
+ `r` -- stands for random (for generating data).
+ `q` -- stands for quantile (for a given probability).
+ `d` -- stands for density (of the distribution at a given value of $x$).

**Distributions**

+ The normal distribution functions end with `norm`.
+ The uniform distribution functions end with `unif`.
+ The Chi-square distribution functions end with `chisq`.
:::

## Warm-up

**1. What is the 95th percentile for trumpet weight?**

```{r}
# Q1 code
```

**2. What is the 10th percentile for trombone weight?**

```{r}
# Q2 code
```

**3. About what percent of trombones do you expect to be more than 5 pounds?**

```{r}
# Q3 code
```

**4. About what percent of reed instruments do you expect to be more than 5 pounds?**

```{r}
# Q4 code
```

**5. Simulate 100 random trombone weights. How many of them were below 4 pounds?**

```{r}
# Q5 code
```

## Catching a Con

You manage to intercept a shipping notice for a delivery to Professor Hill. It says the following:

    Wells Fargo Shipment 1957

    To:  Harold Hill, Mason City, Iowa
    From:  Music Factory, Gary, Indiana

    Items included:
        Trombones: 76
        Cornets: 110
        Saxophones: 542
        Clarinets: 318
        Bassoons: 175
        
    Total Shipped Weight: 4532 lbs.

This is your chance to catch Professor Hill in his lie!

**6. Write a function that samples the correct number of trombones, cornets (trumpets), and reed instruments (saxophones, clarinets, bassoons), and then returns the total weight of the shipment.**

```{r}
music_man <- function(n_tromb, n_cor, n_reed){
  
  trombones <- rnorm(n_tromb, ...)
  cornets   <- ...
  reeds     <- ...
  
  ...
  
  return()
  
}
```

**7. Use the function you just wrote to create random samples of the total weight of *1000* possible shipments by finishing the code below.**

::: callout-caution
**Do not** change the seed in the code provided below!
:::


```{r}
set.seed(1957)

my_weights <- map_dbl(.x = ... , 
                      .f = ~ music_man(n_tromb = 76, ...))
```

## Canvas submission

> How many of these samples had a weight less than or equal to Professor Hill's shipment? 
>
> Do you beleive Professor Hill ordered genuine instruments?

```{r}
# Canvas submission code
```
