Note: This repository also contains material related to a number of R courses I am an instructor for:
This is the code repository for my 2024 book Exploring Operations Research with R.
Management is the process of converting information into action. The conversion process we call decision making. Jay W. Forrester, Industrial Dynamics (1961).
The idea behind the book is to show how the R Programming language can be a valuable tool that can be successfully applied to the field of operations research (OR).
This approach is centred on the idea of the future OR professional as someone who can combine knowledge of key OR techniques (e.g. simulation, linear programming, data science, and network science) with an understanding of progranming languages such as R, including tools for data representation, manipulation, and analysis.
The aim of the book is to provide a self-contained introduction to R (both Base R and the tidyverse) and show how this knowledge can be applied to a range of OR challenges in the domains of public health, infectious diseases, and energy generation, and so provide a platform to develop actionable insights to support decision making.
The book contains three parts, and code from these three parts can be accessed via the links below.
Part I introduces R, and provides a step-by-step guide to the key features of R. The initial focus is on base R, and data structures, including: vectors, matrices, lists, data frames, and tibbles. The building blocks of R --- functions --- are presented, along with important ideas including environments, functionals, and the S3 object system.
ch 1. Getting started with R --- Code
ch 3. Subsetting vectors --- Code
ch 4. Functions, Functionals and the R Pipe --- Code
ch 5. Matrices and Data Frames --- Code
ch 6. The S3 Object System in R --- Code
Part II, presents R's tidyverse, where the main focus is on: ggplot2
, dplyr
, tidyr
, purrr
, and shiny
, as together these provide a versatile platform for rapidly analyzing, interpreting and visualizing data.
ch 7. Visualization with ggplot2 --- Code
ch 8. Data Transformation with dplyr --- Code
ch 9. Relational Data with dplyr and Tidying Data with tidyr --- Code
ch 10. Processing Data with purrr --- Code
ch 11. Shiny Examples.
Part III focuses on four practical examples of using R to support operations research methods. These are exploratory data analysis, linear programming, agent-based simulation, and system dynamics.
ch 12. Exploratory Data Analysis Examples.
ch 13. Linear Programming - Reddy Mikks Example
ch 14. Agent-Based Simulation - Code
ch 15. System Dynamics - Code
The following software is needed to run the examples:
-
R, which can be downloaded from CRAN at https://cran.r-project.org.
-
RStudio, which is an integrated development environment (IDE) to support R programming. RStudio can be downloaded from https://posit.co/downloads/.
-
Specific packages from CRAN that are used in the book, and this can be done from within RStudio. Examples of packages are
ggplot2
to support visualization, anddeSolve
to support system dynamics modelling.
The following books have been valuable reference resources in writing this textbook.
-
Advanced R by Hadley Wickham, which presents a deep dive into R, and covers many fascinating technical topics, including object-oriented programming and metaprogramming.
-
R for Data Science by Hadley Wickham, Mine Cetinkaya-Rundel and Garrett Grolemund, aimed at data scientists to show how to perform data science with R, RStudio and the tidyverse collection of R packages.
-
Forecasting Principles and Practice by Rob J. Hyndman and George Athanasopoulos, which provides a comprehensive introduction to forecasting methods in R and also presents a valuable data processing pipeline for manipulating time series data.
-
Introduction to Statistical Learning, by Gareth James, Daniela Witten, Trevor Hastie, and Robert Tibshirani which demonstrates the application of the statistical learning methods in R, covering both supervised and unsupervised learning.
-
Tidy Modeling with R, by Max Kuhn and Julia Silge, which introduces a collection of R packages to support modelling and machine learning.