5.6 Random Numbers and Probability Tables 173
5.6 Random Numbers and Probability Tables
In older introductory statistics texts, many backend pages have been devoted
to various statistical tables. Several decades ago, many books of statistical
tables were published. Also, the most respected of statistical journals occa-
sionally published articles consisting of statistical tables.
In 1947 the RAND Corporation published the monograph A Million Ran-
dom Digits with 100,000 Normal Deviates, which at the time was a state-of-
the-art resource for simulation and Monte Carlo methods. The random dig-
its can be found at
http://www.rand.org/monograph
_
reports/MR1418.
html
.
These days, much larger tables of random numbers can be produced by
a single line of code, resulting in a set of random numbers that can pass a
battery of stringent randomness tests. With MATLAB and many other widely
available software packages, statistical tables and tables of random numbers
are now obsolete. For example, tables of binomial CDF and PDF for a specific
n and p can be reproduced by
disp(’binocdf(0:12, 12, 0.7)’);
binocdf(0:12, 12, 0.7)
disp(’binopdf(0:12, 12, 0.7)’);
binopdf(0:12, 12, 0.7)
We will show how to sample and simulate from a few distributions in MAT-
LAB and compare empirical means and variances with their theoretical coun-
terparts. The following annotated MATLAB code simulates from binomial,
Poisson, and geometric distributions and compares theoretical and empirical
means and variances.
%various
_
simulations.m
simu = binornd(12, 0.7, [1,100000]);
% simu is 10000 observations from Bin(12,0.7)
disp(’simu = binornd(12, 0.7, [1,100000]); 12
*
0.7 - mean(simu)’);
12
*
0.7 - mean(simu) %0.001069
%should be small since the theoretical mean is n
*
p
disp(’simu = binornd(12, 0.7, [1,100000]); ...
12
*
0.7
*
0.3 - var(simu)’);
12
*
0.7
*
0.3 - var(simu) %-0.008350
%should be small since the theoretical variance is n
*
p
*
(1-p)
%% Simulations from Poisson(2)
poi = poissrnd(2, [1, 100000]);
disp(’poi = poissrnd(2, [1, 100000]); mean(poi)’);
mean(poi) %1.9976
disp(’poi = poissrnd(2, [1, 100000]); var(poi)’);
var(poi) %2.01501