Statistics, Visualization and More Using R - R-package...

57
statistics, visualization and more using r R-package simmer Nina Biller, Fabian Köhnke, Sebastian Mayr 20. Mai 2019 Universität Salzburg

Transcript of Statistics, Visualization and More Using R - R-package...

Page 1: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

statistics, visualization and more using r

R-package simmer

Nina Biller, Fabian Köhnke, Sebastian Mayr20. Mai 2019

Universität Salzburg

Page 2: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Table of contents

Introduction

Basic example (hospital)

Extension of the basic example

Extension: simmer.plot

1

Page 3: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

introduction

Page 4: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simulation problems

Example Problems

∙ queue of customers arriving at a bank

∙ interruption in a machine shop process

∙ consultation in a hospital

⇒ simmer: for discrete-event simulation (DES) in R

3

Page 5: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simulation problems

Example Problems

∙ queue of customers arriving at a bank

∙ interruption in a machine shop process

∙ consultation in a hospital

⇒ simmer: for discrete-event simulation (DES) in R

3

Page 6: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

The discrete-event simulation (DES)

∙ modeling, simulating, and analyzing systems

∙ models a system as a discrete sequence of events

∙ stochastic: some variables are random

∙ advantage: involves coincidence and probability

4

Page 7: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Terminology

∙ Entitiy: is an object of interest in the system (e.g. patient)

∙ Attribute: is a property of an entity

∙ Resource: e.g. doctor for a patient

∙ Queue: list that an entitiy enters if a resource is occupied

∙ Event: any change in the state of the system

5

Page 8: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Pipe Operator: %>%

∙ it takes the output of one statement and forwards it as an input ofthe next statement

∙ you can think of it as a ’ THEN ’

∙ function(argument)⇒ argument % > % function()

∙ advantage for complexe code (more readable)

∙ shortcut for mac: shift, command, m

∙ shortcut for windows: string, command, m

6

Page 9: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Pipe Operator example

without the pipe operator:

round ( exp ( d i f f ( log ( x ) ) ) , 1 )

with the pipe operator:

x %>% log ( ) %>%

d i f f ( ) %>%

exp ( ) %>%

round ( 1 )

7

Page 10: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

basic example (hospital)

Page 11: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

example- important functions

∙ simmer(): this method initialises a simulation environment∙ trajectory(): comprises a chain of activities that can be attached toa generator

∙ add_resource(): defines a new resource in a simulationenvironment

∙ add_generator(): attaches a new source of arrivals to a trajectoryfrom a generator function.

∙ run(): executes steps until a given criterion∙ now(): gets the current simulation time∙ log_(): activities for displaying messages preceded by thesimulation time and the name of the arrival.

∙ leave(): activity for leaving the trajectory with some probability9

Page 12: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

log() and leave()

log(.trj, message)leave(.trj, prob)

. . .pa t ient <− t r a j e c t o r y ( ” pat ients path ” ) %>%## add an intake a c t i v i t y ( ” nurse ” )log_ ( ” I am here ” ) %>%leave ( 1 / 5 ) %>%se i ze ( ” nurse ” , 1 ) %>%timeout ( funct ion ( ) 1 5 ) %>%release ( ” nurse ” , 1 ) %>%. . .

10

Page 13: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

extension of the basic example

Page 14: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Extension of the basic example

∙ Extend the trajectory∙ Use random number generators

∙ Define attributes (like health status)

∙ Include Sub- trajectories

∙ Extend the simulation environment∙ Generate patients with higher priority

∙ Run the simulation multiple times

∙ Monitor the simulations

12

Page 15: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Trajectory manipulation

timeout(.trj, task)

dynamical approach:

%>% timeout ( funct ion ( ) rnorm ( 1 , 1 5 ) )

static approach: initialized at the start of the simulation and treatedas a constant

%>% timeout ( rnorm ( 1 , 1 5 ) )

add_generator(.env, name_prefix, trajectory, distribution, ...)

%>% add_generator ( ” pat ient ” , pat ient , funct ion ( )rnorm ( 1 , 10 , 2 ) , mon = 2 )

13

Page 16: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Resource usage

14

Page 17: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Trajectory manipulation - Attributes

Assigning properties to system entities:

Se t _a t t r i bu te ( . t r j , keys , values , . . . )

keys - vector or single variable with the attribute namevalues - integer or function that return an integer (or integer- vector)

pat ient <− t r a j e c t o r y ( ” pat ients ’ path ” ) %>%. . .s e t _a t t r i bu t e ( keys = ” health ” , values = funct ion ( )sample ( 1 : 1 0 0 , 1 ) ) %>%se t _a t t r i bu t e ( ” mark fo r surgery ” , funct ion ( )i f e l s e ( ge t _a t t r i bu te ( env , ” health ” ) <= 10 , 2 , 0 ) ) %>%

. . .15

Page 18: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Trajectory manipulation - branch

branch(.trj, option, continue, ...)

option - Integer or function that returns an integer (0: skip branch, >1 :follow subtrajectory)continue - Boolean (TRUE: system entity resumes main path afterfinishing the subtrajectory

. . .branch ( option = funct ion ( ) i f e l s e ( ge t _a t t r i bu te( env , ” mark fo r surgery ” ) > 1 , 1 , 0 ) , continue = FALSE ,t r a j e c t o r y ( ” surgery ” ) %>%log_ ( ” surgery s ta r ted ” ) %>%se i ze ( ” surgeon ” , 1 ) %>%timeout ( funct ion ( ) rnorm ( 1 , 1 2 0 , 1 0 ) ) %>%release ( ” surgeon ” , 1 )

) %>%. . .

16

Page 19: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Exercise - Trajectory manipulation

Use the provided “bank” example

1. Exercise1.1 The time at the counter should be drawn from the normal distribution

around a mean of 12.1.2 Add an attribute called “mood” and assign random values from 1 to 10

to it (hint use function() sample() )

2. Exercise2.1 Change the parameters in branch in that way, that the sub trajectory

“Talking to the manager” will never be used.2.2 run the simulation for 100 minutes

17

Page 20: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Extension of the basic example

∙ Extend the trajectory∙ Use random number generators

∙ Define attributes (like health status)

∙ Include Sub- trajectories

∙ Extend the simulation environment∙ Generate patients with higher priority

∙ Run the simulation multiple times

∙ Monitor the simulations

18

Page 21: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Setting priority

add_generator(... , distribution, mon = 1, priority = 0, ...)

add_resource(... , preemptive = TRUE , ...)

preemptive - Boolean (TRUE: system entity with higher priority willinterrupt running operations on the specific resource and use itimmediately)

19

Page 22: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Setting priority

. . .env %>%add_resource ( ” nurse ” , preemptive = TRUE , 1 ) %>%add_resource ( ” doctor ” , 2 ) %>%add_resource ( ” surgeon ” , 1 ) %>%add_resource ( ” admin is t ra t ion ” , 1 ) %>%add_generator ( ” pat ient ” , pat ient , funct ion ( )rnorm ( 1 , 10 , 2 ) , mon = 2 ) %>%## add pat ients with higher p r i o r i t y e . g . be t te rinsuranceadd_generator ( ” important_pat ient ” ,pat ient , p r i o r i t y = 1 , at ( c ( 4 0 , 6 7 , 8 9 , 1 3 0 ) ) )

. . .

20

Page 23: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Output

21

Page 24: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Extension of the basic example

∙ Extend the trajectory∙ Use random number generators

∙ Define attributes (like health status)

∙ Include Sub- trajectories

∙ Extend the simulation environment∙ Generate patients with higher priority

∙ Run the simulation multiple times

∙ Monitor the simulations

22

Page 25: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Multiple runs of the simulation

lapply(X, FUN, ...)

X - vectorFUN - function to be applied to each element of X

We have to put the whole simulation (trajectory, definition ofresources ...) into FUN

23

Page 26: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Multiple runs of the simulation

##START REPLICATION LOOP − Recp l i ca te the simulat ion 10times with lapply ( )envs <− lapply ( 1 : 1 0 , funct ion ( i ) {env <− simmer ( ” Hospi ta l ” ). . .

# def ine T ra j e c to r y. . .# def ine resources and generators. . .# run the simulat ion} ) #END rep l i c a t i on> s t r ( envs )L i s t of 10$ : C lasses ’ simmer ’ , ’ R6 ’ <simmer>. . . . 24

Page 27: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Extension of the basic example

∙ Extend the trajectory∙ Use random number generators

∙ Define attributes (like health status)

∙ Include Sub- trajectories

∙ Extend the simulation environment∙ Generate patients with higher priority

∙ Run the simulation multiple times

∙ Monitor the simulations

25

Page 28: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Monitoring:

get_mon_arrivals(.envs, per_resource = FALSE,...)

Returns a data frame with informations about the arrivals of systementitiesper_resource - adds the variable resource to the data frame that isreturned by the function

26

Page 29: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Monitoring:

get_mon_attributes(.envs)Returns a data frame with informations about the attributes ofsystem entities (e.g. ’health’)

27

Page 30: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Monitoring:

get_mon_resources(.envs)Returns a data frame with informations about the resourses of thesimulation

28

Page 31: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Summary

29

Page 32: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Summary

30

Page 33: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Examples

Use the provided example ’bank’

1. Exercise1.1 Add a generator for bank robbers. They should just appear 40 minutes

after starting the simulation1.2 Set the priority level of the bank robber generator to priority = 2. Which

consequences arise from this?

2. Exercise2.1 Replicate the simulation 50 times2.2 Use the monitoring- functions to find out how many people were at the

bank the whole day (180 minutes)

31

Page 34: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

extension: simmer.plot

Page 35: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Extension: simmer.plot

∙ by Iñaki Ucar & Bart Smeets (2017)

∙ Extension provides a set of methods to plot simmer statistics andsimmer trajectories

∙ Helps to decide on recommendations for resources and clarifiesthe simulation’s trajectory

Statistics

∙ Resources: Utilization and Usage

∙ Arrivals: Activity, Flow and Waiting Time

∙ Attributes

Trajectory33

Page 36: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simmer.plot - statistics resources

Utilization = the average use of a resource, total time in use dividedby the total simulation time

resources <− get_mon_resources ( envs )p lo t ( resources , metr ic = ’ u t i l i z a t i o n ’ )

get_mon_resources = monitored data of resourcesmetric = set to ’utilization’

34

Page 37: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

resource utilization

35

Page 38: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

resource utilization

36

Page 39: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simmer.plot - statistics resources

Usage = how many units of the resource are is use in relation to time

resources <− get_mon_resources ( envs )p lo t ( resources , metr ic = ” usage ” , ”names ” ,items= c ( ” server ” , ” queue ” ) )

metric = set to ’usage’

names = can be set to certain resources e.g. ’nurse’ or c(’nurse’,’surgeon’)

items = can be set to ’server’, ’queue’, ’system’ (=server + queue),separately or combined

37

Page 40: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Resource usage

38

Page 41: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Resource usage

39

Page 42: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simmer.plot - statistics arrivals

a r r i v a l s <− get_mon_arr ivals ( envs )p lo t ( a r r i v a l s , metr ic = ” . . . time ” )

’metric’ has to be set to...

∙ activity_time = timeout time, e.g. time spent at nurse, doctor etc.∙ flow_time = total time spent in system∙ waiting_time = time between activity times, flow time - activitytime

40

Page 43: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Waiting time evolution

41

Page 44: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Waiting time evolution

42

Page 45: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simmer.plot - statistics attributes

If attributes are declared, it’s also possible to plot those.

a t t r i bu t e s <− get_mon_attr ibutes ( envs )p lo t ( a t t r i bu t e s )

43

Page 46: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Attribute evolution

44

Page 47: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Change aesthetics with ggplot2

∙ ggplot2 functions as backend to simmer.plot and is automaticallyinstalled with simmer.plot

∙ all simmer.plot statistic plots are ggplot2 objects

∙ ⇒ ggplot2 functions can also be applied to plots created withsimmer.plot

∙ funtions can simply be added with a ’+’ to your defaultsimmer.plot plot

∙ if you’re not familiar with ggplot2 and are interested in modifyingplots, take a look here: Link

45

Page 48: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Change aesthetics with ggplot2

Some useful functions for simmer plots:

∙ resources - utilization: change color and outline of bars:

. . . +geom_bar ( s t a t = ” i d en t i t y ” , f i l l = ” red ” ,co lor = ” blue ” )

∙ arrivals - all: change color of average line:

. . . +geom_smooth ( co lor =” red ” )

∙ attributes: add dots to indicate units

. . . +geom_point ( )

46

Page 49: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Change aesthetics with ggplot2

∙ all: change label of axis:

. . . +y lab ( ” time ” ) +xlab ( ” evolut ion ” )

∙ all: change title of your plot:

. . . +g g t i t l e ( ” t i t l e ” )

47

Page 50: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Change aesthetics with ggplot2

Example: Change color of average line in waiting time plot to green!

a r r i v a l s <− get_mon_arr ivals ( envs )p lo t ( a r r i v a l s , metr ic = ” wai t ing_t ime ” ) +geom_smooth ( co lor = ” green ” )

Attributes plot with no replication. Points added to mark eachpatient.

48

Page 51: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simmer.optim

∙ parameter optimization method∙ example: maximization of number of patients before 4h mark∙ objective: a variable we want to minimize or maximize∙ constraints: upper and lower boundaries on other variables∙ inputs: the simulation parameters that we want to manipulate

⇒ optimization method computes optimal amount of parameters

∙ not officially released, development dormant

⇒ not in the CRAN-repository, installation possible with devtools viagithub

49

Page 52: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

simmer.plot - trajectories

∙ plot generic to visualize diagrams of trajectory objects usingDiagrammeR as backend package

get_pa le t te <− sca les : : brewer_pal ( type = ” type ” , pa le t te = 1 )p lo t ( t r a j e c to r y , f i l l = get_palet te , verbose =FALSE )

scales :: brewer_pal = get brewer_pal function from scales packagesbrewer_pal = color brewer palettetype = must be ’seq’, ’div’ or ’qual’palette = number for color palettetrajectory = in our case ’patient’verbose = can be set to TRUE if additional info is needed

50

Page 53: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Trajectory

51

Page 54: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Trajectory

52

Page 55: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Exercises

1. Exercises: install and load simmer.plot1.1 Take a look at the usage of the resource “counter” in the bank example

and display server and queue lines. What can you observe?1.2 Take a look at the waiting time and change the color of the average line

to red. What can you observe?

2. Change the number of counters to 2 and plot the same two graphsas above. What can you observe?

3. Create a trajectory plot for the bank example with a color paletteof your choice. Also display additional information to thetrajectory. Explain the trajectory in your own words.

53

Page 56: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

References

∙ Parameter Optimization Functions for ’simmer’.https://github.com/r-simmer/simmer.optim (15.05.2019).

∙ Ucar, I. & Smeets, B. Simmer.https://r-simmer.org (15.05.2019).

∙ Ucar I., Smeets B. & Azcorra A. (2018). simmer: Discrete-EventSimulation for R. Journal of Statistical Software, *accepted forpublication*.https://arxiv.org/abs/1705.09746>.

54

Page 57: Statistics, Visualization and More Using R - R-package ...trutschnig.net/Slides_simmer_Biller_Koehnke_Mayr.pdfsimmer.plot - trajectories ∙ plotgenerictovisualizediagramsoftrajectoryobjectsusing

Thanks for your attention!

55