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 Rolling a Die and Tossing a Coin using R - Quiz Solutions - Prof. Sam Behset, Quizzes of Mathematics

The solutions to quiz 1 for math-338, which involves simulating the outcome of rolling a fair die and tossing a fair coin using r. The r code for simulating 1,000,000 rolls of a die and 1,000,000 tosses of a coin, as well as the analysis of the results. The document also compares the simulation results with the theoretical probabilities of the binomial distribution.

Typology: Quizzes

Pre 2010

Uploaded on 08/18/2009

koofers-user-zsb
koofers-user-zsb 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Math- 338: Quiz 1 Solutions, Wednesday February 25,
2009
(1) Simulations with R: Suppose that we want to simulate 10 times rolling a fair die. We
can use this simple command:
> round(runif(10,0.5,6.5))
[1] 2 3 5 2 2 3 6 5 6 1
I got three 2s, two 6s, two 5s, two 3s, and one 1.
(1) Simulate 1,000,000 rolling of a fair die. Tally your findings. Provide tables of
summaries. Make a comment regarding the big picture behind your simulation
results.
> a=round(runif(1000000,.5,6.5))
> for(i in 1:6)
+
{
+ print(length(a[a==i]))
+ }
[1] 166297
[1] 167058
[1] 166778
[1] 166859
[1] 166672
[1] 166336
(2) Simulate 1000,000 tossing a fair coin. Comment on your findings.
> for(i in 1:2)
1
pf3

Partial preview of the text

Download Simulation of Rolling a Die and Tossing a Coin using R - Quiz Solutions - Prof. Sam Behset and more Quizzes Mathematics in PDF only on Docsity!

Math- 338: Quiz 1 Solutions, Wednesday February 25,

(1) Simulations with R: Suppose that we want to simulate 10 times rolling a fair die. We can use this simple command:

round(runif(10,0.5,6.5)) [1] 2 3 5 2 2 3 6 5 6 1

I got three 2s, two 6s, two 5s, two 3s, and one 1. (1) Simulate 1,000,000 rolling of a fair die. Tally your findings. Provide tables of summaries. Make a comment regarding the big picture behind your simulation results.

a=round(runif(1000000,.5,6.5)) for(i in 1:6)

{

  • print(length(a[a==i]))
  • } [1] 166297 [1] 167058 [1] 166778 [1] 166859 [1] 166672 [1] 166336 (2) Simulate 1000,000 tossing a fair coin. Comment on your findings.

for(i in 1:2)

  • print(length(b[b==i]))
  • } [1] 501304 [1] 498696

(3) Simulate 1000,000 observations from a binomial distribution with probability of success p = 0.6 and the number of trials n = 4. Then using the simulation results, answer the following questions: P r(X ≥ 2) P r(X = 0) P r(X ≤ 2) Next, compare your findings from the simulation study with the actual proba- bilities of the binomial distribution. In other words, calculate the above three probabilities using dbinom and pbinom. This is the power of simulation. Simulations:

c=rbinom(1000000,4,0.6) length(c[c>=2])/ [1] 0. length(c[c==0])/ [1] 0. length(c[c<=2])/ [1] 0. Theoretical: 1-pbinom(1,4,0.6) [1] 0.