PA 8.2: Instrument Con

Distributions + Simulation

Download starter .qmd template

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:

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?

# Q1 code

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

# Q2 code

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

# Q3 code

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

# Q4 code

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

# 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.

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.

Caution

Do not change the seed in the code provided below!

set.seed(1957)

my_weights <- map_dbl(.x = ... , 
                      .f = ~ music_man(n_tromb = 76, ...))
Error: '...' used in an incorrect context

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?

# Canvas submission code