I am creating a headcount model for a contact center. I would like to apply erlang c to a new column of my forecasted data (forecast pulled in via RODBC con)
When I apply my erlang c formula, I get multiple warnings, mostly repeating themselves. The formula does run, but only the 1st line is accurate.
Warning messages:
1: In 1:agents : numerical expression has 96 elements: only the first used
2: In while (gos < gos_target * (gos_target > 1)/100) { : the condition has length > 1 and only the first element will be used
3: In 1:agents : numerical expression has 96 elements: only the first used
4: In while (gos < gos_target * (gos_target > 1)/100) { : the condition has length > 1 and only the first element will be used
The problem is that I need some of the input for the function to pull from the data frame
I need the function to take the call volume and AHT from that current row in the data frame and work out a headcount requirement
The data is a basic table that consist of date, day, month AHT & Calls Columns
I have tried different methods of applying it:
I have used Lapply
I have tried adding it by creating new column
I have tried using rep function
I have tried using for loop
Interval <- 15
Calls <- Should pull from Data
Duration <- Should pull from Data
Wait_time <- 20
gos_target <- 90
Shrinkage <- 21
Rate <- Calls *(60/Interval)
intensity <- function(rate, duration, interval = 60) {
(rate / (60 * interval)) * duration
}
erlang_c <- function(agents, rate, duration, interval = 60) {
int <- intensity(rate, duration, interval)
erlang_b_inv <- 1
for (i in 1:agents) {
erlang_b_inv <- 1 + erlang_b_inv * i / int
}
erlang_b <- 1 / erlang_b_inv
agents * erlang_b / (agents - int * (1 - erlang_b))
}
service_level <- function(agents, rate, duration, target, interval = 60) {
pw <- erlang_c(agents, rate, duration, interval)
int <- intensity(rate, duration, interval)
1 - (pw * exp(-(agents - int) * (target / duration)))
}
resource <- function(rate, duration, target, gos_target, interval = 60) {
agents <-round(intensity(rate, duration, interval) + 1)
gos <- service_level(agents, rate, duration, target, interval)
while (gos < gos_target * (gos_target > 1) / 100) {
agents <- agents + 1
gos <- service_level(agents, rate, duration, target, interval)
}
return(c(ceiling(agents/(1-(Shrinkage/100)))))
}
resource(Calls, Duration, Wait_time, gos_target, 15)
#
I need each column to give me the accurate headcount required. when i run it for one, line of data, any line, the answer is always accurate. as soon as i have more than one row of data i my headcount results calculates, however is always inaccurate, by 5 to 15 agents
gosis more than one dimensional. It shouldn't be the case. You should try to see where / why you havelength(gos)>1