Running an experiment

library(treat.sim)
library(simmer)
#> 
#> Attaching package: 'simmer'
#> The following object is masked from 'package:rmarkdown':
#> 
#>     run

Creating an experiment for the model

In treat.sim all experimental parameters are held in a list. You can use the convenience function create_experiment to create a pre-populated list with all the correct parameter names and default values.

use help(‘create_experiment’) to see the full list of parameters available.

default_experiment <- create_experiment()
print(default_experiment$n_triage_bays)
#> [1] 1
print(default_experiment$triage_mean)
#> [1] 3

The above example creates a default experiment. To vary parameters simply set the corresponding argument in the create_experiment function.

extra_triage <- create_experiment(n_triage_bays=2)
print(extra_triage$n_triage_bays)
#> [1] 2

extra_faster_triage <- create_experiment(n_triage_bays=2,
                                         triage_mean=2.75)

print(extra_faster_triage$n_triage_bays)
#> [1] 2
print(extra_faster_triage$triage_mean)
#> [1] 2.75

Run the model and view a log of events

To run the model pass an experiment list to the single_run function. To see a log of events set the environments log level to 1.

To reduce the printed log we se the run_length of the model to 100 time units (minutes). The default run length of the model is 1020 minutes.

default_experiment <- create_experiment()
env <- single_run(default_experiment, run_length=100.0)
#> 4.19095: Patient0: **Non-Trauma arrival**
#> 4.89149: Patient0: (NT) Triage wait time: 0.700537653174251
#> 5.54302: Patient1: **Non-Trauma arrival**
#> 6.54109: Patient2: **Trauma arrival
#> 8.07949: Patient1: (NT) Triage wait time: 2.53646138318029
#> 8.19123: Patient0: Reg wait time: 3.29973886843509
#> 9.94338: Patient2: (T) Triage wait time: 3.40228698248593
#> 11.0408: Patient3: **Non-Trauma arrival**
#> 11.9585: Patient3: (NT) Triage wait time: 0.917680343147367
#> 12.0846: Patient1: Reg wait time: 4.00514393416909
#> 15.8501: Patient4: **Non-Trauma arrival**
#> 16.0983: Patient4: (NT) Triage wait time: 0.248191235091813
#> 16.2498: Patient3: Reg wait time: 4.2912712942446
#> 20.8725: Patient4: Reg wait time: 4.77424521925426
#> 24.1966: Patient0: Exam wait time: 16.0053536986857
#> 24.1966: Patient0: NT Total time in system: 20.005630220295
#> 24.1966: Patient0: A patient has departed the UTC
#> 28.2759: Patient5: **Trauma arrival
#> 30.1627: Patient5: (T) Triage wait time: 1.88677053898573
#> 30.382: Patient3: Exam wait time: 14.1321509468087
#> 30.382: Patient3: NT patient requirement treatment
#> 31.7045: Patient1: Exam wait time: 19.6199040726095
#> 31.7045: Patient1: NT patient requirement treatment
#> 40.6994: Patient4: Exam wait time: 19.8269110173209
#> 40.6994: Patient4: NT patient requirement treatment
#> 42.1027: Patient6: **Trauma arrival
#> 42.8843: Patient3: NT treatment complete
#> 42.8843: Patient3: NT Total time in system: 31.8434073780425
#> 42.8843: Patient3: A patient has departed the UTC
#> 44.738: Patient7: **Non-Trauma arrival**
#> 46.7955: Patient8: **Non-Trauma arrival**
#> 46.8335: Patient9: **Trauma arrival
#> 48.7765: Patient6: (T) Triage wait time: 6.67373630399668
#> 50.579: Patient7: (NT) Triage wait time: 5.84105475260591
#> 51.5631: Patient8: (NT) Triage wait time: 4.76756757707464
#> 53.067: Patient10: **Non-Trauma arrival**
#> 54.163: Patient7: Reg wait time: 3.58401603498012
#> 54.5292: Patient9: (T) Triage wait time: 7.69574494471994
#> 54.7226: Patient10: (NT) Triage wait time: 1.655591990596
#> 56.8028: Patient1: NT treatment complete
#> 56.8028: Patient1: NT Total time in system: 51.2598209408886
#> 56.8028: Patient1: A patient has departed the UTC
#> 57.3631: Patient8: Reg wait time: 5.80005488803418
#> 60.1337: Patient10: Reg wait time: 5.41109897569248
#> 70.6244: Patient4: NT treatment complete
#> 70.6244: Patient4: NT Total time in system: 54.7743290673685
#> 70.6244: Patient4: A patient has departed the UTC
#> 71.0115: Patient8: Exam wait time: 13.6483817287682
#> 71.0115: Patient8: NT patient requirement treatment
#> 71.4249: Patient10: Exam wait time: 11.2911362974792
#> 71.4249: Patient10: NT patient requirement treatment
#> 73.0296: Patient7: Exam wait time: 18.866528977941
#> 73.0296: Patient7: NT patient requirement treatment
#> 77.8156: Patient2: (T) Trauma room wait time: 67.872232044441
#> 83.1252: Patient8: NT treatment complete
#> 83.1252: Patient8: NT Total time in system: 36.3296541604857
#> 83.1252: Patient8: A patient has departed the UTC
#> 96.5949: Patient10: NT treatment complete
#> 96.5949: Patient10: NT Total time in system: 43.5278965055397
#> 96.5949: Patient10: A patient has departed the UTC

To run the model and suppress set log_level=0

default_experiment <- create_experiment(log_level=0)
env <- single_run(default_experiment, run_length=100.0)#
print("Simulation complete.")
#> [1] "Simulation complete."