You are on page 1of 3

SPSS: BINOMIAL MONTE CARLO SIMULATION EXAMPLE

Approximating a binomial distribution using SPSS

This guide shows how to approximate a binomial distribution by selecting many samples of
size n from a 0,1 distribution. For each sample, the number of successes, k, is counted.
Then a distribution is created showing how often k occurs. That is an approximation of the
the binomial distribution. Approximations like this are called Monte Carlo simulations. We
empirically estimate how likely each value of k is, by picking many different samples, and
seeing what proportion of the time k occurs in the sample. We’re creating one empirical
estimate of the probability for each possible value of k.

EXAMPLE 1: n = 6, p = .5 Number of samples: 1000

k Frequency Percent Valid Percent Cumulative Percent


0 17 1.7 1.7 1.7
1 105 10.5 10.5 12.2
2 247 24.7 24.7 36.9
3 310 31.0 31.0 67.9
4 211 21.1 21.1 89.0
5 94 9.4 9.4 98.4
6 16 1.6 1.6 100.0
Total 1000 100.0 100.0

K
400

300

200

100
Frequency

Std. Dev = 1.24


Mean = 2.9

0 N = 1000.00
0.0 1.0 2.0 3.0 4.0 5.0 6.0

K
EXAMPLE 2: Also n=6, p= .5 Note that the frequencies are not identical!

k Frequency Percent Valid Percent Cumulative Percent


0 20 2.0 2.0 2.0
1 93 9.3 9.3 11.3
2 213 21.3 21.3 32.6
3 332 33.2 33.2 65.8
4 242 24.2 24.2 90.0
5 83 8.3 8.3 98.3
6 17 1.7 1.7 100.0
Total 1000 100.0 100.0

K
400

300

200

100
Frequency

Std. Dev = 1.22


Mean = 3.0

0 N = 1000.00
0.0 1.0 2.0 3.0 4.0 5.0 6.0

K
HOW THE DATA SET ABOVE WAS CREATED

INPUT PROGRAM .
LOOP #I = 1 TO 1000 .
DO REPEAT X = R1 TO R6 .
COMPUTE X = RV.BERNOULLI(.5) .
END REPEAT .
COMPUTE K = SUM(R1 TO R6) .
END CASE .
END LOOP .
END FILE .
END INPUT PROGRAM .
EXECUTE .
FREQUENCIES VARIABLES = k
/HISTOGRAM = NORMAL .
EXECUTE .

1. Run SPSS and choose File/New/Syntax…


2. Type the syntax in the box above into the SPSS Syntax Editor box.
NOTE: Every line except the line ending in k ends in a required period!
3. In the Syntax Editor box, choose Run/All.

EXPLANATION OF RESULTS

The “1000” tells SPSS to pick 1000 sample at random


The two “R6”’ values indicate that each sample should be of size 6.
‘‘RV.BERNOULLI(.5)’’ indicates a random variable which is one Bernoulli trial with
probability of success equal to .5.

After running this, the Data window will contain 1000 samples, one in each row. Each
sample will have 6 scores and a value of k. k will be the sample sum, or count.

You might also like