creating animations with r
play

Creating Animations with R Yihui Xie Department of Statistics, Iowa - PowerPoint PPT Presentation

Creating Animations with R Yihui Xie Department of Statistics, Iowa State University July 21, 2010 useR! 2010 @ NIST, Gaithersburg, MD 600 HuSpeech[1:10] 400 200 0 2 4 6 8 10 paragraph


  1. Creating Animations with R Yihui Xie Department of Statistics, Iowa State University July 21, 2010 useR! 2010 @ NIST, Gaithersburg, MD 600 HuSpeech[1:10] 400 ● ● ● 200 ● ● ● ● ● ● ● 0 2 4 6 8 10 paragraph index

  2. Contents Introduction Demo in Statistics Iterative Algorithms Random Numbers and Simulations Sampling/Resampling Methods Changes over a Variable Output Formats Other Approaches Conclusions

  3. Introduction ◮ PhD?... ◮ some statistics ideas can be visualized ◮ and hopefully can be fun! ◮ the R package animation ◮ in the beginning, the world was full of math formulae... ◮ let there be animations, and there was ( awake ) audience ◮ ... ◮ and I created the R package animation ◮ to turn ideas into animations, quickly and faithfully ◮ John M. Chambers Statistical Software Award 2009 ◮ begin with install.packages(’animation’) and enjoy!

  4. Newton’s Method Root−finding by Newton−Raphson Method: 5x 3 − 7x 2 − 40x + 100 = 0 ● 1000 Current root: 5.10165938690441 f ( x ) = 5x 3 − 7x 2 − 40x + 100 500 0 ● ● −500 −1000 −6 −4 −2 0 2 4 6 x Figure 1: How Newton’s method works: x k + 1 = x k − f ( x k ) / f ′ ( x k )

  5. Newton’s Method (cont’d) Root−finding by Newton−Raphson Method: atan ( x ) = 0 1.0 Current root: −1.69407960055382 ● 0.5 f ( x ) = atan ( x ) 0.0 ● ● −0.5 −1.0 −4 −2 0 2 4 x Figure 2: and when Newton’s method does not work

  6. Quincunx (the Bean Machine) ● Figure 3: From randomly falling beans to the Normal distribution!

  7. Bootstrapping 1.0 ● ● ● ● ● ● ● ● ● ● ● 0.8 ● ● ● ● ● ● 0.6 ● ● ● x 0.4 ● ● ● ● ● ● 0.2 ● ● ● ● ● 0.0 ● 5 10 15 20 2.0 2.0 1.5 1.5 Density 1.0 1.0 0.5 0.5 0.0 0.0 0.40 0.40 0.45 0.45 0.50 0.50 0.55 0.55 0.60 0.60 0.65 0.65 0.70 0.70 Figure 4: Bootstrapping i.i.d data and show the distribution of ¯ x boot

  8. Moving Window Auto-Regression ● ● 1.0 ● ● ● ● ● ● ● ● ● ● Original data ● ● ● ● ● ● ● ● ● ● 0.0 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● −1.0 ● ● ● ● ● ● ● ● ● ● 0 10 20 30 40 50 1.0 AR(1) coefficient ● 0.5 0.0 −0.5 0 10 20 30 40 50 Figure 5: Moving Window Auto-Regression

  9. Exporting Animations ◮ we can view the animations in the (default) windows graphics device ◮ but Linux users often find the pictures flickering (R does not support double buffering) ◮ the animation package supports four output formats ◮ an HTML page which looks like a movie player ◮ GIF created by ImageMagick ◮ Flash by SWF Tools ◮ PDF by L A T EX with the animate package

  10. Supported Formats Format Function Required tools Viewer Control HTML ani.start() web browser Yes ani.stop() (JavaScript) GIF / saveMovie() ImageMagick image viewer / No ∗ MPEG ( convert ) movie player Flash saveSWF() SWF Tools Flash player / No ∗ ( *2swf ) browser plugin PDF saveLatex() pdfL A T EX Acrobat Reader Yes Table 1: Supported output formats in the animation package (* depends on the viewer)

  11. Other Approaches the other two related packages (on Omegahat and R-Forge) SVGAnnotation SVG animation with smooth transition between animation frames (the function animate() ), but currently only the browser Opera supports SVG animations 1 swfDevice generate native SWF files from R (graphics device swf() ) 1 sorry, this impression came from one year ago and might be inaccurate... Joran told me that Chrome and Safari also support SVG animations: http://yihui.name/en/2010/07/my-talk-on-animations-at-user-2010/

  12. Conclusions ◮ we can reveal the processes of some statistical methods in a very straightforward way ◮ R is flexible enough to keep students awake in class

  13. Thanks! ◮ Q&A? ◮ Homepage & Blog: http://yihui.name (slides & R code available in my CV page) ◮ Email: xie@yihui.name ◮ and check http://animation.yihui.name for more demonstrations online

Recommend


More recommend