library(readr)
## Warning: package 'readr' was built under R version 4.5.2
# 1. Memuat data
data <- read_csv("C:/Users/Msi user/Downloads/Call Center Data.csv")
## Rows: 1251 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Answer Rate, Service Level (20 Seconds)
## dbl (4): Index, Incoming Calls, Answered Calls, Abandoned Calls
## time (3): Answer Speed (AVG), Talk Duration (AVG), Waiting Time (AVG)
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ic <- data$`Incoming Calls`
# 2. Statistik deskriptif
cat('N =', length(ic), '\n')
## N = 1251
cat('Min =', min(ic), '\n')
## Min = 5
cat('Max =', max(ic), '\n')
## Max = 1575
cat('Mean =', round(mean(ic), 4), '\n')
## Mean = 198.5396
cat('Median =', median(ic), '\n')
## Median = 177
cat('Std Dev =', round(sd(ic), 4), '\n')
## Std Dev = 156.5342
cat('Variance =', round(var(ic), 4), '\n')
## Variance = 24502.95
cat('Q1 =', quantile(ic, 0.25), '\n')
## Q1 = 123
cat('Q3 =', quantile(ic, 0.75), '\n')
## Q3 = 233
# 3. Pembentukan state (berbasis kuartil: Q1=123, Q3=233)
assign_state <- function(x) {
if (x < 123) return('S1') # Rendah
else if (x < 233) return('S2') # Sedang
else return('S3') # Tinggi
}
states <- sapply(ic, assign_state)
cat('\nDistribusi State:\n')
##
## Distribusi State:
print(table(states))
## states
## S1 S2 S3
## 311 625 315
print(round(prop.table(table(states)) * 100, 2))
## states
## S1 S2 S3
## 24.86 49.96 25.18
# 4. Matriks frekuensi transisi
n <- length(states)
N_mat <- table(states[-n], states[-1])
cat('\nMatriks Frekuensi Transisi:\n')
##
## Matriks Frekuensi Transisi:
print(N_mat)
##
## S1 S2 S3
## S1 106 143 61
## S2 156 414 55
## S3 49 67 199
# 5. Matriks probabilitas transisi
P <- N_mat / rowSums(N_mat)
cat('\nMatriks Probabilitas Transisi:\n')
##
## Matriks Probabilitas Transisi:
print(round(P, 6))
##
## S1 S2 S3
## S1 0.341935 0.461290 0.196774
## S2 0.249600 0.662400 0.088000
## S3 0.155556 0.212698 0.631746
cat('Verifikasi jumlah baris:', rowSums(P), '\n')
## Verifikasi jumlah baris: 1 1 1
# 6. Probabilitas n-langkah
mat_pow <- function(M, n) {
result <- diag(nrow(M))
for (i in seq_len(n)) result <- result %*% M
result
}
for (n in c(2, 3, 5, 10)) {
cat('\nP^', n, ':\n')
print(round(mat_pow(P, n), 6))
}
##
## P^ 2 :
##
## S1 S2 S3
## [1,] 0.262667 0.505144 0.232189
## [2,] 0.264371 0.572629 0.163000
## [3,] 0.204551 0.347019 0.448430
##
## P^ 3 :
##
## S1 S2 S3
## [1,] 0.252017 0.505159 0.242823
## [2,] 0.258682 0.535931 0.205387
## [3,] 0.226315 0.419603 0.354082
##
## P^ 5 :
##
## S1 S2 S3
## [1,] 0.249416 0.500838 0.249746
## [2,] 0.251644 0.508835 0.239521
## [3,] 0.242804 0.477472 0.279724
##
## P^ 10 :
##
## S1 S2 S3
## [1,] 0.248881 0.499007 0.252112
## [2,] 0.248966 0.499310 0.251724
## [3,] 0.248630 0.498120 0.253249
# 7. Distribusi steady state
A <- t(P) - diag(3)
A <- rbind(A, rep(1, 3))
b <- c(0, 0, 0, 1)
pi_ss <- qr.solve(A, b)
names(pi_ss) <- c('S1 (Rendah)', 'S2 (Sedang)', 'S3 (Tinggi)')
cat('\nDistribusi Steady State:\n')
##
## Distribusi Steady State:
print(round(pi_ss, 6))
## S1 (Rendah) S2 (Sedang) S3 (Tinggi)
## 0.248860 0.498935 0.252205
cat('Verifikasi (pi*P harus = pi):\n')
## Verifikasi (pi*P harus = pi):
print(round(pi_ss %*% P, 6))
##
## S1 S2 S3
## [1,] 0.24886 0.498935 0.252205