[This article was first published on Probability and statistics blog » r, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Sample once from the Uniform(0,1) distribution. Call the resulting value
iters = 200 locations = rep(0,iters) top = 1 multiplier = 2 for(i in 1:iters) { locations[i] = runif(1,0,top) top = locations[i] * multiplier } windows() plot(locations[1:i],1:i,pch=20,col="blue",xlim=c(0,max(locations)),ylim=c(0,iters),xlab="Location",ylab="Iteration") # Optional save as movie, not a good idea for more than a few hundred iterations. I warned you! # library("animation") # saveMovie(for (i in 1:iters) plot(locations[1:i],1:i,pch=20,col="blue",xlim=c(0,max(locations)),ylim=c(0,iters),xlab="Location",ylab="Iteration"),loop=1,interval=.1)
To leave a comment for the author, please follow the link and comment on their blog: Probability and statistics blog » r.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.