Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Simulation of Fair and Unfair Die: Convergence of Relative Frequencies to Expected Values , Lab Reports of Mathematics

Solutions to problem 2 of lab2 in math-338, where students are required to simulate rolling a fair and an unfair die and observe the convergence of relative frequencies of outcomes to their expected values. Tabulated results of simulations for a fair die and an unfair die using r programming language.

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-by9
koofers-user-by9 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Math- 338: Solutions to Lab2 Part 2
Solution to Problem 2
The gist of this problem is to show that as the number of simulations increases, the relative
frequency of simulated outcomes in each experiment converge to their expected values under
both fair and unfair scenarios. Here, I have tabulated the results of my simulation for the
fair die. Please note that due its random nature, there is no reason that your simulation
values should exactly match mine. However, your simulations should show that the relative
frequency of each outcome in the die experiment converge to 1
6=.1666.
a1=round(runif(10,0.5,6.5))
a2=round(runif(100,0.5,6.5))
a3=round(runif(1000,0.5,6.5))
a4=round(runif(10000,0.5,6.5))
a5=round(runif(100000,0.5,6.5))
a6=round(runif(1000000,0.5,6.5))
number of simulations 1 2 3 4 5 6
10 0.2 0.1 0.2 0.1 0.3 0.1
100 0.17 0.16 0.18 0.21 0.16 0.12
1000 0.165 0.147 0.174 0.170 0.186 0.158
10000 0.1710 0.1628 0.1680 0.1679 0.1643 0.1660
100000 0.16452 0.16668 0.16742 0.16766 0.16606 0.16766
1000000 0.167065 0.167098 0.166617 0.167093 0.166054 0.166073
Table 1: Relative frequency of each outcome for varying number of simulations.
Suppose now, that the aim is to simulate rolling of an unfair die, the one with probabil-
ities: P(1) = .2, P (2) = .1, P (3) = .1, P (4) = .2, P (5) = .2, P (6) = .2. As suggested in class,
we may use the command sample.
Here is a simple way of simulating let’s say, 1000,000 rolls of the unfair die:
> a=sample(c(1,2,3,4,5,6),1000000,replace=T,prob=c(.2,.1,.1,.2,.2,.2))
> length(a[a==1])/1000000
[1] 0.1998
1
pf2

Partial preview of the text

Download Simulation of Fair and Unfair Die: Convergence of Relative Frequencies to Expected Values and more Lab Reports Mathematics in PDF only on Docsity!

Math- 338: Solutions to Lab2 Part 2

Solution to Problem 2

The gist of this problem is to show that as the number of simulations increases, the relative frequency of simulated outcomes in each experiment converge to their expected values under both fair and unfair scenarios. Here, I have tabulated the results of my simulation for the fair die. Please note that due its random nature, there is no reason that your simulation values should exactly match mine. However, your simulations should show that the relative frequency of each outcome in the die experiment converge to 16 = .1666.

a1=round(runif(10,0.5,6.5)) a2=round(runif(100,0.5,6.5)) a3=round(runif(1000,0.5,6.5)) a4=round(runif(10000,0.5,6.5)) a5=round(runif(100000,0.5,6.5)) a6=round(runif(1000000,0.5,6.5))

number of simulations 1 2 3 4 5 6 10 0.2 0.1 0.2 0.1 0.3 0. 100 0.17 0.16 0.18 0.21 0.16 0. 1000 0.165 0.147 0.174 0.170 0.186 0. 10000 0.1710 0.1628 0.1680 0.1679 0.1643 0. 100000 0.16452 0.16668 0.16742 0.16766 0.16606 0. 1000000 0.167065 0.167098 0.166617 0.167093 0.166054 0.

Table 1: Relative frequency of each outcome for varying number of simulations.

Suppose now, that the aim is to simulate rolling of an unfair die, the one with probabil- ities: P (1) =. 2 , P (2) =. 1 , P (3) =. 1 , P (4) =. 2 , P (5) =. 2 , P (6) = .2. As suggested in class, we may use the command sample. Here is a simple way of simulating let’s say, 1000,000 rolls of the unfair die:

a=sample(c(1,2,3,4,5,6),1000000,replace=T,prob=c(.2,.1,.1,.2,.2,.2)) length(a[a==1])/ [1] 0.

Note that the relative frequencies are extremely close to our expected probabilities, .2, .1,

.1, .2, .2, and .2.

  • length(a[a==2])/

  • [1] 0.
  • length(a[a==3])/

  • [1] 0.
  • length(a[a==4])/

  • [1] 0.
  • length(a[a==5])/

  • [1] 0.
  • length(a[a==6])/

  • [1] 0.