The R Journal Volume 4/2, December 2012
Total Page:16
File Type:pdf, Size:1020Kb
The Journal Volume 4/2, December 2012 A peer-reviewed, open-access publication of the R Foundation for Statistical Computing Contents Editorial . .3 Contributed Research Articles What’s in a Name? . .5 It’s Not What You Draw, It’s What You Don’t Draw . 13 Debugging grid Graphics . 19 frailtyHL: A Package for Fitting Frailty Models with H-likelihood . 28 influence.ME: Tools for Detecting Influential Data in Mixed Effects Models . 38 The crs Package: Nonparametric Regression Splines for Continuous and Categorical Predic- tors.................................................... 48 Rfit: Rank-based Estimation for Linear Models . 57 Graphical Markov Models with Mixed Graphs in R . 65 Programmer’s Niche The State of Naming Conventions in R . 74 News and Notes Changes in R . 76 Changes on CRAN . 80 News from the Bioconductor Project . 101 R Foundation News . 102 2 The Journal is a peer-reviewed publication of the R Foun- dation for Statistical Computing. Communications regarding this pub- lication should be addressed to the editors. All articles are licensed un- der the Creative Commons Attribution 3.0 Unported license (CC BY 3.0, http://creativecommons.org/licenses/by/3.0/). Prospective authors will find detailed and up-to-date submission in- structions on the Journal’s homepage. Editor-in-Chief: Martyn Plummer Editorial Board: Heather Turner, Hadley Wickham, and Deepayan Sarkar Editor Help Desk: Uwe Ligges Editor Book Reviews: G. Jay Kerns Department of Mathematics and Statistics Youngstown State University Youngstown, Ohio 44555-0002 USA [email protected] R Journal Homepage: http://journal.r-project.org/ Email of editors and editorial board: [email protected] The R Journal is indexed/abstracted by EBSCO, DOAJ, Thomson Reuters. The R Journal Vol. 4/2, December 2012 ISSN 2073-4859 3 Editorial by Martyn Plummer rell, explaining advanced graphics features of R. We then have two papers on multilevel models: Il Do Welcome to volume 4, issue 2 of The R Journal. Ha, Maengseok Noh, and Youngjo Lee present the frailtyHL package for fitting survival models, and Rense Nieuwenhuis, Manfred te Grotenhuis, and Changes to the journal Ben Pelzer present the influence.ME package for di- agnostics in multilevel models. We also have two Thomson Reuters has informed us that The R Jour- papers on flexible and robust regression: Zhenghua nal has been accepted for listing in the Science Ci- Nie and Jeffrey Racine discuss nonparametric regres- tation Index-Expanded (SCIE), including the Web of sion splines with the crs package, while John Kloke Science, and the ISI Alerting Service, starting with and Joseph McKean discuss rank-based regression volume 1, issue 1 (May 2009). This complements for linear models with Rfit. Finally, Kayvan Sadeghi the current listings by EBSCO and the Directory of and Giovanni Marchetti show how the ggm package Open Access Journals (DOAJ), and completes a pro- can be used to examine the statistical properties of cess started by Peter Dalgaard in 2010. mixed graphical models. Since The R Journal publishes two issues per year, the delay between acceptance and publication can sometimes be long. In July, we started putting ac- Changes to the editorial board cepted articles online, so that they are immediately accessible. If you want to see a preview of some of The end of the year also brings changes to the edi- the articles in the next issue, go to the “Accepted Ar- torial board. Heather Turner is leaving the board af- ticles” page on the R Journal Web site. ter four years. Heather has been on the board since A minor formatting change in this issue is the in- the first issue of R News and, in addition to being an clusion of back-links in the bibliography. Citations indefatigable editor, is responsible for much of the in The R Journal are hyper-links that will take you computational infrastructure of the journal. Another to the corresponding entry in the bibliography. The departure is Bill Venables, who has been editor of back-links now enable you to go back to the referring Programmer’s Niche since the very first issue of R page. News – the predecessor of The R Journal – in 2001. The last paper handled by Bill is a survey of naming conventions in R by Rasmus Bååth. We welcome Bet- In this issue tina Grün, who will join the editorial board in 2013. I shall be stepping down as Editor-in-Chief and will The Contributed Research Articles section of this be leaving this task in the capable hands of Hadley issue opens with a trio of papers by Paul Mur- Wickham. The R Journal Vol. 4/2, December 2012 ISSN 2073-4859 4 The R Journal Vol. 4/2, December 2012 ISSN 2073-4859 CONTRIBUTED RESEARCH ARTICLES 5 What’s in a Name? The Importance of Naming grid Grobs resulting scene is the same as in Figure1) and call When Drawing Plots in R grid.ls() again to show that the grobs on the dis- play list now have the names that we specified. by Paul Murrell > grid.text(c("text", "circle", "rect"), + x=1:3/4, gp=gpar(cex=c(3, 1, 1)), Abstract Any shape that is drawn using the + name="leftText") grid graphics package can have a name associ- > grid.circle(r=.25, name="middleCircle") ated with it. If a name is provided, it is possi- > grid.rect(x=3/4, width=.2, height=.5, ble to access, query, and modify the shape after + name="rightRect") it has been drawn. These facilities allow for very detailed customisations of plots and also for very > grid.ls(fullNames=TRUE) general transformations of plots that are drawn text[leftText] by packages based on grid. circle[middleCircle] rect[rightRect] Introduction The grid package also provides functions that al- low us to access and modify the grobs on the display When a scene is drawn using the grid graphics pack- list. For example, the following code modifies the cir- age in R, a record is kept of each shape that was used cle in the middle of Figure1 so that its background to draw the scene. This record is called a display list becomes grey (see Figure2). We select the grob to and it consists of a list of R objects, one for each shape modify by specifying its name as the first argument. in the scene. For example, the following code draws The second argument describes a new value for the several simple shapes: some text, a circle, and a rect- gp component of the circle (in this case we are modi- angle (see Figure1). fying the fill graphical parameter). > library(grid) > grid.edit("middleCircle", gp=gpar(fill="grey")) > grid.text(c("text", "circle", "rect"), + x=1:3/4, gp=gpar(cex=c(3, 1, 1))) > grid.circle(r=.25) > grid.rect(x=3/4, width=.2, height=.5) text circle rect Figure 2: The simple shapes from Figure1 with the text circle rect middle circle modified so that its background is grey. The purpose of this article is to discuss why it is useful to provide explicit names for the grobs on the Figure 1: Some simple shapes drawn with grid. grid display list. We will see that several positive consequences arise from being able to identify and The following code uses the grid.ls() function modify the grobs on the display list. to show the contents of the display list for this scene. There is an object, called a grob (short for “graphical object”), for each shape that we drew. The output be- Too many arguments low shows what sort of shape each grob represents and it shows a name for each grob (within square This section discusses how naming the individual brackets). In the example above, we did not specify shapes within a plot can help to avoid the problem any names, so grid made some up. of having a huge number of arguments or parame- ters in a high-level plotting function. > grid.ls(fullNames=TRUE) The plot in Figure3 shows a forest plot, a type text[GRID.text.5] of plot that is commonly used to display the results circle[GRID.circle.6] of a meta-analysis. This plot was produced using the rect[GRID.rect.7] forest() function from the metafor package (Viecht- bauer, 2010). It is also possible to explicitly name each shape This sort of plot provides a good example of how that we draw. The following code does this by spec- statistical plots can be composed of a very large num- ifying the name argument in each function call (the ber of simple shapes. The plot in Figure3 consists of The R Journal Vol. 4/2, December 2012 ISSN 2073-4859 6 CONTRIBUTED RESEARCH ARTICLES Vaccinated Control Author(s) and Year TB+ TB− TB+ TB− Relative Risk [95% CI] Aronson, 1948 4 119 11 128 0.41 [ 0.13 , 1.26 ] Ferguson & Simes, 1949 6 300 29 274 0.20 [ 0.09 , 0.49 ] Rosenthal et al, 1960 3 228 11 209 0.26 [ 0.07 , 0.92 ] Hart & Sutherland, 1977 62 13536 248 12619 0.24 [ 0.18 , 0.31 ] Frimodt−Moller et al, 1973 33 5036 47 5761 0.80 [ 0.52 , 1.25 ] Stein & Aronson, 1953 180 1361 372 1079 0.46 [ 0.39 , 0.54 ] Vandiviere et al, 1973 8 2537 10 619 0.20 [ 0.08 , 0.50 ] TPT Madras, 1980 505 87886 499 87892 1.01 [ 0.89 , 1.14 ] Coetzee & Berjak, 1968 29 7470 45 7232 0.63 [ 0.39 , 1.00 ] Rosenthal et al, 1961 17 1699 65 1600 0.25 [ 0.15 , 0.43 ] Comstock et al, 1974 186 50448 141 27197 0.71 [ 0.57 , 0.89 ] Comstock & Webster, 1969 5 2493 3 2338 1.56 [ 0.37 , 6.53 ] Comstock et al, 1976 27 16886 29 17825 0.98 [ 0.58 , 1.66 ] RE Model 0.49 [ 0.34 , 0.70 ] 0.05 0.25 1.00 4.00 Relative Risk (log scale) Figure 3: A forest plot produced by the forest() function from the metafor package.