Simulations – Long-run behavior of random variables

University of California, Los Angeles
Department of Statistics
Statistics M11
Introduction to Statistical Methods for Business and Economics
Instructor: Nicolas Christou
Winter 2001
Simulations – Long-run behavior of random variables
In this lab you will see how the “law of large numbers” works, through some simulations. To
see for example the long-run average of the discrete random variable X (X is the number that
appears when a die is rolled) you would have to roll a die many many times. The computer
will “roll the die” for us. You then sum these outcomes and you divide by the number of
rolls. This average should be very close to the expected value of X (or the mean of X), as we
discussed in class. The mean of a discrete random variable X is the weighted average of the
values of X, where the weights are the probabilities. But first let’s compute the expected
value of X. This is how:
X
P(X)
1
1/6
2
1/6
3
1/6
4
1/6
5
1/6
6
1/6
E(X)=m=1x1/6 + 2x1/6 + 3x1/6 + 4x1/6 + 5x1/6 + 6x1/6 => E(X)=m=3.5.
There is program called dice2 that will do the experiment for us. The program is already
installed at the computer lab. If you type . dice2 you will receive the following information:
. dice2
Here is how to use dice2
dice2 rolls [numdice numside, save]
rolls = number of rolls of the dice
numdice= the number of dice rolled, default=2
numside= the number of sides on the dice, default=6
The save option saves the resulting data, and
clears out the data currently in memory.
Let’s say that you want to roll one die that has 6 sides (1-6) 10 times. This is what you type:
. dice2 10 1 6, save
10 is the number of rolls, 1 is the number of dice, 6 is the number of
sides.
The program will save the 10 numbers (the result of these 10 rolls) and also will construct a
histogram of these 10 values. You can also see the 10 numbers by typing . list or by typing
. edit . Comment on the shape of the histogram. How would the histogram look if many
trials are to be performed? Answer this question before you actually ask the computer to do
many trials.
Here are the results of these particular 10 rolls.
. list
1.
trials
1
sumdice
3
2.
2
2
3.
3
4
4.
5.
6.
7.
8.
9.
10.
4
5
6
7
8
9
10
4
5
1
1
2
2
5
The trials is the number of trial (1st, 2nd, etc.) and sumdice is
the number that shows up. Later when you will roll two dice
sumdice will represent the sum of the two numbers that appear.
You can ask for the descriptive statistics of these 10 numbers. Here is the Stata output.
. summarize sumdice
Variable |
Obs
Mean
Std. Dev.
Min
Max
---------+----------------------------------------------------sumdice |
10
2.9
1.523884
1
5
The number of observations is 10 (these are the 10 rolls), the mean of these 10 numbers is
2.9, and the standard deviation is 1.523884. Also the minimum was 1 and the maximum was
5. So no 6 was rolled in these 10 trials. The long-run average of X is m=3.5. Obviously the
10 observations produce a mean that is not very close to the long-run average.
Try different number of trials. Every time increase by 50 or 100 and see how the histogram
and the mean change.
Variance and standard deviation:
The variance of a discrete random variable X is the weighted average of the squared
deviations of the values of X from the mean of X. The weights are the probabilities.
Compute the variance of X, where X is the number that appears when a die is rolled,
using the shortcut formula that we discussed in class.
Take the square root to find the standard deviation.
Compare this standard deviation with the standard deviation of the experiment for
different number of rolls. What do you observe?
Rolling two dice:
Repeat the previous work but now you want to roll 2 dice.
Let X be the sum of the two numbers shown. What is the expected number of X?
Using the program dice2 roll the two dice 10 times and then increase the number of
trials by 50 or 100. What do you observe?
-
Repeat with more than 2 dice.
Good Luck!