An introduction to R Honors 207 Cognitive Science (These Slides were Shamelessly Stolen from Dr. Pablo Gomez, DePaul University)

Slides:



Advertisements
Similar presentations
Introduction to S-Plus by Francesco Ferretti Analysis of Biological Data Course Winter term 2007 Dalhousie University.
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
R for Macroecology Aarhus University, Spring 2011.
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
Programming Fundamentals. Programming concepts and understanding of the essentials of programming languages form the basis of computing.
R for Research Data Analysis using R Day1: Basic R Baburao Kamble University of Nebraska-Lincoln.
PHP (2) – Functions, Arrays, Databases, and sessions.
Program Design and Development
R. > log2(32) [1] 5 > sqrt(2) [1] > seq(0, 5, length=6) [1] > plot(sin(seq(0, 2*pi, length=100)))
Alternative text for elementary statistics –Elementary Concepts –Basic Statistics.
R – a brief introduction Johannes Freudenberg Cincinnati Children’s Hospital Medical Center
Guide To UNIX Using Linux Third Edition
Chapter 2: Algorithm Discovery and Design
How to Use the R Programming Language for Statistical Analyses Part I: An Introduction to R Jennifer Urbano Blackford, Ph.D. Department of Psychiatry Kennedy.
What is R Muhammad Omer. What is R  R is the programing language software for statistical computing and data analysis  The R language is extensively.
Statistical Software An introduction to Statistics Using R Instructed by Jinzhu Jia.
What is R By: Wase Siddiqui. Introduction R is a programming language which is used for statistical computing and graphics. “R is a language and environment.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Introduction to the R language
1 An Introduction – UCF, Methods in Ecology, Fall 2008 An Introduction By Danny K. Hunt & Eric D. Stolen Getting Started with R (with speaker notes)
Introduction to Computational Thinking Vicky Chen.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
An brief introduction to R and R Package used in ecology Kechang Niu Department of Ecology, PKU
Session 3: More features of R and the Central Limit Theorem Class web site: Statistics for Microarray Data Analysis.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
Eng Ship Structures 1 Introduction to Matlab.
Using the ‘R’ Language for Bioinformatics
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
An Introduction to R Statistical Computing AMS 597 Stony Brook University Spring 2009 By Tianyi Zhang.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Postgraduate Computing Lectures PAW 1 PAW: Physicist Analysis Workstation What is PAW? –A tool to display and manipulate data. Learning PAW –See ref. in.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
Introduction to R Basics * Based on R tutorial by Lorenza Bordoli.
1 Introduction to R A Language and Environment for Statistical Computing, Graphics & Bioinformatics Introduction to R Lecture 3
Introduction to R Chris Free. Introduction to R Free! Superior (if not comparable) to commercial alternatives Available on all platforms Not just for.
Sihua Peng, PhD Shanghai Ocean University
Programming in R Intro, data and programming structures
R programming language
Introduction to R.
Lecture: MATLAB Chapter 1 Introduction
Software for scientific calculations
Introduce to R chris.
Introduction to R Studio
R Programming.
Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Communication and Coding Theory Lab(CS491)
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Tutorial 10: Programming with javascript
Simulation And Modeling
Presentation transcript:

An introduction to R Honors 207 Cognitive Science (These Slides were Shamelessly Stolen from Dr. Pablo Gomez, DePaul University)

What this is o A short incomplete tour around some of the basic concepts of R as a programming language o Some hints on how to obtain documentation on the many library functions (packages)

R, S and S-plus S: an interactive environment for data analysis developed at Bell Laboratories since S2: RA Becker, JM Chambers, A Wilks S3: JM Chambers, TJ Hastie S4: JM Chambers Exclusively licensed by AT&T/Lucent to Insightful Corporation, Seattle WA. Product name: “S-plus”. Implementation languages C, Fortran. See:

R, S and S-plus S: an interactive environment for data analysis developed at Bell Laboratories since 1976 R: initially written by Ross Ihaka and Robert Gentleman at Dep. of Statistics of U of Auckland, New Zealand during 1990s. Since 1997: international “R-core” team of ca. 15 people with access to common CVS archive. GNU General Public License (GPL) - can be used by anyone for any purpose - contagious Open Source -quality control! -efficient bug tracking and fixing system supported by the user community

What R does and does not o data handling and storage: numeric, textual o matrix algebra o hash tables and regular expressions o high-level data analytic and statistical functions o classes (“OO”) o graphics o programming language: loops, branching, subroutines o is not a database, but connects to DBMSs o has no graphical user interfaces, but connects to Java, TclTk o language interpreter can be very slow, but allows to call own C/C++ code o no spreadsheet view of data, but connects to Excel/MsOffice o no professional / commercial support

R and statistics oStatistics: most packages deal with statistics and data analysis o State of the art: many statistical researchers provide their methods as R packages

R as a calculator > log2(32) [1] 5 > sqrt(2) [1] > seq(0, 5, length=6) [1] > plot(sin(seq(0, 2*pi, length=100)))

variables > a = 49 > sqrt(a) [1] 7 > a = "The dog ate my homework" > sub("dog","cat",a) [1] "The cat ate my homework“ > a = (1+1==3) > a [1] FALSE numeric character string logical

functions and operators Functions do things with data “Input”: function arguments (0,1,2,…) “Output”: function result (exactly one) Example: add = function(a,b) { result = a+b return(result) } Operators: Short-cut writing for frequently used functions of one or two arguments. Examples: + - * / ! & | %

functions and operators Functions do things with data “Input”: function arguments (0,1,2,…) “Output”: function result (exactly one) Functions may also do other things than returning a result. E.g., plot something on the screen: “side effects” *Lexical scope and Statistical Computing. R. Gentleman, R. Ihaka, Journal of Computational and Graphical Statistics, 9(3), p (2000).

vectors, matrices and arrays vector: an ordered collection of data of the same type > a = c(1,2,3) > a*2 [1] Example: we could encode a memory trace as a vector Other vector types: character strings, logical

vectors, matrices and arrays matrix: a rectangular table of data of the same type example: the expression values for genes for 30 tissue biopsies: a matrix with rows and 30 columns. array: 3-,4-,..dimensional matrix example: the red and green foreground and background values for spots on 120 chips: a 4 x x 120 (3D) array.

Lists vector: an ordered collection of data of the same type. > a = c(7,5,1) > a[2] [1] 5 list: an ordered collection of data of arbitrary types. > doe = list(name="john",age=28,married=F) > doe$name [1] "john“ > doe$age [1] 28 Typically, vector elements are accessed by their index (an integer), list elements by their name (a character string). But both types support both access methods.

Branching if (logical expression) { statements } else { alternative statements } else branch is optional

Loops When the same or similar tasks need to be performed multiple times; for all elements of a list; for all columns of an array; etc. for(i in 1:10) { print(i*i) } i=1 while(i<=10) { print(i*i) print(i) i=i+sqrt(i) }

regular expressions A tool for text matching and replacement which is available in similar forms in many programming languages (Perl, Unix shells, Java) > a = c("CENP-F","Ly-9", "MLN50", "ZNF191", "CLH-17") > grep("L", a) [1] > grep("L", a, value=T) [1] "Ly-9" "MLN50" "CLH-17" > grep("^L", a, value=T) [1] "Ly-9" > grep("[0-9]", a, value=T) [1] "Ly-9" "MLN50" "ZNF191" "CLH-17" > gsub("[0-9]", "X", a) [1] "CENP-F" "Ly-X" "MLNXX" "ZNFXXX" "CLH-XX"

Storing data Every R object can be stored into and restored from a file with the commands “save” and “load”. This uses the XDR (external data representation) standard of Sun Microsystems and others, and is portable between MS-Windows, Unix, Mac. > save(x, file=“x.Rdata”) > load(“x.Rdata”)

Importing and exporting data There are many ways to get data into R and out of R. Most programs (e.g. Excel), as well as humans, know how to deal with rectangular tables in the form of tab-delimited text files. > x = read.delim(“filename.txt”) also: read.table, read.csv > write.table(x, file=“x.txt”, sep=“\t”)

Getting help Details about a specific command whose name you know (input arguments, options, algorithm, results): >? t.test or >help(t.test)

Web sites cran.r-project.org Full text search: or with ‘… site:.r-project.org’ or other R-specific keywords