In: Statistics and Probability
Two mechanics are changing oil filters for the arriving customers. The service time has an Exponential distribution with mean 12 minutes for the first mechanic, and mean 3 minutes for the second mechanic. When you arrive to have your oil filter changed, your probability of being served by the faster mechanic is 0.8.
(a) Use simulation to generate 10000 service times and estimate the mean service time for you.
(b) Summarize your data with hist(x, probability = TRUE) and mean(x), where x is your simulated data. Add two vertical lines indicating the simulated mean and the theoretical mean.
(c) Comment on your findings.
Hint: You should generate say 10000 values some from the quicker one and some from the slower one depending on the chance. The histogram should look like the theoretical distribution of the service time random variable. A discussion can be made about the comparison between the simulated and the theoretical results. The theoretical mean can be calculated by weighting the two mean times with weights being the probabilities. If you want, ask me about a derivation of the theoretical mean.
set.seed(7657)
N <- 10000
X <- array(dim=N)
for(i in 1:N)
{
u <- runif(1)
if(u<0.8)
{
X[i] <- rexp(1,rate=1/3)
}
else
{
X[i] <- rexp(1,rate=1/12)
}
}
M <- mean(X)
TH_mean <-((3*0.8)+(0.2*12))
hist (X,probability=TRUE, col= "orange")
abline(v=TH_mean,col = 'blue',lwd =4)
abline (v=M, col = 'red', lwd =2)
HISTOGRAM OF X
The theoritical mean is 4.8 minutes whereas the simulated mean is found to be 4.816.
The theoritical mean is shown by blue colour vertical line and simulated mean is shown by a red colour line in the Histogram.
N = 10000
x = NULL
for (i in 1:N)
{
u = runif(1)
if(u<0.8)
{
x[i] = rexp(1,rate = 1/3)
}
else
{
x[i] = rexp(1,rate = 1/12)
}
}
SM<-mean(x)
TH_mean <-((3*0.8)+(0.2*12))
hist(x, probability = TRUE, ylim = c(0,0.3), breaks = 25)
abline(v=TH_mean,col = 'blue',lwd =4)
abline (v=SM, col = 'black', lwd =2)
Both theoritical and simulated mean are very close as evident from the Histogram.
Hence both mean were successfully estimated.