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. (1) Use simulation to generate 10000 service times and estimate the mean service time for yourself. (2) Summarize your data with R code hist(x, probability = TRUE) and mean(x), where x is an array representing your simulated data. Add to the histogram two vertical lines indicating the simulated mean and the theoretical mean. A histogram can be made based on frequencies. A density histogram can also be made. To get a density histogram, the height of each bar is divided by the total number of values, and then by the length of the bar. Such a histogram has a vertical scale comparable with the probability density function of the distribution from which data are randomly drawn. (3) Add the curve of the probability density function (which is a mixture of two exponential pdfs) of the service time to the density histogram you got in question (2). For a mixture of two exponential distributions
Two mechanics are changing oil filters for the arriving customers. The service time has an Exponential distribution with
(1) Use simulation to generate 10000 service times and estimate the mean service time for yourself.
(2) Summarize your data with R code hist(x, probability = TRUE) and mean(x), where x is an array representing your simulated data. Add to the histogram two vertical lines indicating the simulated mean and the theoretical mean. A histogram can be made based on frequencies. A density histogram can also be made. To get a density histogram, the height of each bar is divided by the total number of values, and then by the length of the bar. Such a histogram has a vertical scale comparable with the probability density
(3) Add the curve of the probability density function (which is a mixture of two exponential pdfs) of the service time to the density histogram you got in question (2). For a mixture of two exponential distributions
Hints:
- You should generate say 10000 values, some from the quicker one and some from the slower one depending on the chance.
- The density 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.
- To add lines and a legend to an existing graph, do something like
x <- rexp(100, rate = .5)
hist(x, main = "Mean and
abline(v = mean(x), col = 2, lty = 2, lwd = 2) # Add a vertical line at the simulated mean
abline(v = median(x), col = 3, lty = 3, lwd = 2) # Add a vertical line at the simulated median
legend(4.1, 30, c("Simulated Mean", "Simulated Median"), col = 2:3, text.col = 2:3, lty = 2:3, lwd = 2, bty = "n") # Add a legend at location (4.1, 30)
Step by step
Solved in 3 steps with 5 images