sta4321-1 - n<-200 x1<-round(runif(n))

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Simulating Random Variables
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simulating Coin Flips Probability of a head Let 0 represent heads and 1 represent tails. > round(runif(10)) [1] 1 1 0 0 0 0 0 0 1 0 > mean(round(runif(10))) [1] 0.5 > mean(round(runif(1000))) [1] 0.486 > mean(round(runif(10^6))) [1] 0.499662 Arthur Berg Simulating Random Variables 2/ 3
Background image of page 2
Simulating Coin Flips Simulation Paths Now we keep track of the proportion of heads as we increase the sample size
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n<-200 x1<-round(runif(n)) x2<-round(runif(n)) x3<-round(runif(n)) plot(cumsum(x1)/(1:n), type="l", col="red", ylim=c(0,1), lwd=3) lines(cumsum(x2)/(1:n), type="l", col="blue", lwd=3) lines(cumsum(x3)/(1:n), type="l", col="orange", lwd=3) Arthur Berg Simulating Random Variables 3/ 3...
View Full Document

This note was uploaded on 10/04/2011 for the course STA 4321 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 3

sta4321-1 - n<-200 x1<-round(runif(n))

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online