0% found this document useful (0 votes)
28 views

A Quick Guide To R Simulation

This document provides a quick guide to simulating continuous and discrete uniform demand in R. It includes instructions on downloading R, setting parameters for the simulations, generating random demands from uniform distributions, and testing ordering policies to minimize costs by calculating the mean of costs per period. The document contains two examples: one that simulates continuous uniform demand between 20 and 40 units, and another that simulates discrete uniform demand that can be 5, 10, 15, 20, 25, or 30 units.

Uploaded by

David Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

A Quick Guide To R Simulation

This document provides a quick guide to simulating continuous and discrete uniform demand in R. It includes instructions on downloading R, setting parameters for the simulations, generating random demands from uniform distributions, and testing ordering policies to minimize costs by calculating the mean of costs per period. The document contains two examples: one that simulates continuous uniform demand between 20 and 40 units, and another that simulates discrete uniform demand that can be 5, 10, 15, 20, 25, or 30 units.

Uploaded by

David Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

A Quick Guide to R

Simulation

Download (Or use R in undergrad computer lab)


Go to https://www.r-project.org/
Select your preferred CRAN mirror and download R based on your
operation system.

Continuous Uniform Demand Simulation


# Setup parameters
Cp =2; Cv = 1; Cs = 0.5;
# How many random demands will be generated?
n = 100000;
#Generate n random demands from the uniform distribution
Demand = runif(n, min = 20, max = 40);
#Test the policy where we order 100/3 gallons for every period
y = 100/3;
mean(Cp*pmin(y,Demand) + Cs* pmax(y-Demand,0) - Cv*y)

Discrete Uniform Demand Simulation


# Setup parameters
Cp =1; Cv = 0.25; Cs = 0;
# How many random demands will be generated?
n = 100000;
#Generate n random demands from the discrete uniform distribution
Demand =
sample(c(5,10,15,20,25,30),n,replace=TRUE,c(1/8,1/8,1/8,1/8,1/4,1/4));
#Test the policy where we order 25 copies for every period
y = 25;
mean(Cp*pmin(y,Demand) + Cs* pmax(y-Demand,0) - Cv*y)

You might also like