Page 302 Problem 9

Assume that the service time for a customer at a bank is exponentially distributed with mean service time 2 minutes. Let X be the total service time for 10 customers. Estimate the probability that X > 22 minutes

custs <- rexp(10000000, .5)
dim(custs) <- c(1000000,10)
sums <- apply(custs, 1, sum)

sum(sums > 22)/length(sums)
## [1] 0.339545
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.2
df <- data.frame('custs' = sums)
ggplot(as.data.frame(df)) + geom_density(aes(x = custs), color = 'blue') 

The distribution will actually be gamma with shape parameter 10 and scale parameter 2.

1 - pgamma(22, 10, .5)
## [1] 0.3405106
gammas <- rgamma(1000000,10, .5)
df2 <- data.frame('gammas' = gammas, 'custs' = sums)
ggplot(as.data.frame(df)) + geom_density(aes(x = custs), color = 'blue') + geom_density(aes(x = gammas), color = 'red')