[This article was first published on The power of 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.
So I’ve been here dealing with the installation of a software that Yihui Xie suggested me to change the format of the animations displayed in R, she told me that all I needed to do was to go to http://imagemagick.org to download ImageMagick for my operating system and install it, but all I got was lots and lots of files and I haven’t found the one to start the installation, so I decided to post the last 4 animations I was thinking to post in here with the code to create them in case you want to try them by yourselves.
The first animation I’m going to start with is called “Bootstrapping the i.i.d data”, This is a naive version of bootstrapping but may be useful for novices. As you can see in the first image, in the top plot, the circles denote the original dataset, while the red sunflowers (probably) with leaves denote the points being resampled; the number of leaves just means how many times these points are resampled, as bootstrap samples with replacement. The bottom plot shows the distribution of x bar star. The whole process has illustrated the steps of resampling, computing the statistic and plotting its distribution based on bootstrapping.
The code to generate such animation is:
ani.options(ani.height = 500, ani.width = 600, outdir = getwd(),
title = “Bootstrapping the i.i.d data”,
description = “This is a naive version of bootstrapping but
may be useful for novices.”)
ani.start()
par(mar = c(2.5, 4, 0.5, 0.5))
boot.iid(main = c(“”, “”), heights = c(1, 2))
ani.stop()
For the second example I chose an animation called “The concept of confidence intervals”. This animation shows the concept of the confidence interval which depends on the observations: if the samples change, the interval changes too. At last we can see that thecoverage rate will be approximate to the confidence level.
If you want to generate this animation, the code is the next:
ani.options(ani.height = 400, ani.width = 600, outdir = getwd(), nmax = 100,
interval = 0.15, title = “Demonstration of Confidence Intervals”,
description = “This animation shows the concept of the confidence
interval which depends on the observations: if the samples change,
the interval changes too. At last we can see that the coverage rate
will be approximate to the confidence level.”)
ani.start()
par(mar = c(3, 3, 1, 0.5), mgp = c(1.5, 0.5, 0), tcl = -0.3)
conf.int()
ani.stop()
The third animation I chose was one I thought would be pretty useful, it’s called “The Newton-Raphson Method for Root-finding”. I think this animation doesn’t need further explanation, it goes along with the tangent lines and iterates, and you can also change the function that the example gives you to try as default, pretty interesting one.
So the code is:
oopt = ani.options(ani.height = 500, ani.width = 600, outdir = getwd(), nmax = 100,
interval = 1, title = “Demonstration of the Newton-Raphson Method”,
description = “Go along with the tangent lines and iterate.”)
ani.start()
par(mar = c(3, 3, 1, 1.5), mgp = c(1.5, 0.5, 0), pch = 19)
newton.method(function(x) 5 * x^3 – 7 * x^2 – 40 *
x + 100, 7.15, c(-6.2, 7.1), main = “”)
ani.stop()
ani.options(oopt)
The last example I thought would be pretty interesting for the ones who had just started learning probability, it’s called “Simulation of flipping coins”. This animation has provided a simulation of flipping coins, which might be helpful in understanding the concept of probability. This is such a colorful and simple animation, pretty interesting, enjoy it.
If you want to generate it, just type:
oopt = ani.options(ani.height = 500, ani.width = 600, outdir = getwd(), interval = 0.2,
nmax = 50, title = “Probability in flipping coins”,
description = “This animation has provided a simulation of flipping coins,
which might be helpful in understanding the concept of probability.”)
ani.start()
par(mar = c(2, 3, 2, 1.5), mgp = c(1.5, 0.5, 0))
flip.coin(faces = c(“Head”, “Stand”, “Tail”), type = “n”,
prob = c(0.45, 0.1, 0.45), col =c(1, 2, 4))
ani.stop()
ani.options(oopt)
To leave a comment for the author, please follow the link and comment on their blog: The power of 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.