DOC PREVIEW
STATISTICAL GRAPHICS FOR VISUALIZING DATA AN INTRODUCTION TO LATTICE GRAPHICS IN R

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

STATISTICAL GRAPHICS FOR VISUALIZING DATAAN INTRODUCTION TO LATTICE GRAPHICS IN RWilliam G. JacobyMichigan State University and ICPSRIndiana University WorkshopJanuary 29, 2010http://polisci.msu.edu/jacoby/iu/graphicsI. Some Basic R ConceptsA. Terminology— “R” and “S”1. The S language was developed at Bell Laboratories, beginning in the 1970’s2. Since the 1990’s, a commercial version of S, called “S-Plus,” has been available.3. R is an independent and collaborative software project which is very similar (but not com-pletely identical) to S.4. R was originally developed by Robert Gentleman and Ross Ihaka from the University ofAuckland (rumor has it that the initial letter of their first names is the source of the name,“R.”)5. Since 1997, an international group of statisticians has continued to develop and oversee theR environment. Additional contributions have been provided by many other analysts.B. R is a computing environment that creates objects by applying functions to other objects.C. Naming R objects (i.e., datasets, variables, functions, etc.)1. R names can be arbitrarily long (but, short names are preferable for practical reasons).2. R names can be composed of letters, numbers, and periods.3. The first character of a name must be a letter, and periods are usually used as word separatorswithin long names.D. R is composed of a base system, which is supplemented by user-supplied “packages.”II. Obtaining and Installing RA. R is open-source software— in other words, it’s free!B. The R base system1. The “central location” for information about R is the web site for “The R Project for Statis-tical Computing,” located at http://www.r-project.org.An Introduction to Lattice Graphics in RJanuary 2010Page 22. Download the executable file required to create your R installation from a mirror site of the“Comprehensive R Archive Network” (CRAN).3. After downloading R, run the executable to install.C. How to install R packages1. Start R in the usual manner (either double-click on the appropriate desktop icon, or selectthe R item from the Windows Start menu).2. Select the “Packages” item from the menu bar.3. Select “Install package(s) . . . ” from the drop-down list.4. Select a CRAN mirror site from the list that R provides, and then select the package thatyou want to install.5. Immediately after installation (i.e., when the R command prompt appears in the Console),the package is ready for use.D. How to load R packages1. Within an R session, packages are typically loaded with the library() function.2. For example, the presentation in this course will employ the “RWinEdt” package (to coor-dinate the WinEdt text processor with R) and the “lattice” package to create the variousgraphs. These are loaded with the following R statements:library(RWinEdt)library(lattice)III. Communicating with RA. The “R Console”1. This is the window through which the user communicates with R2. Commands (usually R functions and/or assignments) are entered on the command line withinthe Console3. Note that R is case-sensitive! Therefore, it is very important to develop (and adhere to) yourown personal rules for using upper- and lower-case letters in R commands.B. Using a text processor with R1. Although commands can be typed directly into R Console, it is usually more convenient touse a text processor to create the commands, and then paste them into the R Console.2. R contains a sparse, but fully functional text processor. Just select the “File” item on themenu bar, and then the “New Script” item from the drop-down list. This will open a separatewindow within which you can type, edit, and submit R commands.3. Any word processor (e.g., MS Word) can be used to create R commands. However, hiddencodes may cause problems. For example, R does not interpret the hyphen from MS Word aasa subtraction or negation operator.4. It is generally better to use a text processor, some of which (e.g., WinEdt, Tinn-R, and ESS)contain special features that facilitate interaction with R.An Introduction to Lattice Graphics in RJanuary 2010Page 3C. R commands1. The structure of a typical R statement is as follows:new.object <- function(arguments)Where: new.object is the name of a new object which is created by the command; the “<-”is the R assignment operator; function() is the name of a previously-defined (or built-in)function; and, arguments are the arguments to that function.2. Typing in the name of an object will cause R to print out the contents of that object.3. Defining an object without giving it a name is equivalent to typing in the name of that object(this may seem like an obtuse point now, but it has great practical importance for latticegraphics).D. A graphical user interface (that is, a “GUI”) for R can be obtained by installing and loading the“Rcmdr” package.IV. Getting Data into RA. Input from the keyboard1. A vector of data values (e.g., the data values for a single observation, or for a single variable)can be input using the c() function.2. Combine vectors into a rectangular matrix, using the rbind() or cbind() functions.B. Reading from an ASCII text file1. The read.table() function.2. Use the file.choose() function to browse to the file.3. Typical format for input data file has one line per observation, with whitespace betweenadjacent values.C. The header record1. The data file can contain a header record which provides variable names for the dataset. Ifso, the header=T must be included in the call to read.table().2. If the header record contains one fewer names than there are columns in the data, R willassume that the first column contains row names, rather than a variable.D. Using data files created by other statistical software1. The “foreign” package can be used to translate data files into R data frames.2. For example, the read.dta() function reads data files created by STATA software.V. Some Basic R Data StructuresA. Data frame— corresponds to structure of a typical multivariate dataset (but don’t confuse witha matrix, which is a different kind of data structure in R!).B. Vector— a unidimensional array of data values (can be either numeric or character), often createdwith the c() function.An Introduction to Lattice Graphics in RJanuary 2010Page 4C. Factor— an array of data values that R regards as non-numeric categories (which R calls “levels”).Note that the levels of a factor can have a specified ordering (the default


STATISTICAL GRAPHICS FOR VISUALIZING DATA AN INTRODUCTION TO LATTICE GRAPHICS IN R

Download STATISTICAL GRAPHICS FOR VISUALIZING DATA AN INTRODUCTION TO LATTICE GRAPHICS IN R
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view STATISTICAL GRAPHICS FOR VISUALIZING DATA AN INTRODUCTION TO LATTICE GRAPHICS IN R and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view STATISTICAL GRAPHICS FOR VISUALIZING DATA AN INTRODUCTION TO LATTICE GRAPHICS IN R 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?