Skip main navigation

Dynamical plots of relative frequencies of 6s

How to create dynamical plots of relative frequencies?

We have already seen that the relative frequency of observed 6s in most of the simulated instances of 100 dice rolls is close to the ‘fair’ share, 100/6 = 16.667.

It is helpful to watch how the (random) proportion of ‘6’s changes in the course of successive rolls of the dice (see the next image).

Graph showing the relative frequency of 6s against dice rolls. Converging towards the red A/b target line at 16.667.

The R code used to produce this graph is as follows:

# Set a required number of dice rolls: 
n <- 100 
# Now simulate n dice rolls: 
set.seed(2023) 
x <- sample(1:6, size=n, replace=TRUE) 
y <- (x == 6) 
s <- cumsum(y) 
k <- seq(1:n) 
r <- s/k 
plot(r, type="l", lwd=2, xlab="Number of dice rolls", ylab="Relative frequency of 6s") 
abline(h=1/6, lwd=2, lty="dashed", col="red") 

The command  abline(h=1/6)  is used to show the hypothetical ‘target’ 1/6 = 0.16667.

In the image, we see that the proportion of 6s, as a function of the number of dice rolls, aims to approach the target, but the plot may look a bit crude.

It is natural to expect that the convergence should improve with more rolls, say  n=500. The next image shows this improvement.

Plot showing a simulation of frequency of 6s in 500 dice rolls. Converging towards the red a/b line set at 1/6= 0.16667.

The plot in the previous image shows a particular simulation of 500 dice rolls determined by the chosen seed.

Removing this fixation (e.g via set.seed(Sys.time())), we can look at how a newly-simulated random path behaves, as shown in the next image.

Graph showing newly simulated random path for frequency of 6s in 500 dice rolls after removing the fixation.

Every time you repeat this simulation, you will get a new random path – check it out that, in the long run, they all ‘converge’ to the target frequency 1/6 = 0.16667.

These empirical observations are an illustration of the so-called stability of frequencies. The deterministic values emerging in such a random limiting procedure may be interpreted as the probabilities of the outcomes under study.

A theoretical justification of such a result is called the law of large numbers which can be proved as a mathematical fact that follows from some natural assumptions. This will be discussed in greater detail later in the course.

Next steps

In this activity so far, you have developed your awareness of the sampling distribution of frequencies and the stability of frequencies. In the next few step we will finish our study of computer simulations by investigating the use of simulations to ‘measure’ probability and margin of error. 

This article is from the free online

Statistical Methods

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now