Sie sind auf Seite 1von 18

Overview Usage Closing Information

R Statistics Overview
Mike Ryckman
University of Arizona

August 29th, 2008

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

What is R?

Open Source Statistics Package (Free/Flexible) Object Oriented Programing Language (Sorta) Managed by CRAN but contributed to by ANYONE

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

Why R?

Free Flexible Tested Transparent Graphics Simulations and Modeling R vs. Stata?

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

Cool Graphics

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

Cool Graphics

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

Cool Graphics

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

Cool Graphics

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

What is R? Why R?

Cool Graphics

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

Getting R

R is available from and managed by CRAN (The Comprehensive R Archive Network). http://cran.r-project.org/ Downloads are available for basically every operating system (Windows, Mac, a variety of Linux-es)

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

Opening R

Figure: The R GUI


Mike Ryckman R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

R as a Calculator

R is basically a really sweet calculator... you type in commands and it evaluates them... >3 + 5 >8 * 2 >5 / 4 >sqrt(35) So everything you type in will be performed and (if warranted) return an answer.

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

Functions and Objects


R basically has two things... functions and objects. An object is something, a function does something. We will talk much more about this as the semester moves along. >c(1,3,5) >x<-c(1,3,5) >x >mean(x) >sum(x) >x*5 First, we see the function c(), this combines a series of objects into a vector. Next we see we can store that vector as the variable x.
Mike Ryckman R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

Libraries

R is very exible... because of this, code for individual operations is stored in various libraries. There are many libraries out there, and it can sometimes be dicult to gure out which ones you need. >library(foreign) This will load the (very common) foreign library... this contains functions for loading data from sources like .dta les.

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

Libraries
Libraries give R its real power. Because R is open source, Libraries an be created by anyoneand indeed, many have been. Examples: foreign has all the tools for importing and exporting data in various formats easily. maptools contains tools for making and coloring maps based on dierent data. Stata cannot do this... RODBC contains tools for connecting to outside databases and drawing information in directly using SQL statements. This is a bit advanced but can be hugely helpful if you know what youre doing. Rcmdr is the R Commander: a special package that makes a nice and easy to use menu interface much like Stata has... This is a great way to get started with R.
Mike Ryckman R Statistics Overview

Overview Usage Closing Information

Getting Started Using R

Getting Data

First we need to open a dta le... >library(foreign) Now, we want to nd our le... >mydata<-read.dta(file.choose()) You can now see your variables... >names(mydata)

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

Problems with R

R can be a bit annoying. Here are some reasons: It is command line onlyit wont help you gure out the right command. It does not have great documentation. Figuring out how to do even basic tasks can sometimes take an annoyingly long time. Its memory usage is optimized for smaller le sizes. Although R can work with large datasets, youll often nd it is painfully slow in its performance in these cases.

Mike Ryckman

R Statistics Overview

Overview Usage Closing Information

R vs. Stata
Most of you will likely nd Stata much easier to useand for good reason. R can do some things that Stata cannot. R also performs a number of tasks in a far easier way (once you know how to do them) than Stata does. Stata is very ecient with large datasets (if you have the memory to open them)R is not. It is also much easier to try out new models and things in Stata than in R. Often youll have a lot of trouble guring out simple commands in R. R is much better at simulations than Stata. With R, youll likely nd you learn a lot more about what is actually happening in your datausually because you can easily replicate the commands yourself.
Mike Ryckman R Statistics Overview

Overview Usage Closing Information

Resources

Introductory Statistics with R, Peter Dalgaard Data Analysis and Graphics Using R, John Maindonald and John Braun Data Analysis Using Regression and Multilevel/Hierarchical Models, Andrew Gelman and Jennifer Hill Linear Models with R, Julian J. Faraway Statistics: An Introduction Using R, Michael J. Crawley

Mike Ryckman

R Statistics Overview

Das könnte Ihnen auch gefallen