Publications by Yihui Xie
Happy New Year with R
I have to admit that the previous post on Christmas is actually not much fun. Today I received another pResent from Yixuan which is more interesting: Basically the code deals with letter polygons (i.e. glyphs) and plot them with proper projections from 3D to 2D space: ## original code by Yixuan <[email protected]>, with my slight modification h...
1111 sym R (3923 sym/1 pcs)
Press Enter in LyX Sweave as You Wish
For a long time I’ve been wondering why we are not able to use Enter in the LyX Scrap environment which was set up by Gregor Gorjanc for Sweave. Two weeks ago, I (finally!) could not help asking Gregor about this issue, as I’m using “LyX + Sweave” more and more in my daily work. He explained it here: LyX-Sweave: mandatory use of control+e...
2384 sym R (1030 sym/1 pcs) 2 img
Guess the Random Seed
Stephanie asked in 511 today if we were able to get the random seed which was set by set.seed() but we were only given the random numbers (without knowing the seed). This kind of “hacker” questions sound interesting. One dirty solution should be the brute-force method, e.g: # x: the random vector; # FUN: the function that generates random num...
1340 sym R (822 sym/2 pcs)
R Tips in Stat 511
Here are some (trivial) R tips in the course Stat 511. I’ll update this post till the semester is over. Formatting R Code I’ve submitted an R package named formatR to CRAN yesterday. This package should be easier than the code below, because there is a GUI to tidy your R code. Install with install.packages('formatR'). Reading code is pain, ...
3565 sym R (6197 sym/8 pcs) 10 img
Font Families for the R PDF Device
Motivated by the excellent R package pgfSweave, I begin to notice the font families in my graphs when writing Sweave documents. The default font family for PDF graphs is Helvetica, which is, in most cases (I think), inconsistent with the LaTeX font styles. Some common font families are listed in ?postscript, and we can take a look at them by: for...
1278 sym R (461 sym/1 pcs)
A Demo for the Ratio Estimation in Sampling Survey (Animation)
Amber Watkins gave me a suggestion on the animation for the ratio estimation, and I think this is a good topic for my animation package. I’ve finished writing the initial version of the function sample.ratio() for this package, which will appear in the version 1.1-2 a couple of days later. As we know, the benefit of ratio estimation is that sam...
1235 sym R (1435 sym/1 pcs) 8 img
Looking for Software Paths in Windows Registry
When we want to call external programs in R under Windows, we often need to know the paths of these programs. For instance, we may want to know where ImageMagick is installed, as we need the convert (convert.exe) utility to convert images to other formats, or where OpenBUGS is installed because we need this path to use the function bugs(). Usuall...
2334 sym R (2957 sym/4 pcs) 2 img
Demonstrating the Power of F Test with gWidgets
We know the real distribution of the F statistic in linear models — it is a non-central F distribution. Under H0, we have a central F distribution. Given 1 – α, we can compute the probability of (correctly) rejecting H0. I created a simple demo to illustrate how the power changes as other parameters vary, e.g. the degrees of freedoms, the no...
1203 sym R (2640 sym/1 pcs)
Rules of Thumb to Meet R Gurus in the Help List
Here is my personal list of rules of thumb for people who want to meet some R gurus (quickly) in the R help mailing list ([email protected]): If you want to meet Dr Bill Venables, just say something about Type III Sum of Squares (better if you also mention the “unbeatable” SAS); If you want to meet Prof Douglas Bates, say something about LS...
1872 sym
formatR: farewell to ugly R code
It is not uncommon to see messy R code which is almost not human-readable like this: # rotation of the word "Animation" # in a loop; change the angle and color # step by step for (i in 1:360) { # redraw the plot again and again plot(1,ann=FALSE,type="n",axes=FALSE) # rotate; use rainbow() colors text(1,1,"Animation",srt=i,col=rainbow(360)[i],ce...
1853 sym R (479 sym/2 pcs) 4 img