Simulation
Shreyashi Basak
1 / 19
Motivation
Simulating observed value of a RV using a random number.
Necessary for Monte Carlo simulation.
Suppose we roll three dices. What is the probability that the
sum of the outcomes will be greater than 10?
Suppose customers arrive at a service station. Service time
follows an exponential distribution with mean of 5 minutes.
What is the probability that the waiting time is more than 8
minutes?
2 / 19
We use random numbers and following lemma for developing
theory.
Lemma
Let X be a continuous random variable. Then
U = F (X ) ∼ U(0, 1).
3 / 19
Random Number Table:
4 / 19
Simulating observation: Continuous case
Find the CDF function F for the random variable and its
inverse F −1 .
Select a random number from the table and interpret it as a
probability.
Evaluate F −1 at this randomly selected point to obtain a
randomly generated value for the random variable X .
Some authors call it the Inverse Transformation Method.
5 / 19
Problem
Simulate observations for a variable that follows the exponential
(1) distribution using numbers
0.532, 0.345, 0.012, 0.003, 0.987, 0.123 in the given order.
6 / 19
Problem
Simulate observations for a variable that follows the exponential
(1) distribution using numbers
0.532, 0.345, 0.012, 0.003, 0.987, 0.123 in the given order.
Ans.: Take u1 = .532, u2 = .345, u3 = .012, u4 = .003 and so on
with x = F −1 (u) = − ln(1 − u)/λ.
Problem
Find c so that f (x) = c(x − 1)2 for 1 < x ≤ 2 becomes a density
function. Simulate X for random numbers .4358, .8764, .9092 in
the given order.
6 / 19
Problem
Simulate observations for a variable that follows the exponential
(1) distribution using numbers
0.532, 0.345, 0.012, 0.003, 0.987, 0.123 in the given order.
Ans.: Take u1 = .532, u2 = .345, u3 = .012, u4 = .003 and so on
with x = F −1 (u) = − ln(1 − u)/λ.
Problem
Find c so that f (x) = c(x − 1)2 for 1 < x ≤ 2 becomes a density
function. Simulate X for random numbers .4358, .8764, .9092 in
the given order.
Ans.: c = 3 and x = u 1/3 + 1.
6 / 19
Problem
Generate 3 random samples from a standard Cauchy distribution
using inverse sampling method using the random numbers
0.211, 0.456, 0.324.
1 1
Hint.: Pdf of standard Cauchy is f (x) = π 1+x 2 , −∞ < x < ∞.
Problem
Generate 3 random samples from a Weibull(2,3) distribution using
inverse sampling method using the random numbers
0.121, 0.206, 0.324.
α
x
α α−1 − β
Hint.: Pdf of a Weibull distribution is f (x) = β α x e ,
x ≥ 0, α > 0, β > 0
7 / 19
Simulating observation: Discrete case
Example
Simulate 3 entries using Binomial(11, 0.4) using random numbers
0.253, 0.312, 0.456. .
8 / 19
Simulating observation: discrete case (cont...)
Suppose Ob(X ) = {x1 < x2 < . . .} (finite or infinite)
Let u be a random number in consideration. Interpret it as a
probability, that is, as a number between 0 and 1.1 This represents
our entry corresponding to U where U ∼ U((0, 1)).
Choose j such that
FX (xj−1 ) ≤ u < FX (xj ).
Take xj as the observed value corresponding to u.
Convention: u < FX (x1 ) then output is x1 .
1
If we are asked to consider 3 digits then divide by 103 and so on.
9 / 19
Problem
Let X has geometric distribution with parameter p = .20. Use
random numbers .345, .534, .243 in the given order to simulate
values of X .
10 / 19
Problem
Let X has geometric distribution with parameter p = .20. Use
random numbers .345, .534, .243 in the given order to simulate
values of X .
Hint: Let u1 = .345, u2 = .534, u3 = .243 and corresponding
simulated values are 2, 4, 2 respectively.
10 / 19
Problem
Let X follows Poisson with parameter 4. Use random numbers
.345, .834, .222, .783, .034 in the given order to simulate values of
X.
Ans. Simulated values corresponding to given values are 3, 6, 2, 5, 1
(in the given order).
11 / 19
Problem
Using all the random numbers 0.64, 0.73, 0.23, 0.77 and 0.71,
the one binomial random variable observation with parameter
n = 5, p = 0.5 generated is
(i) 2 (ii) 1 (iii) 5 (iv) none of these.
Problem
If U ∼ U(0, 1) and X has probability density function
f (x) = x + 0.5, 0 < x < 1, then the observation of X can be
generated
√ using √ √
−1+ 9−8U −1+ 9+8U −1+ 8U
(i) 2 (ii) 2 (iii) 2 (iv) None of these.
12 / 19
Problem
Suppose that the probabilities are
0.2466, 0.3452, 0.2417, 0.1128, 0.0395, 0.0111, 0.0026 and 0.0005
that there will be 0, 1, 2, 3, 4, 5, 6 or 7 polluting spills in the Great
lakes on any one day. Simulate this model for the four digit
numbers
1189, 2431, 2022, 6541, 6937, 7851, 8551, 4183, 9642, 6799, 9969.
Find the total number of polluting spills in the Great lakes in 11
days.
13 / 19
Problem
Suppose that the probabilities are
0.2466, 0.3452, 0.2417, 0.1128, 0.0395, 0.0111, 0.0026 and 0.0005
that there will be 0, 1, 2, 3, 4, 5, 6 or 7 polluting spills in the Great
lakes on any one day. Simulate this model for the four digit
numbers
1189, 2431, 2022, 6541, 6937, 7851, 8551, 4183, 9642, 6799, 9969.
Find the total number of polluting spills in the Great lakes in 11
days.
Ans.: Total= 0 + 0 + 0 + 2 + 2 + 2 + 3 + 1 + 4 + 2 + 5.
13 / 19
Problem
A company ‘A’ plan to supply raw material to company ‘B’ on a
daily basis according to a Poisson process at the rate of 1 unit per
day. Each day company ‘B’ is supposed to run a quality testing
before accepting the supplied raw material from ‘A’. If the
acceptance of each unit of supplied material is independent with
probability 0.8, using random numbers 0.20, 0.75, 0.66 exactly once
in the given order, simulate the number of units accepted in the
1st and the 2nd day.
14 / 19
Problem
A company ‘A’ plan to supply raw material to company ‘B’ on a
daily basis according to a Poisson process at the rate of 1 unit per
day. Each day company ‘B’ is supposed to run a quality testing
before accepting the supplied raw material from ‘A’. If the
acceptance of each unit of supplied material is independent with
probability 0.8, using random numbers 0.20, 0.75, 0.66 exactly once
in the given order, simulate the number of units accepted in the
1st and the 2nd day.
Answer:
Xi ; Units of raw material on i th day. Then Xi ∼ Poisson(1).
14 / 19
Problem
A company ‘A’ plan to supply raw material to company ‘B’ on a
daily basis according to a Poisson process at the rate of 1 unit per
day. Each day company ‘B’ is supposed to run a quality testing
before accepting the supplied raw material from ‘A’. If the
acceptance of each unit of supplied material is independent with
probability 0.8, using random numbers 0.20, 0.75, 0.66 exactly once
in the given order, simulate the number of units accepted in the
1st and the 2nd day.
Answer:
Xi ; Units of raw material on i th day. Then Xi ∼ Poisson(1).
Xi 0 1 2 3 4 5 6
F [Xi ] 0.368 0.736 0.920 0.981 0.996 0.999 1.000
14 / 19
Yi ; number of units accepted on i th day. Then, Yi ∼ Bin(xi , .8).
15 / 19
Yi ; number of units accepted on i th day. Then, Yi ∼ Bin(xi , .8).
Let U1 ∼ U((0, 1)). We are given u1 = 0.20.
Now, 0.20 < F (X1 = 0) hence simulated value of X1 is 0.
15 / 19
Yi ; number of units accepted on i th day. Then, Yi ∼ Bin(xi , .8).
Let U1 ∼ U((0, 1)). We are given u1 = 0.20.
Now, 0.20 < F (X1 = 0) hence simulated value of X1 is 0.
Proceeding in similar manner, we see that u2 = 0.75 hence we get
x2 = 2 as F (X2 = 1) ≤ u2 < F (X2 = 2).
We have Y2 ∼ Bin(2, 0.8).
Y2 0 1 2
F [Y2 ] 0.04 0.36 1
Using u3 = 0.66, we get that y2 = 2.
Hence, total units accepted in first and second day= 0+ 2= 2.
15 / 19
Problem
A cement factory produces 0 to 5 tons of cements daily according
to Poisson process with λ = 2. The produced cement is shifted to
the retailer in every two days, there are exactly two trucks available
to transport. Each truck (independent of the other truck) has the
capacity of 1, 2 and 3 tons equally likely. The selling of each ton is
independent with probability 0.80. Using random numbers
0.92, 0.71 and 0.55 once in the given order, simulate the net sell of
transported product. (Observations rounded off to 3 decimal
places.)
16 / 19
Problem
A cement factory produces 0 to 5 tons of cements daily according
to Poisson process with λ = 2. The produced cement is shifted to
the retailer in every two days, there are exactly two trucks available
to transport. Each truck (independent of the other truck) has the
capacity of 1, 2 and 3 tons equally likely. The selling of each ton is
independent with probability 0.80. Using random numbers
0.92, 0.71 and 0.55 once in the given order, simulate the net sell of
transported product. (Observations rounded off to 3 decimal
places.)
Ans.: Cement produced in two days= 7 tons. Capacity of truck= 5
tons. Number of tons sold= 4.
16 / 19
Problem
Suppose the claims are made to an insurance company according
to a Poisson process with rate 3 per day. The amount of the claim
is a continuous variable with density U(($1000, $1500)). The
insurance company receives payment of $2000 per day. At the end
of each day settlement is done and if the company runs short with
the money to repay the claim of that day, then company borrows
remaining money, else, in the case of excess money, the excess
money will be used to settle the next day claim rather than
repaying its loan. Use following random numbers exactly once in
given order to simulate
the total amount at the end of the fifth day; the random numbers are
0.22, 0.50, 0.75, 0.12, 0.20, 0.53, 0.10, 0.21, 0.32, 0.01, 0.31, 0.80, 0.71.
Also find the total amount borrowed by the insurance company
during the above mentioned period.
17 / 19
Total amount borrowed= 1040
Total amount at the end of day five= [Link]:
Day Claims Balance amount
after settlement
1 2 -625
2 1 900
3 3 -415
4 0 2000
5 2 1245
18 / 19
Problem
A company has two machines. Each machine has 3 electrical
components. Each electrical component works independently and
2
has a failure time distribution (in hours) f (t) = 2te −t , t > 0. The
components are placed in the machine such that until one fails, the
other does not start and machine does not fail until all the
components fail. Using the random numbers 0.1, 0.7, 0.2
(machine-I), 0.9, 0.3, 0.8 (machine II), simulate number of
machines working more than 3 hours (observations rounded off to
3 decimal places).
19 / 19
Problem
A company has two machines. Each machine has 3 electrical
components. Each electrical component works independently and
2
has a failure time distribution (in hours) f (t) = 2te −t , t > 0. The
components are placed in the machine such that until one fails, the
other does not start and machine does not fail until all the
components fail. Using the random numbers 0.1, 0.7, 0.2
(machine-I), 0.9, 0.3, 0.8 (machine II), simulate number of
machines working more than 3 hours (observations rounded off to
3 decimal places).
Machine I Machine II
.1 0.1054 .9 2.3026
Ans.: .7 1.204 .3 0.3567
.2 0.2231 .8 1.6094
Total 1.5325 Total 4.2687
19 / 19