The Political Methodologist Newsletter of the Political Methodology Section American Political Science Association Volume 13, Number 2, Fall 2005
Total Page:16
File Type:pdf, Size:1020Kb
The Political Methodologist Newsletter of the Political Methodology Section American Political Science Association Volume 13, Number 2, Fall 2005 Editors: Adam J. Berinsky, Massachusetts Institute of Technology [email protected] Michael C. Herron, Dartmouth College [email protected] Jeffrey B. Lewis, University of California Los Angeles [email protected] Editorial Assistant: Matthew Atkinson, University of California Los Angeles [email protected] Contents Notes From the Editors Welcome back to TPM. Our issue leads off with three arti- Notes from the Editors 1 cles in the computing section. Luke Keele walks us through 3-D graphics in R. Based on his own process of trial and error, this article will be useful for novices and experi- Computing and Software 2 enced users alike. We then move to an overview of the Luke Keele: 3-D Graphics in R ........... 2 new version of STATA reviewed, as usual, by Neal Beck. Finally, Christopher Lawrence and Dick Eddelbuttel intro- Nathaniel Beck: Stata 9: Another First Look . 7 duce Quantian–an open source computing package. Christopher N. Lawrence and Dirk Eddelbuettel: We then turn to two articles about a topic near and Quantian: A Comprehensive Statistical Com- dear (financially speaking) to all our hearts—data entry. puting Environment . 10 Michael Herron discusses how to use Xemacs macros to con- vert ASCII data files to formats that can be easily imported into spreadsheets or statistical packages. Seth Masket, in Data Entry 13 turn, describes the ins and outs of hiring overseas profes- Michael C. Herron: Using XEmacs Macros to sionals to input your data. Process ASCII Data Files . 13 We also have in this issue a review of Box- Seth Masket: Data Entry: Going Pro . 19 Steffensmeier and Jones’ recent book on Event History Mod- els. This book is one of the first in the Analytical Methods for Social Research series, published by Cambridge Univer- Book Reviews 20 sity Press. We plan to review additional titles from this series in future issues. Tze Kwang Teo: Review of Janet M. Box- Steffensmeier and Bradford S. Jones’ Event We close with a note from our section President, History Modeling: A Guide for Social Scien- Janet Box-Steffensmeier, and the call for participation for tists ....................... 20 the 2006 Society for Political Methodology Summer Meet- ing. The next issue of TPM is beginning to take shape, Section Activities 22 but we are always on the lookout for more material. Your submissions and ideas for topics to address are most wel- A note from our Section President . 22 come. Call for Participation: the 2006 Society for Politi- cal Methodology Summer Meeting . 22 The Editors 2 The Political Methodologist, vol. 13, no. 2 Computing and Software 3-D Graphics in R Luke Keele The Ohio State University [email protected] Three dimensional graphics may not be widely used data: two which define the values of the x and y axes and in published work, but in political methodology, three– one for the quantity of interest to be plotted. For users fa- dimensional plots have a number of uses. The plotting of miliar with persp, this is an important difference. In persp, likelihoods and response surfaces from Monte Carlo exper- the response variable needs to be in matrix not vector form. iments are examples of where three–dimensional plots are To use wireframe, the response variable must be in vec- quite useful. tor form. Fortunately, for many users it is probably more The options for software are not extensive, however. convenient to have data in vector form. Excel can produce such graphs but the quality of the plots is As an example, I use data from a Monte Carlo ex- not excellent. One would assume that R would be a natural periment on misspecification in an OLS regression. I want choice for producing such plots given R’s generally excellent to plot the bias as a function of two parameters: α and φ. graphing capabilities. And it is a good choice, but to get I need my data in R to take the following form: publication quality 3-D graphics requires more work than typically required when plotting in R. What I hope to do, > ols[1:20,] here, is save others the time it took me to figure out how to a bias phi produce quality graphics with the wireframe command. 1 0.05 0.01716063 0.05 The standard 3-D plot command in R is persp. 2 0.10 0.04543059 0.05 While one can produce good looking plots with persp, it 3 0.15 0.06780803 0.05 has a couple of key deficiencies when it comes to producing 4 0.20 0.09976802 0.05 publication quality plots. First, the axes do not have the 5 0.25 0.12303042 0.05 full functionality typical in most R plots. One cannot adjust 6 0.30 0.15644003 0.05 the tick marks and must rely on automatic axis creation. 7 0.35 0.19504754 0.05 Second, one cannot use plotmath characters as axis labels. 8 0.40 0.22869483 0.05 Therefore, one is stuck with “Alpha” instead of “α” for axis 9 0.45 0.27677437 0.05 labels. While these may seem like small deficiencies, they 10 0.50 0.32982011 0.05 are problematic when producing publication quality plots. 11 0.55 0.39086068 0.05 The next option in R is to use the wireframe com- 12 0.60 0.45282179 0.05 mand from the lattice package. The lattice library is 13 0.65 0.54175071 0.05 an R implementation of the trellis graphics package in 14 0.70 0.61998347 0.05 S-plus. While the lattice package can do a variety of 15 0.75 0.72936067 0.05 plots, it is primarily designed to plot relationships between 16 0.05 0.02583256 0.10 three variables. Typically, this is done with the xyplot 17 0.10 0.04417769 0.10 command to generate scatterplots between two variables 18 0.15 0.06806339 0.10 conditional on the values of a third variable. The focus 19 0.20 0.09310019 0.10 on this type of plot is unfortunate, since it means that 20 0.25 0.12514266 0.10 surface plots as produced in wireframe tend to be over- looked in the documentation. In fact, the documentation for all the lattice graphics commands is sparse, and for The two parameters, α and φ, both run from 0.05 1 wireframe is particularly thin. This is doubly unfortunate to 0.75 in increments of 0.05. If one only has the response since lattice\trellis commands tend to be complex. variable in vector format, the expand.grid command can To start with, let’s discuss how one’s data needs to be used to create the parameter vectors. See the R docu- be set up. For a single 3-D plot, one needs three vectors of mentation or Fox (2002) for examples. Notice that I have used close increments between the values of α and φ. This 1One can use the freely available trellis manual when using lattice, but it too only gives sparse consideration to the the wireframe command. The Political Methodologist, vol. 13, no. 2 3 will make the surface plot smoother. Next, I need to load use the following: zlab = list(label = "Bias", rot = the lattice package: 90). This is useful when the z-axis label is very long, or to rotate the x- and y-axis labels to be parallel to the axis > library(lattice) when the plot is at an angle. Other changes to the axis la- bels can be made in a similar fashion. See the next plot for To change the background color of the plotting area an example. to white from the default grey, I use a high level plotting Let’s start to clean the plot up. First, you probably command: noticed the box that goes around the outside of the entire plot. Removing it is quite easy, but finding the command > trellis.par.set(theme = col.whitebg()) to do so is not. It is controlled by a high level command for the axes. To remove it, I use trellis.par.set. I also The command trellis.par.set can be used to clean up the axis labeling in the next example: set a large number of graphing parameters. A call to trellis.par.get() will list at least 50 default graphing > trellis.par.set("axis.line", parameters and their values. Now let’s produce a basic 3-D + list(col="transparent")) plot with the wireframe command: > fig2 <- wireframe(bias ~ a * phi, > fig1 <- wireframe(bias ~ a * phi, + data = ols, + data = ols, screen = + screen = list(z = -245, x = -75), + list(z = -245, x = -75), + xlab = expression(paste(alpha)), + xlab = expression(paste(alpha)), + ylab = expression(paste(phi)), + ylab = expression(paste(phi)), + zlab = list(label = "Bias", + zlab = "Bias", + font = 1, cex = 0.60), + zlim = range(seq(0.0, 0.85, + zlim = range(seq(0.0, 0.85, + by=0.20))) + by=0.20))) Bias Bias α α φ φ Figure 2: Removing The Border and Changing Axis Features Figure 1: Basic Plot The call to trellis.par.set removes the box around the plot. Notice now that the axis tick marks are Many of the normal plotting options such as xlab also gone. This is because the command I used to remove and ylab work as expected. One obvious addition to these the border is an axis command. We’ll get the tick marks commands is zlab and zlim.