Transcription of Computational Statistics Using R and R Studio An ...
1 Computational Statistics Using R and R StudioAn Introduction for ScientistsRandall PruimSC 11 Education Program (November, 2011)Contents1 An Introduction to Welcome toRandRStudio.. Using R as a Calculator .. R Packages .. Getting Help .. Data .. Summarizing Data .. Additional Notes on R Syntax .. Installing R .. Exercises ..342 Getting Interactive Simple Things ..373 A Crash Course in Statistics for Biologists (and Their Friends) Why Use R? .. Computational Statistics : Where Are All The Formulas? .. Three Illustrative Examples .. The Multi-World Metaphor for Hypothesis Testing .. Taking Randomness Seriously .. Exercises, Problems, and Activities ..704 Some Biology Specific Applications of Working With Sequence Data.
2 Obtaining Sequence Data .. Sequence Alignment ..795 Taking Advantage of the Sharing With and Among Your Students .. Data Mining Activities ..90A More About Installing and Using Packages .. Some Workflow Suggestions .. Working with Data .. PrimaryRData Structures .. More About Vectors .. Manipulating Data Frames .. Functions inR.. 111 Computational Stats with R and RStudio 2011, R PruimSC 11 SeattleAbout These NotesThese materials were prepared for the SC 11 Education Program held in Seattle in November of the material is recycled from two workshops: Teaching Statistics Using R, a workshop conducted prior to the May 2011 United States Con-ference on Teaching can find out more about this workshop Computational Science for Biology Educators, an SC11 workshop held at Calvin College in can find out more about this workshop activities and examples in these notes are intended to highlight a modern approach to Statistics andstatistics education that focuses on modeling, resampling based inference, and multivariate notes contain far more than will be covered in the workshop, so they can serve as a referencefor those who want to learn more.
3 For still more reference material, see the above mentioned notes and R PackagesRcan be obtained Download and installation are pretty straight-forward for Mac, PC, or linux addition toR, we will make use of several packages that need to be installed and loaded (and its dependencies) will be assumed throughout. Other packages may appearfrom time to time, including fastR: companion toFoundations and Applications of Statisticsby R. Pruim abd: companion toAnalysis of Biological Databy Whitlock and Schluter vcd: visualizing categorical dataWe also make use of thelatticegraphics package which is installed withRbut must be loaded an alternative interface be installed as a desktop (laptop) application oras a server application that is accessible to others via the available has provided accounts for Education Program participants on anRStudioserver :8787 There are some things in these notes (in particular those usingmanipulate()) that require theRStudiointerface toR.
4 Most things should work in any flavor NotesMarginal notes appear here and there. Sometimes these are side comments that we wanted to say,Digging DeeperManymarginalnotes will look likethis didn t want to interrupt the flow to mention. These may describe more advanced features of theCaution!But warnings are setdifferently to makesure they catch or make suggestions about how to implement things in the classroom. Some are warningsto help you avoid common pitfalls. Still others contain requests for BoxSo, do you like hav-ing marginal notesin these notes?Document CreationThis document was created November 13, 2011, usingSweaveand R version (2011-07-08).Sweave isR s system for reproducible research and allows text, graphics, andRcode to be intermixedand produced by a single DeeperIf you know LATEXas well asR, thenSweaveprovides anicesolutionformixing the Stats with R and RStudio 2011, R PruimSC 11 SeattleProject MOSAICThe USCOTS11 workshop was developed by Project MOSAIC.
5 Project MOSAIC is a communityof educators working to develop new ways to introduce mathematics, Statistics , computation, andmodeling to students in colleges and purpose of the MOSAIC project is to help us share ideas and resources to improve teaching, andto develop a curricular and assessment infrastructure to support the dissemination and evaluation ofthese ideas. Our goal is to provide a broader approach to quantitative studies that provides bettersupport for work in science and technology. The focus of the project is to tie together better diverseaspects of quantitative work that students in science, technology, and engineering will need in theirprofessional lives, but which are today usually taught in isolation, if at particular, we focus on.
6 ModelingThe ability to create, manipulate and investigate useful and informative mathematicalrepresentations of a real-world analysis of variability that draws on our ability to quantify uncertainty and to drawlogical inferences from observations and capacity to think algorithmically, to manage data on large scales, to visualizeand interact with models, and to automate tasks for efficiency, accuracy, and traditional mathematical entry point for college and university students and a subjectthat still has the potential to provide important insights to today s on support from the US National Science Foundation (NSF DUE-0920350), Project MOSAIC supports a number of initiatives to help achieve these goals, including:Faculty development and training opportunities,such as the USCOTS 2011 workshop and our2010 gathering at the Institute for Mathematics and its ,a series of regularly scheduled seminars, delivered via the Internet, that provide a forum forinstructors to share their insights and innovations and to develop collaborations to refine anddevelop them.
7 A schedule of future M-casts and recordings of past M-casts are available at theProject MOSAIC web site, development of a concept inventory to support teaching is somewhatrare in today s curriculum for modeling to be taught. College and university catalogs are filledwith descriptions of courses in Statistics , computation, and calculus. There are many textbooksin these areas and the most new faculty teaching Statistics , computation, and calculus have asolid idea of what should be included. But modeling is different. It s generally recognized asimportant, but few if instructors have a clear view of the essential construction of syllabi and materialsfor courses that teach the MOSAIC topics in a betterintegrated way. Such courses and materials might be wholly new constructions, or they mightbe incremental modifications of existing resources that draw on the connections between theMOSAIC welcome and encourage your participation in all of these Stats with R and RStudio 2011, R PruimSC 11 Seattle8An Introduction to R1An Introduction to RThis is a lightly modified version of a handout RJP used with his Intro Stats studentsSpring 2011.
8 Aside from the occasional comment to instructors, this chapter could be usedessentially as is with toRandRStudioRis a system for statistical computation and graphics. We useRfor several open-source and freely available for Mac, PC, and Linux machines. This means that thereis no restriction on having to license a particular software program, or have students work in aspecific lab that has been outfitted with the technology of user-extensible and user extensions can easily be made available to commercial quality. It is the package of choice for many statisticians and those who usestatistics becoming very popular with statisticians and scientists, especially in certain sub-disciplines,like genetics. Articles in research journals such asScienceoften include links to theRcode usedfor the analysis and graphics very powerful.
9 Furthermore, it is gaining new features every day. New statistical methodsare often available first access toRin a web browser. This has some additional advantages: no installation isrequired, the interface has some additional user-friendly components, and work begun on one machinecan be picked up seamlessly later on somewhere URL for theRStudioserver on Calvin s supercomputer :8787It is also possible to downloadRStudioserver and set up your own server orRStudiodesktop forstand-alone you have logged in to anRStudioserver, you will see something like Figure 11 Seattle 2011, R PruimComputational Stats with R and RStudioAn Introduction to R9 Figure : Welcome thatRStudiodivides its world into four panels. Several of the panels are further subdividedinto multiple the user some control over which panels are located where and whichtabs are in which panels, so you initial configuration might not be exactly like the one illustrated console panel is where we type commands thatRwill R as a CalculatorRcan be used as a calculator.
10 Try typing the following commands in the console panel.> 5 + 3[1] 8> * [1] 358> sqrt(16)[1] 4 You can save values to named variables for later TipIt s probably bestto settle on usingone or the otherof the right-to-leftassignmentoper-ators rather thantoswitchbackand thisdocument, we willprimarily use thearrow operator.> product = * # save result> product # show the result[1] 358> product <- * # <- is assignment operator, same as => product[1] 358> * -> newproduct # -> assigns to the right> newproduct[1] 358 Once variables are defined, they can be referenced with other operators and Stats with R and RStudio 2011, R PruimSC 11 Seattle10An Introduction to R>.