################################################################## # DigitalWater.r # Statypus Water: Digital Production Audit # Course Resources: statypus.org ################################################################## # 1. SET MACHINE PARAMETERS mu <- 500.5 sigma <- 0.2 # 2. PHASE 1: THE LONE WOLF (n=1) # Generate 10,000 individual bottles. lone_wolves <- rnorm(10000, mean = mu, sd = sigma) # Plot with 0.3mL Target Zone goalposts (Red dashed lines) hist(lone_wolves, main = "Individual Bottles (n=1)", xlim = c(499.5, 501.5), col = "gray90", border = "white") abline(v = c(500.2, 500.8), col = "red", lwd = 3, lty = 2) # Proportion Check: How many fell outside the Target Zone (500.2 to 500.8)? mean(lone_wolves < 500.2 | lone_wolves > 500.8) # 3. PHASE 3: THE SNIPER RIFLE (10,000 Cases of n=16) # Simulating 10,000 unique cases (16 bottles each). # Storing the average volume of each case in 'case_avgs'. case_avgs <- replicate(10000, mean(rnorm(16, mean = mu, sd = sigma))) # Plot the averages (Using skyblue for on-screen clarity) hist(case_avgs, main = "10,000 Case Averages (n=16)", xlim = c(499.5, 501.5), col = "skyblue", border = "white") abline(v = c(500.2, 500.8), col = "red", lwd = 3, lty = 2) # 4. THE AUDIT # Out of our 10,000 simulated cases, how many hit the mark of 500.1 or less? sum(case_avgs <= 500.1)