You are on page 1of 11

# ?

Spreadsheet Simulation
Basics
IENG 455
Feng Yang
West Virginia University
1

Outline
Probability Review for Input Modeling
distributions
standard tricks
How SIMTOOLS works
what happens on an iteration
producing random inputs
Common Modeling Techniques
In-Class Practice

1
Probability Distribution
TRIANG Height is proportional
to probability of
outcome near that
value

x
12 15 21

DISCRETE
Height is equal to
the probability of
the outcome

x
1 2 3 4

## When trying to model an uncertain situation using a

probability distribution, the first question is:
What is the collection of possible outcomes?
3

Possible Outcomes
Discrete, and a finite number of them.
# of workers absent out of 70 on a shift
number of defective parts in a lot of 100
number of available presses on Monday
Discrete, and an infinite number of them.
Annual demand for a product
Number of accidents during the year
Number of parts produced until the machine
jams

2
Possible Outcomes (contd)
Continuous, over a finite range.
The actual diameter of a machined part
Number of productive hours during a day
Interest rate change next year on an adjustable rate
mortgage
Continuous, with fixed lower bound.
Total time to complete a work order
Time to failure of a machine or component
Continuous, with infinite upper and lower bounds.
hours a shipment is early or late
deviation of a machined diameter from specs
deviation of demand from forecast

Distributions Classifications
Discrete and a finite number Binomial, Discrete,
Hypergeometric, IntUniform

## Discrete and an infinite number Geometric, Negbin, Poisson

Continuous over a fixed range Beta, Triang, Uniform

## Continuous with a fixed lower ChiSq, Erlang, Expon, Gamma,

bound Lognorm, Pearson5, Pearson6,
Weibull

## Continuous and unbounded Normal, Student t

3
Standard Tricks
X is a random variable
E( X + a ) = E( X ) + a
Var( a X ) = a2 Var( X )
Make a distribution with lower bound 0 into a distribution with
lower bound a.
TRIANINV( RAND( ), 0, 1, 2 ) + a

pdf: pdf:
x x
0 1 2 0 a a+1 a+ 2

## Adding a constant does not change the variance, but does

shift the mean by a. Thus, in this example the new mean is
a +1
7

## Standard Tricks (contd)

Make a distribution with possible outcomes in the range (0,1)
into a distribution whose outcomes have range (a, b) by
multiplying by ( b - a ) and adding a.
Ex: a + ( b - a )*RAND( )

pdf:
x
0 0.03 0.05

## The mean and variance are both changed by this

transformation.
new mean = a + ( b - a ) * (old mean)
new variance = ( b - a )2 *(old variance)
8

4
Creating Uncertainty
How are the random input values generated?

## Random number generator

All simulation languages have a way to produce a sequence of
pseudorandom numbers.
Uniform(0,1) 1 0 x 1
f ( x) =
0 otherwise
Important statistical properties of a sequence of uniformly
distributed random numbers, U1, U2, U3,
1. Uniformity
2. Independence: the probability of observing a value in a
particular interval is independent of the previous values drawn.
9

Generation of
Pseudo-Random Numbers
Goal: produce a sequence of numbers in [0,1] which
simulates, or imitates, the ideal properties of uniform
distribution and independence as closely as possible.
Linear congruential method produces a sequence of
integers, X1, X2, X3, between 0 and m-1:
X i+1 = (aXi + c) mod m, i = 0, 1, 2, ...
Ui = X i / m, i = 1, 2, ...
X0: seed; a: constant multiplier; c: increment; m: modulus

## mod operator: n1 mod n2

returns the remainder after n1 is divided by n2
10

5
Example
X0 = 27, a = 17, c = 43, m = 100

11

X0
27
a
17
c
43
m
100
Pseudo-Random Numbers
(contd)
X0 27
X1 2 U1 0.02 Sequence: 0.02, 0.77, 0.52,
X2 77 U2 0.77
X3 52 U3 0.52 Can only take values from {0,
X4 27 U4 0.27 1/m, 2/m, , (m-1)/m}
X5 2 U5 0.02
X6 77 U6 0.77 Make m a large integer such as
X7 52 U7 0.52
m=248
X8 27 U8 0.27
X9 2 U9 0.02
The pseudorandom numbers as a
X10 77 U10 0.77
X11 52 U11 0.52
long (at least 2 billion) list of
X12 27 U12 0.27 numbers in the interval [0, 1]
X13 2 U13 0.02 that appear to be independent
X14 77 U14 0.77 random values, but are
X15 52 U15 0.52
completely repeatable.
X16 27 U16 0.27
12

6
Random-Variate Generation
Random numbers on the interval [0,1] can be converted into
random values from any distribution.
Inverse Transform Technique can be used to sample from the
exponential, the uniform, the Weibull, and the triangle
distributions and empirical distributions.
E.g., Generating random numbers X1, X2, X3, which have an
exponential distribution.
x
1. Compute the cdf of X: F( x) = 1-e ( x 0)
2. Set F( X ) = U U ~ Uniform(0,1)
Solve F( X ) = U for X in terms of U
1
X = ln(1 U )

3. Generate Uniform RVs U1, U2, U3, and compute
X i = F-1 (U i )
13

Exponential Distribution
500500Uniform(0,1)
Uniform(0,1)
0
1.200
Mean=0.5000224
1.000

## 0.800 The function that

0.600
generates Exponential
0.400

0.200
RVs with mean 1 is
0.000
0 0.25 0.5 0.75 1
X = -ln(1-U)
100%
0 1

500500
Exponential(1)
Exponential(1)
0.900
0.800
Mean=1.000154
The plots show 500
0.700
0.600 U(0,1)s and the
0.500
0.400
0.300
corresponding
0.200
0.100
Exponentials
0.000
0 2 4 6 8

90% 5%
.0499 2.976
14

7
Example
Triangular Distribution
Consider a RV X with pdf pdf:
x, 0 x 1 x

f ( x) = 2 x 1 x 2 0 1 2
0
otherwise
0, x0
2
Step 1: Compute cdf x /2 0 < x 1
F( x) =
1 - (2 - x) /2 1 < x 2
2

1 x>2

Step 2: For 0 X 1, U= X 2 / 2 (0 U 1/2)
For 1 X 2, U = 1 - ( 2 X ) 2 / 2 (1/2 U 1)
0 U 1/ 2
X = F-1 (U ) X = 2U
2 2(1 U ) 1/2 U 1
15

## Common Modeling Techniques

The value of a cell is uncertain, but depends on no other cell.
Ex: The demand for product ABC-123 next month is
modeled as Poisson with mean 1500
In the cell for demand put
= POISINV(RAND( ), 1500)
The uncertain outcome in one period depends on uncertain
outcomes in previous periods.
Ex: For the next 4 quarters, sales in one period are expected
to be the same as the previous period, but with an average
deviation of 20%.
A1: current sales
A2: = NORMINV( RAND( ), A1, 0.2*A1)
A3: = NORMINV( RAND( ), A2, 0.2*A2)
A4: = NORMINV( RAND( ), A3, 0.2*A3)
16

8
Do not confuse functional and statistical dependence:
If a functional relationship is known, use it.
Ex: If number of returns (C1) is a fraction (B1) of number of sales
(A1), first express that logical relationship (C1: = A1*B1), then select
distributions for A1 and B1.
A statistical relationship is a tendency, with the strength
ranging from -1 to +1.
Ex: Sales in market sector A tend to go up with sales in market sector
B. This will be modeled by a correlation.

The value in the cell depends on a specific event that either does
or does not happen.
Ex: If release 2.0 is ready by January (65% chance), then we will
ship 120,000 units; otherwise we will have to release it in June and
we will only ship 40,000 copies.
A1: = BINOMINV( RAND( ), 1 , 0.65 )
B1: = (1-A1)*40000 + A1*120000
or an alternative
B1: = IF(A1=1, 120000, 40000) 17

Drug Development
A drug company is planning to invest in a new drug. The
cost of research has a uniform distribution on \$300,000 to
\$500,000. There is a 40% chance that the drug will not be
effective, in which case there will be no sales. If the drug is
effective, then the total market for the drug is 400,000
people. The company expects their share of the market to
have a triangular distribution with minimum 5%,
maximum 30%, and most likely 20% of the people. For
each person who uses the new drug, the company expects
to make \$100 in sales during the first year. The drug
company would like to know the distribution of profit
they can expect from undertaking this investment.

18

9
Drug Development (contd)
Cost of Drug Development Revenue
Effectiveness ?
Market Share ?
Revenue per person ?
Number of People ?

Total Profit ?

## Total Profit is the random output

Find out the distribution of Total Profit.

19

## Cost of Drug Development Revenue

Effectiveness 0
Market Share 0.129254114
Revenue per person \$100.00
Number of People \$400,000.00

## Total Profit SimTable -493,686.99

0 4,933,579.21
0.001001 -455,347.63
0.002002 -333,638.31
0.003003 -352,831.21
0.004004 6,936,666.44
0.00500501 3,984,978.68

20

10
Histogram of Total Profit (1000 obs.)

## Out of 1000 obs.

Total Profit Num of obs.
<0 390
>2,000,000 608
>6,000,000 412
>8,000,000 202
>10,000,000 42

21

11