# Need help in understanding how to carryout Discrete Event Simulation for forecasting using the utilities package in R

I am using the utilities package in R to conduct the DES for a forecasting project. My problem involves forecasting the service requirement for patients. On average five patients get admitted to the ward daily and there are 46 beds in a ward.

In order to do this simulation I have set K=46 (since I believe K = users/total facility capacity). I have set n=20, the number of patients and lambda=5 (avg no. of patients). The revival time is 30 minutes.

SOME CODE IS RE-USED FROM SUPPLEMENTARY MATERIAL OF THE PACKAGE

The use time of the facility:

use_time <- mu * runif(K)  where mu=1440 minutes (avg time the facility service remains in use.

The arrival time:

 ARRIVE <- cumsum(rexp(K, rate = 1/lambda))

Hence the code for QUEUE function:

QUEUE <- queue(arrive = ARRIVE, use.full = use_time,
n = 20, revive = 30)

lambda <- 5 # avg number of arrivals per day
K <- 46 # users of the facility
ARRIVE <- cumsum(rexp(K, rate = 1/lambda))

mu <- 1440

use_time <- mu * runif(K)

library(utilities)
QUEUE <- queue(arrive = ARRIVE, use.full = use_time,
n = 20, revive = 30)

plot(QUEUE)


My question is: the time I see at the bottom of the plot is in minutes? Or should this be in hours? Second, are the parameters set correctly? I am new to this hence I am not sure if I am on the right track.

There are quite a few problems with your analysis at present. First of all, you say that there are 46 beds in the facility, but then your subsequent analysis uses $$n=20$$ instead (the parameter n is the number of facilities). Secondly, the arrival times you have generated (based on the example code) does not conform to your description of the number of patients that arrive each day and how long they are served.

Even if you were to fix these issues, the main problem is that you have proposed to use a large number of facilites relative to the number of patients you actually have arriving at the amenity. If you have five patients arriving each day and they stay for one day each then you are going to have about five patients at the amenity at a time. Since this is far less than the proposed number of facilities, the facilities will easily be enough to deal with all the patients and so the analysis will not be very interesting; all patients will be served immediately with no waiting time. If you want to conduct a meaningful analysis here then you will need to simulate the arrival times and use times in a way that conforms to the behaviour of your patients.

If you would like to understand how to do this type of analysis I recommend you read O'Neill (2021), which describes the model and computation. This paper discusses the queuing model used in the queue function and it shows you how to use the function. As can be seen in that paper (and in the function documentation), the function takes in inputs for the arrival times, use times and patience times for each of the users. If you want to use this function effectively, you will need to first simulate appropriate inputs for these items for your patients. The queue function can then model the outcomes that will occur given any number n of hospital beds.

...the time I see at the bottom of the plot is in minutes? Or should this be in hours?

The time in the queuing object and the resulting plot is in whatever units were used for the input. If your input times are in minutes then the times shown in the output will be in minutes, and so on.

• Thank you so much!! 46 beds are used by three different departments, hence there is no fixed number of beds allocated to stroke patients; in this case, I believe K should be 5 users daily (no. of patients arriving at the facility). The number of beds allocated to these patients should be 20, (n=20, I am making the assumption the remaining 26 beds are allocated to non-stroke patients). However, patients do not leave within a day; some patients stay on for a few days to a week or two, depending on the severity of the stroke.I am trying to start off with a really good simple model.