

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Math- 338: Solutions to Lab2 Part 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.
.1, .2, .2, and .2.
length(a[a==2])/
length(a[a==3])/
length(a[a==4])/
length(a[a==5])/
length(a[a==6])/