Arena2R – An R Package for Arena Simulation Users
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Arena Simulation is a well-known Discrete Event Simulation Software. However, if you are a power user you might want to extend your analysis beyond what Arena’s Process Analyzer offers. In this tutorial, I’ll guide you through the main functions of Arena2R package.
If you’re not an R user, fear not! Arena2R comes with an app you can use to explore your Arena Simulation data. All you’ll have to do is to Install R and R Studio, and run two commands in your R console.
Installation
You can install arena2r from CRAN with:
install.packages("arena2r")
Then, load the package:
library(arena2r) ## Warning: package 'arena2r' was built under R version 3.5.2 library(dplyr) ## Warning: package 'dplyr' was built under R version 3.5.2 ## ## Attaching package: 'dplyr' ## The following objects are masked from 'package:stats': ## ## filter, lag ## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union library(ggplot2)
Exporting Arena Report Database
This is a basic example which shows you how to get your Arena results quickly into R. The basic idea is to run different scenarios and save each of them to a separate csv file. (Yes, you could use Process Analyzer (PAN) to run all scenarios, but to my knowledge, there’s no way to get your data out of the PAN easily).
Follow these steps to get Arena simulation results to R:
- Run your model with \(n\) replications. Do not change the number of replications between scenarios.
- For each scenario, save a csv with simulation results clicking on “Tools > ReportDatabase > Export Summary Statistics to CSV File”. Use the standard options. If Arena throws an error, then you’ll have to figure out how to get your results into a csv file. Sometimes it’s necessary to save the report database as a *.mdb file before generating the csv file.
Using the Shiny App
If you’re not familiar to R, you can run this command on R Console and use the example app.
runArenaApp()
After running this command, the app screen will pop up. You can upload your csv files and play around with the Confidence Interval and Scatter Plots.
Using the Package with an R Script
- Open a new .R file, and run the following code:
# Load the library: library(arena2r) # Define the path to your folder with Arena csv files. In my case, it's here: my_path = "../../../arena2r/inst/Arena14/" # Then, get a tidy results data.frame out of your files! results = arena2r::get_simulation_results(my_path)
You can also play around with the arena_results dataset included in the package. To use it, follow these steps:
library(arena2r) # Load the example dataset: data("arena_results") # Let's call it results results = arena_results knitr::kable(head(results))
Scenario | Statistic | Replication | Value |
---|---|---|---|
SCENARIO 1 | Entity 1.NumberIn | 1 | 233 |
SCENARIO 1 | Entity 1.NumberIn | 2 | 247 |
SCENARIO 1 | Entity 1.NumberIn | 3 | 239 |
SCENARIO 1 | Entity 1.NumberIn | 4 | 261 |
SCENARIO 1 | Entity 1.NumberIn | 5 | 264 |
SCENARIO 1 | Entity 1.NumberIn | 6 | 266 |
After these steps, now you have a tidy data.frame with your results. Let’s get into possible visualizations. Usually, you’ll be interested in the mean confidence interval for some response variable, across scenarios.
# Plot a Statistic confidence interval across scenarios for a response variable. arena2r::plot_confint(sim_results = results, response_variable = "Entity 1.NumberOut")
Now let’s explore the relationship between two variables, across scenarios and replications:
# Now let's plot analyse the relationship between two variables: arena2r::plot_scatter(sim_results = results, x_variable = "Entity 1.NumberIn", y_variable = "Entity 1.NumberOut")
Now let’s go a bit deeper and leverage ggplot2 to create a plot faceted by Scenario:
# If you use ggplot and you want to get more customized plots, I suggest you to spread your data.frame: wide_results = results %>% tidyr::spread(Statistic, Value) # Recreating my plot with ggplot, now loking at Resource Utilization: p = ggplot(data = wide_results, mapping = aes(x = `Resource 1.Utilization`, y = `Entity 1.NumberOut`, color = Scenario)) + geom_point() + facet_wrap(~Scenario) p
Finally, let’s summarise every statistic across all scenarios.
statistics_summary = arena2r::get_statistics_summary(sim_results = results, confidence = 0.95) knitr::kable(head(statistics_summary[,1:6]))
Scenario | Statistic | Mean | SD | Min | Max |
---|---|---|---|---|---|
SCENARIO 1 | Entity 1.NumberIn | 241.03333 | 15.773140 | 209.000000 | 276.0000 |
SCENARIO 1 | Entity 1.NumberOut | 225.13333 | 7.735870 | 205.000000 | 240.0000 |
SCENARIO 1 | Entity 1.NVATime | 0.00000 | 0.000000 | 0.000000 | 0.0000 |
SCENARIO 1 | Entity 1.OtherTime | 0.00000 | 0.000000 | 0.000000 | 0.0000 |
SCENARIO 1 | Entity 1.TotalTime | 11.15272 | 4.850762 | 5.161059 | 25.2438 |
SCENARIO 1 | Entity 1.TranTime | 0.00000 | 0.000000 | 0.000000 | 0.0000 |
I hope you enjoyed the package. Feel free to suggest new features and to contribute to its development!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.