introduction to r - ucla statistics · 2010. 12. 16. · intro software installation bugs r...

17
Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva [email protected] February 22, 2011 Irina Kukuyeva [email protected] Introduction to R Stats 100B

Upload: others

Post on 01-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Statistics 100B

Introduction to R

Irina [email protected]

February 22, 2011

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 2: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Outline

1 Introduction

2 Software Installation

3 Common Bugs and Fixes

4 R Resources

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 3: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

1 IntroductionWhat is R?What can you do with R?What is the catch?

2 Software Installation

3 Common Bugs and Fixes

4 R Resources

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 4: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

What is R?

What is R?

“R is a computer language that allows the user toprogram algorithms and use tools that have beenprogrammed by others.”

Zuur et. al. (2009)

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 5: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

What can you do with R?

What can you do with R?

You can ...

do calculations

perform statistical analysis (using available code)

create powerful graphics

write your own functions

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 6: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

What is the catch?

What is the catch?

R has a steep learning curve:

It requires programming...

... but

the programming used in R is very similar across methods

a lot has already been done in terms of statistical tools

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 7: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

1 Introduction

2 Software Installation

3 Common Bugs and Fixes

4 R Resources

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 8: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Installing R

1 Go tohttp://cran.r-project.org/and select either:

MacOS XWindows and base

2 Select to download thelatest version: 2.12.1(2010-12-16)

3 Install and Open. The Rwindow should looksomething like this:

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 9: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

1 Introduction

2 Software Installation

3 Common Bugs and FixesSyntax ErrorTrailing +Error When Performing Operations

4 R Resources

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 10: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Syntax Error

Error: syntax error

Possible causes:

Incorrect spelling (of the function, variable, etc.)

Including a ”+” when copying code from the Console

Having an extra parenthesis at the end of a function

Having an extra bracket when subsetting

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 11: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Trailing +

Trailing +

Possible causes:

Not closing a function call with a parenthesis

Not closing brackets when subsetting

Not closing a function you wrote with a squiggly brace

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 12: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Error When Performing Operations

Error in ... : requires numeric

matrix/vector arguments

Possible causes:

1 Objects are data frames, not matrices

2 Elements of the vectors are characters

Possible solutions:

1 Coerce (a copy of) the data set to be a matrix, with theas.matrix() command

2 Coerce (a copy of) the vector to have numeric entries, withthe as.numeric() command

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 13: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

1 Introduction

2 Software Installation

3 Common Bugs and Fixes

4 R ResourcesGetting Help in RUseful Links for R

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 14: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Getting Help in R

R Help

For help with any function in R ,put a question mark before thefunction name to determine whatarguments to use, examples andbackground information.

1 ?plot

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 15: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Useful Links for R

Online Resources for R I

Download R: http://cran.stat.ucla.edu/

Search Engine for R: http://rseek.org

R Reference Card:http://cran.r-project.org/doc/contrib/Short-refcard.pdf

R Graph Gallery: http://addictedtor.free.fr/graphiques/

R Graphics Gallery:http://research.stowers-institute.org/efg/R/

Statistics with R: http://zoonek2.free.fr/UNIX/48R/all.html

Springer (useR! series):http://www.springerlink.com/home/main.mpx

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 16: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Useful Links for R

Online Resources for R II

UCLA Statistics Information Portal:http://info.stat.ucla.edu/grad/

UCLA Statistical Consulting Center:http://scc.stat.ucla.edu

Irina Kukuyeva [email protected]

Introduction to R Stats 100B

Page 17: Introduction to R - UCLA Statistics · 2010. 12. 16. · Intro Software Installation Bugs R Resources Statistics 100B Introduction to R Irina Kukuyeva ikukuyeva@stat.ucla.edu February

Intro Software Installation Bugs R Resources

Useful Links for R

References

I. Kukuyeva.Basic R.UCLA Statistical Consulting Center, Sept. 28, 2010.http://scc.stat.ucla.edu/mini-courses/materials-from-past-mini-courses/fall-2009-mini-course-materials/

Irina Kukuyeva [email protected]

Introduction to R Stats 100B