Simulation in R, Part 1

Sunrise

I’m currently taking a class titled Prescriptive Analytics (DS 775 in the UW curriculum). Operations Research (OR) might be a better name for the class… it is the name of the text book we’re using, after all. OR is a broad and advanced field involving various optimization techniques. The fundamental problem involves maximizing or minimizing an outcome by making decisions on variables given certain constraints.

One example is a product mix problem for a manufacturing company. The goal is to maximize profit (the outcome) by deciding how many of each product to make (the decisions) given its capacity to make the products (the constraints).

Another example is the traveling salesman problem. The goal is to find the optimal route for a salesman to visit all cities in his area. For example, a recent homework problem involved finding the shortest distance (the outcome) by finding the best route (the decisions) through all 48 capitals in the contiguous US (the constraint – must visit all capitals).

This week’s topic is simulation… one that I’m finding very interesting. Simulation involves using the computer to imitate an operation or process to estimate its result. It can take many forms, including a combination of physical systems like a road simulator (something my former company, MTS Systems, builds) or wind tunnels. Or it could be used to estimate the likelihood of a team winning a game or a particular party winning seats in an election.

A common use is to estimate operations or processes where the inputs are probabilistic in nature. The goal of this post and the next post is to give you a real world example.

Perhaps like many of you, I enjoy doing home projects. I’m also betting that many of you, like me, are not very good at estimating the time it will take to do the project. For example, let’s say I’m going to build some custom cabinets for my mud room (something on my To Do list… once I get done going to graduate school). Here’s an estimate for the time to take to build this on nights and weekends:

  1. Design – 4 weeks
  2. Build – 8 weeks
  3. Finish – 2 weeks
  4. Install – 1 week

If I add up the times, this project should take me 15 weeks.

However, the reality is that these are just my ‘best guess’ times. The range of outcomes for each step is more likely something like:

  1. Design – Min of 2 weeks, max of 8 weeks
  2. Build – Min of 4 weeks, max of ….I’m not exactly sure (don’t mock me… we’ve all had projects that were supposed to take weeks that have taken months. Or years.)
  3. Finish – Min of 1 week, max of 3 weeks
  4. Install – Done in 1 or 2 weeks, equal in likelihood.

On average, how long will this project really take me? In my next post, I’ll walk you through how to model this in R and run a simulation to answer this question.

Picture details:  Lida sunrise, iPhone 7 Plus, 11/10/2018, f/2.8, 1/60 s, ISO-500