Running multiple replications

library(treat.sim)

To obtain the distribution a key performance measure from treat.sim you should run multiple replications. This runs the model \(n\) times each time using different pseudo random numbers.

The first step is to create an experiment. When creating the experiment we recommend setting log_level=0. The mulitple replication functionality of treat.sim uses this parameter to suppress log output.

Use logging within a single run of the model rather than mulitple replications.

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

Multiple replications of the model is achieved using the multiple_replications functions. A user must pass an experiment and the number of replications.

envs <- multiple_replications(default_experiment, n_reps=5)
#> [1] "running replications..."
#> [1] "Complete."

The multiple replications function returns a list of simmer environments rather than a neat table of key performance measures.

We return the simmer environments as this allows you to do your own analysis of KPIs if desired.

To obtain a table of replications versus KPIs use the replication_results_table function.

Note replication_results_table assumes that you have used the default simulation run length in its calculation of resource utilisation. If you have run the model for a different run length from default please set the results_collection_period parameter.

rep_table <- replication_results_table(envs, default_experiment)
rep_table
#>   replication 00_arrivals 01a_triage_wait 01b_triage_util 02a_registration_wait
#> 1           1         227       38.510472       0.6500712              55.63581
#> 2           2         217       39.962735       0.5764697              92.59627
#> 3           3         220        8.028919       0.5145182             125.19868
#> 4           4         207       32.157743       0.5447273             100.08161
#> 5           5         220       17.281597       0.5382466              95.79616
#>   02b_registration_util 03a_examination_wait 03b_examination_util
#> 1             0.8313868             33.71627            0.8440569
#> 2             0.8241213             24.76566            0.8355781
#> 3             0.8363566             22.93733            0.8317090
#> 4             0.7600335             22.39284            0.7850996
#> 5             0.8497077             29.89311            0.8479559
#>   04a_treatment_wait(non_trauma) 04b_treatment_util(non_trauma)
#> 1                       161.3438                      0.8528225
#> 2                       120.8921                      0.8715918
#> 3                       151.4920                      0.8235007
#> 4                       104.7379                      0.8154391
#> 5                       124.9008                      0.8803980
#>   05_total_time(non-trauma) 06a_stabilisation_wait 06b_stabilisation_util
#> 1                  224.4021               322.3138              0.6826987
#> 2                  232.8177               341.0050              0.7482643
#> 3                  226.3541               175.9264              0.8472946
#> 4                  227.6200               217.9818              0.8518988
#> 5                  213.6180               163.9983              0.6404862
#>   07a_treatment_wait(trauma) 07b_treatment_util(trauma) 08_total_time(trauma)
#> 1                   4.930242                  0.2696664              448.4067
#> 2                  20.730095                  0.3229111              501.7710
#> 3                   4.735720                  0.4148506              273.4123
#> 4                  11.741513                  0.3679632              358.0275
#> 5                   5.159307                  0.1560905              347.3643
#>   09_throughput
#> 1           149
#> 2           167
#> 3           149
#> 4           153
#> 5           145

Full script

# create default experiment - turn off event logging
default_experiment <- create_experiment(log_level=0)

# run 5 replications of the model (return is list of simmer envs)
envs <- multiple_replications(default_experiment, n_reps=5)
#> [1] "running replications..."
#> [1] "Complete."

# convert envs into a data.table of KPIs by replication.
rep_table <- replication_results_table(envs, default_experiment)
rep_table
#>   replication 00_arrivals 01a_triage_wait 01b_triage_util 02a_registration_wait
#> 1           1         227       38.510472       0.6500712              55.63581
#> 2           2         217       39.962735       0.5764697              92.59627
#> 3           3         220        8.028919       0.5145182             125.19868
#> 4           4         207       32.157743       0.5447273             100.08161
#> 5           5         220       17.281597       0.5382466              95.79616
#>   02b_registration_util 03a_examination_wait 03b_examination_util
#> 1             0.8313868             33.71627            0.8440569
#> 2             0.8241213             24.76566            0.8355781
#> 3             0.8363566             22.93733            0.8317090
#> 4             0.7600335             22.39284            0.7850996
#> 5             0.8497077             29.89311            0.8479559
#>   04a_treatment_wait(non_trauma) 04b_treatment_util(non_trauma)
#> 1                       161.3438                      0.8528225
#> 2                       120.8921                      0.8715918
#> 3                       151.4920                      0.8235007
#> 4                       104.7379                      0.8154391
#> 5                       124.9008                      0.8803980
#>   05_total_time(non-trauma) 06a_stabilisation_wait 06b_stabilisation_util
#> 1                  224.4021               322.3138              0.6826987
#> 2                  232.8177               341.0050              0.7482643
#> 3                  226.3541               175.9264              0.8472946
#> 4                  227.6200               217.9818              0.8518988
#> 5                  213.6180               163.9983              0.6404862
#>   07a_treatment_wait(trauma) 07b_treatment_util(trauma) 08_total_time(trauma)
#> 1                   4.930242                  0.2696664              448.4067
#> 2                  20.730095                  0.3229111              501.7710
#> 3                   4.735720                  0.4148506              273.4123
#> 4                  11.741513                  0.3679632              358.0275
#> 5                   5.159307                  0.1560905              347.3643
#>   09_throughput
#> 1           149
#> 2           167
#> 3           149
#> 4           153
#> 5           145