DOC PREVIEW
STEVENS MA 331 - Getting Started with R

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 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 22 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 22 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 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

A Brief Introduction to RWhat is R?Why Use R?Why Not a Spreadsheet?Obtaining RStarting RSome Notes to Help Get You StartedR ObjectsManipulating Lists: Vectors and MatricesAccessing Elements in ArraysBasic OperationsPlots and GraphsMultiple PlotsOther PlotsLists & Data FramesGetting HelpKeeping a Diary, Saving and Loading DataSaving DataWriting Functions & Sourcing CodeGetting Started with RJames Holland Jones∗Department of Anthrop ological Science sStanford UniversityJuly 12, 20051 A Brief Introduction to RIn this summer workshop we will be using the R statistical computing language to facilitateteaching the concepts and methods of formal demography. R provides a convenient environmentfor manipulating lists of numbers (called vectors) and arrays of numb e rs (called matrices). Whilethere are many more c ommon applications that will allow you to manipulate lists of numbers(e.g., spreadsheet programs), R also allows for the easy calculation of a number of quantitiesthat are of vital interest to population biologists. R also provides a powerful environment forperforming numerical simulations, an important tool in the population biologist’s arsenal.What R lacks in apparent user-friendliness, it more than makes up for in power. Whilethere is certainly a learning curve associated with developing the skills you will need to performanalyses in R, this is really true of any software package that you will use. Once you acquiresome of the basics, you will find that using R is logical and simple.A couple questions naturally arise: (1) What is R? and (2) Why use it instead of, say, aspreadsheet application which is more typically use d in introductory demography courses?1.1 What is R?• R is numerical s oftware• R is a “dialect” of the S statistical programming language• R is free• R is state-of-the-art in statistical computing. It is what many (most?) research statisticiansuse in their work∗Correspondence Address: Department of Anthropological Sciences, Building 360, Stanford, CA 94305-2117;phone: 650-723-4824, fax: 650-725-9996; email: [email protected] Why Use R?R has a number attractive features that recommend it for a course such as this.• R is FREE! That, by itself, is almost enough. No complicated lice nsing. Broad dissemi-nation of research methodologies and results, etc.• R is available for a variety of computer platforms (e.g., Linux, MacOS, Windows).• R is widely used by professional statisticians, biologists, demographers, and other scien-tists. This increases the likelihood that code will exist to do a calculation you might wantto do.• R has a remarkable online presence in the form of help lists, tutorials, etc. which willfacilitate solving the problems you inevitably run into in the course of your research.• R represents the state-of-the-art in statistical computing.1.3 Why Not a Spreadsheet?• While a spreadsheet is handy for doing many demographic calculations, it is not ideal formany of the problems we will be tackling.• For example, for a variety of problems in formal demography and population biology,one must calculate an eigenvalue. This is a simple task in an environment such as R orMatlab, but does not exist (to the best of my knowledge in most common spreadsheetapplications.• For some applications, we will be numerically solving ordinary differential equations. Rhas a package to do this, spreadsheet applications lack such facilities.2 Obtaining RThe first step toward successfully using R is to obtain the software. R is freely available andhas been precompiled for a variety of platforms.2Figure 1: The R-Project home page.Go to the R-Project home page (figure 1). The url is: http://www.r-project.org. Fromhere, you can find a wealth of information on R, including extensive online documentation.Follow the link for CRAN (which stands for “The Comprehensive R Archive Network”). Youwill be given a list of mirrors from which to choose. I use the Berkeley mirror (figure 2), but itdoesn’t really matte r which you use – probably one that’s is geographically close to you is best.Here is the url for the Berke ley mirror: http://cran.cnr.berkeley.edu/.Download the precompiled binary that is appropriate for your operating system and followthe instructions provided.Aside for Geeks and Geek-Wannabes If you happen to already be an Emacs user, Ican’t recommend to strongly using ESS (Emacs Speaks Statistics), which allows you to run Rthrough Emacs and thereby capitalize on all its editing, syntax coloration, etc. functionality.3Figure 2: Screenshot of CRAN (Berkeley mirror).For information on using ESS, see http://ess.r-project.org/.43 Starting RStart R. Regardless of your platform, you will get a me ss age that looks something like this:R : Copyright 2005, The R Foundation for Statistical ComputingVersion 2.1.1 (2005-06-20), ISBN 3-900051-07-0R is free software and comes with ABSOLUTELY NO WARRANTY.You are welcome to redistribute it under certain conditions.Type ’license()’ or ’licence()’ for distribution details.Natural language support but running in an English localeR is a collaborative project with many contributors.Type ’contributors()’ for more information and’citation()’ on how to cite R or R packages in publications.Type ’demo()’ for some demos, ’help()’ for on-line help, or’help.start()’ for a HTML browser interface to help.Type ’q()’ to quit R.>Take it for a spin. Try to demo() option.4 Some Notes to Help Get You StartedThese are some notes that I put together for my class, “Human Population Biology,” offeredin the Department of Anthropological Sciences at Stanford. It has a decidedly evolutionary-anthropology flavor, but it should help get you started thinking about doing demographic workin R.4.1 R ObjectsSome discussion of objects. Then we talk about vectors and matrices and eventually lists anddata frames.4.1.1 Manipulating Lists: Vectors and MatricesA vector is simply a list of numbers arranged either as a row or a column. Say that we performa census on a community of chimpanzees. Nishida et al. (1990) suggest that the chimpanzee lifecycle can be meaningfully structured according to the following categories: (1) infant, (2) olderinfant, (3) juve nile, (4) adolescent, (5) older adolescent, (6) prime adult, and (7) old adult. In1980, Nishida et al.’s census of the Mahale Mountain M-group revealed that the com munity iscomposed of 7 infants, 13 older infants, 8 juveniles, 13 adolescents, 5


View Full Document

STEVENS MA 331 - Getting Started with R

Download Getting Started with 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 Getting Started with 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 Getting Started with 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?