roger barlow hep computing seminar 21 st february 2008

15
R Roger Barlow HEP Computing seminar 21 st February 2008

Upload: beatrice-owens

Post on 03-Jan-2016

36 views

Category:

Documents


0 download

DESCRIPTION

R. Roger Barlow HEP Computing seminar 21 st February 2008. What is R?. A data handling+graphics system with particular emphasis on statistical tools Compare and contrast: PAW, Root, Easyplot, Matlab…. Getting hold of R. Google ‘R download’ and follow instructions Quite painless - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Roger Barlow HEP Computing seminar 21 st  February 2008

RRoger Barlow

HEP Computing seminar

21st February 2008

Page 2: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 2

What is R?

A data handling+graphics system with particular emphasis on statistical tools

Compare and contrast: PAW, Root, Easyplot, Matlab…

Page 3: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 3

Getting hold of R

Google ‘R download’ and follow instructions

Quite painless

Windows and unix versions exist

Page 4: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 4

Philosophy

1.1 The R environmentR is an integrated suite of software facilities for data manipulation, calculation

and graphical display. Among other things it has• an effective data handling and storage facility,• a suite of operators for calculations on arrays, in particular matrices,• a large, coherent, integrated collection of intermediate tools for data analysis,• graphical facilities for data analysis and display either directly at the computer

or on hardcopy,and• a well developed, simple and effective programming language (called ‘S’)

which includes conditionals, loops, user defined recursive functions and input and output facilities. (Indeed most of the system supplied functions are themselves written in the S language.)

The term “environment” is intended to characterize it as a fully planned and coherent system, rather than an incremental accretion of very specific and inflexible tools, as is frequently the case with other data analysis software.

Page 5: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 5

What do you get?

Command line for entering instructions

Help buttonGives help

And manuals

Screen whereplots appear

Page 6: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 6

Example: simple stuff

Page 7: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 7

Assignment and vectors

c means ‘concatenate’

Assignment operators

Page 8: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 8

Plotting

Page 9: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 9

Arguments

Type help

(“<whatever>”)

Eg

help(“rnorm”)

Page 10: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 10

More plotting

Page 11: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 11

Other plots

Page 12: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 12

Functions and scripts

Page 13: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 13

What was in the source file

print("Loading Fourier routines")PIBY2<-asin(1); PI<-2*piby2; TWOPI=2*PI; ROOT2PI=sqrt(TWOPI)alternation<-function(n) {2*(seq(1:n) %% 2)- 1}fourier<-function(data,lo,hi) { nbins <- length(data) nn=round(nbins/2) W <- hi-lo delta <- W /nbins ii<-seq(1,nbins)-1 x<-delta*ii+lo theta<-x*twopi/W fc<-seq(1,nn) fs<-seq(1,nn) for(i in seq(1,nn)){ fc[i]<- sum(cos(i*theta)*data) fs[i]<- sum(sin(i*theta)*data) } fc[nn]=fc[nn]/2 fs[nn]=0 list(c=2*fc/nbins,s=2*fs/nbins, zero=sum(data)/nbins)}

Page 14: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 14

Files and stuff

For hardcopy:>postscript(“<filename>”)>… plotting>dev.off()Also png(“<filename>”) and others

File input>s=read.table(“<filename>")>print(s$V1)>plot(s$V1,s$V2) etcOr read.table(“<filename>”,HEADER=TRUE)And first line of file will be taken as names used instead of V1, V2…

Page 15: Roger Barlow HEP Computing seminar 21 st  February 2008

Roger Barlow: R Slide 15

Interested?

• Type demo() at the prompt