Data have been collected on service times at a drive-in-bank window at the Shady Lane National Bank. This data is summarized into intervals as follows;
Interval (Seconds) | Frequency |
---|---|
15-30 | 10 |
30-45 | 20 |
45-60 | 25 |
60-90 | 35 |
90-120 | 30 |
120-180 | 20 |
180-300 | 10 |
We have 150 observations.
We are going to generate service times by the table look-up method. We are going to calculate relative Frequencies, cumulative Frequencies \({ c }_{ i }\), and slope \({ a }_{ i }\).
We will suppose that the minimum time it takes to service a customer is 15 seconds, so \({ x }_{(0)}\) = 15
All calucation will be done in R.
x <- c(15, 30, 45, 60, 90, 120, 180, 300)
freq <- c(0, 10, 20, 25, 35, 30, 20, 10)
obsv <- sum(freq)
rfreq <- round(freq/obsv,4)
cfreq <- cumsum(rfreq)
f_slope <- function(x, cf){
s <- numeric()
for (i in 1:8){
a <- ((x[i+1]-x[i])/(cf[i+1]-cf[i]))
s <- c(s, round(a, 4))
}
return(s)
}
slope <- f_slope(x, cfreq)
x_char <- c('15-30', '30-45', '45-60', '60-90', '90-120', '120-180', '180-300')
df <- as.data.frame(cbind(x_char, freq[2:8], rfreq[2:8], cfreq[2:8], slope[1:7]))
colnames(df) <- c('Interval Seconds', 'Frequency', 'Relative Frequency', 'Cumulative Frequency', 'Slope')
df
## Interval Seconds Frequency Relative Frequency Cumulative Frequency
## 1 15-30 10 0.0667 0.0667
## 2 30-45 20 0.1333 0.2
## 3 45-60 25 0.1667 0.3667
## 4 60-90 35 0.2333 0.6
## 5 90-120 30 0.2 0.8
## 6 120-180 20 0.1333 0.9333
## 7 180-300 10 0.0667 1
## Slope
## 1 224.8876
## 2 112.5281
## 3 89.982
## 4 128.5898
## 5 150
## 6 450.1125
## 7 1799.1004
The inverse cdf is calculated as:
\(X={ x }_{ i-1 }+{ a }_{ i }(R-{ c }_{ i-1 })\) \(when\quad { c }_{ i-1 }<R\le { c }_{ i }\)
We will now generate 5 random R from Table A.1. in the book.
The numbers are 05317, 21425, 11108, 55441, 61130, we will convert them to numbers between 0 and 1 and use them as our R values.
R_random <- c(05317, 21425, 11108, 55441, 61130)
R_random <- R_random/100000
The first number “generated” \({ R }_{ 1 }=0.05317\) is between \({ c }_{ 0 }=0\) and \({ c }_{ 1 }=0.0667\) then
\({ X }_{ 1 }={ x }_{ (0) }\quad +\quad { a }_{ 1 }({ R }_{ 1 }-{ c }_{ 0 })=15\quad +\quad 224.8876(0.05317\quad -\quad 0)\)
Similarly, we will calcualte all the values X.
f_xvar <- function (x, a, r, c){
Xi <- x+a*(r-c)
return(round(Xi,4))
}
X1 <- f_xvar(15, as.numeric(df$Slope[1]), R_random[1], 0)
X2 <- f_xvar(45, as.numeric(df$Slope[3]), R_random[2], as.numeric(df$`Cumulative Frequency`[2]))
X3 <- f_xvar(30, as.numeric(df$Slope[2]), R_random[3], as.numeric(df$`Cumulative Frequency`[1]))
X4 <- f_xvar(60, as.numeric(df$Slope[4]), R_random[4], as.numeric(df$`Cumulative Frequency`[3]))
X5 <- f_xvar(120, as.numeric(df$Slope[5]), R_random[5], as.numeric(df$`Cumulative Frequency`[4]))
X_var <- c(X1, X2, X3, X4, X5)
X_var
## [1] 15.2659 32.4997 29.1111 55.1088 109.8339