R (and S, and S-Plus, another program based on S) is an interactive, interpretive, function language.

Size: px
Start display at page:

Download "R (and S, and S-Plus, another program based on S) is an interactive, interpretive, function language."

Transcription

1 R R (and S, and S-Plus, another program based on S) is an interactive, interpretive, function language. Available on Linux, Unix, Mac, and MS Windows systems. Documentation exists in several volumes, and in an on-line help system. On a windows device (such as X11 or MS Windows), the most common interface for R is the RGui, which has a pane called R Console in which R statements can be typed.

2 R Fundamentals Most statements are of the form variable <- function(...) or object or function(...) to make an assignment to display an object to execute a function Instead of <-, can use =, as in the text. (I use <- because I learned R (actually S) over 35 years ago, before = was acceptable in the language.) R is case sensitive.

3 R Fundamentals R objects: variables, vectors, lists, matrices, arrays, formulas, time series, factors (for statistical applictions), data frames (for statistical applictions), fits (for statistical applictions) R has an extensive set of functions, i.e. verbs. The specific meaning depends on the class of the object to which it is applied.

4 Objects are built by constructor functions such as c, data.frame, array, matrix, ts, etc. or by an analysis function such as lm, acf, etc. > A <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow=3) This object is a matrix and can participate in matrix multiplication and so on. Typing A results in A =

5 R Syntax, Functions All actions are functions. A function name is followed by a set of perentheses to enclose arguments. help() or help(plot), e.g. or?plot q() The syntax is somewhat similar to C++, except that there are no special delimiters for statements; statements continue as necessary to complete the function. Statements may be grouped by { and }. Blanks are significant only when it makes sense for them to be. The language is not strongly typed. Numbers are generally single precision floating point numbers.

6 Examples > x <- c(2, 5, 3) > x > z1 < *i > z2 <- complex(real=3, imaginary=4) > z <- scan(file="example.dat") > y <- scan() 1: : : : : > a <- 0:10 > b <- 0:10/10 > c <- seq(from=0, t=1, by=.1) > plot(y,type="1")

7 General Design R deals with functions. This dictates the syntax no statement delimiters (but does use { and }). Comments begin with #. No fixed naming conventions; the wise user, however, adopts mnemonic conventions. Use periods to represent components. Various ways of extracting components. $ component operator: object$member See objects with objects().

8 R Matrices A <- matrix(c(1, 3, 5, 2, 4, 6), nrow=3) x <- c(3, 4) z <- A[2, ] w <- A[2, 1:2] v <- c(1, 2, 1) b <- A%*%x; cc <- v%*%a D <- cbind(a, v) E <- solve(d) f <- solve(d, v) H <- D%*%A L <- D*D M <- D^2 objects() rm(...)

9 Other Operators and Functions <,<=, >, >=, ==,!= &,,! sin, cos,... abs, Arg, sqrt, Re, Im, Conj, round, trunc, floor, ceiling, sign, %%, exp, log, log10 t, crossprod, solve, sink("filename") sink() Plus lots of functions for statistical analyses.

10 Packages in R There are many packages that extend the functionality of R. Each package may contain several functions in a given area of application or of analysis. These must first be installed using files that you usually get from some online respository. Once you choose a mirror site from which to obtain the files, you choose the specific package from a drop-down list. Once a package is installed, it must be loaded in any R session in which you need a function from the package. A package can be loaded by using the drop-down menu under the Packages button, or else it can be loaded by means of the library function in R.

11 Programming Conditionals: if(x >= 3) { y <- 2 z <- 4 } else if (x <= 1) ## note how the command must be continued { y <- 1 } else y <- 5

12 Conditionals Conditionals resolve to a numeric value of 0 for false and 1 for true. They can be operated on. x <- 3 y <- 5*(x>2) + 4 Yields a value of 9 for y.

13 Loops Suppose the vector x is given. n1 <- length(x)-1 y <- rep(1,n1) for (i in 1:n1) { if(x[i+1]<x[i]) y[i]<- -1 } or y <- rep(1,n1) i <- 1 while (i <= n1) { if(x[i+1]<x[i]) y[i]<- -1 i <- i+1 }

14 Vectorization Loops are inefficient in R. Try to implement as statements involving vectors. y <- ifelse(x[-1]<x[1:n1],-1,1) Now, let A be a matrix. Instead of y <- numeric(dim(a)[2]) for (i in 1:dim(A)[2]) { y[i] <- sum(a[,i]) } Use apply: y <- apply(a,2,sum)

15 R Functions for Graphics plot plot.factor pairs brush hist stem barplot persp faces stars matplot And others. The actual appearance of the graph depends on the class of the object. Arguments for functions may be required or optional. Most required ones are positional, many optional ones are keyword.

16 R Functions for Standard Distributions Some distributions: beta f gamma norm t unif

17 R Functions for Standard Distributions Functions d density p cumulative probability q quantile r random number generation Examples: rnorm(25, 100, 8) generates 25 N(100,64) numbers qf(.95, 5, 10) the.95 quantile of an F with 5 and 10 degrees of freedom.

18 The Object Orientation of R Most of the functions of R are overloaded and are data-driven. A new class can be defined by defining a constructor function that gives an identifier to the class: factor <- function(x, levels = sort(unique(x)), labels = as.character(levels)) { y <- match(x, levels) names(y) <- names(x) levels(y) <-labels class(y) <- "factor" y } The function factor will construct an object of class factor.

19 Saving Graphics Files There are several standard formats for storing graphics and pictures. The two I use are Encapsulated PostScript, for use in T E X JPEG, for use in HTML R can save graphics files in either of these formats. One way to do this is make the graph the active window, and then to choose Save as... on the File menu. It is annoying to have to point and click on menus. (Almost) everything I do in R is from a script (program) that I write prior to execution.

20 Graphics Devices The grdevices package has useful functions for specifying where a plot goes ; that is, the device on which it appears. By default, it goes to a pane in the RGui window. The function that opens a new pane, that is, a new device, in the RGui window is windows(). The panes are numbered sequentially; that is, each time windows() is invoked, a new device with a number one greater than the previous one (begining with 2) is created. A particular pane is made the active device by dev.cur(i), where i is the number of the device. A particular pane is closed by dev.off(i), where i is the number of the device.

21 Saving Graphics Files If the graphics device is the active pane in the RGui window, you can save it using the menus in the RGui. On windows devices, you can save the active pane by saveplot( ex0101,type="eps") This function creates a file with the extension eps. Another way of saving a graphics file is by printing directly to it. This is done by using various functions in the grdevices package that specify both the format and the name of the file, for example, pdf( ex0101.pdf ) or postscript( ex0101.eps ). Notice that these functions do not provide a extension on the file name. The file is only saved by using the dev.off() function.

22 Saving and Using Files in R Each time you reference an external file in an R session of course you can use the full path name, which is tiresome and requires multiple changes to a saved R script. R provides help in keeping your work organized into directories. One way is to set a working directory and then all external files come out of or go into that directory until you change it again. setwd( c:/work/china/gt/isye6740_course ) After this command, the command saveplot( ex0101,type="eps")ex0101 puts the file ex0101.eps in c:\work\china\gt\isye6740_course Notice the difference in / and \

23 Saving and Using Files in R If your R program interacts with external files in various directories, setting and resetting the directory is annoying. An alternative to setwd is to define one or more character strings and then use paste. datadir <- c:/work/china/gt/isye6740_course/data graphdir <- c:/work/china/gt/isye6740_course Then x <- read.table(filename=paste(datadir, rats.dat,sep=""))... saveplot(filename=paste(graphdir, ex0101,sep=""),type="eps")

24 Bringing Data into R There are several input functions in R. Which to use depends on the source and format of the data. scan readline read.csv read.table etc. url <- " x <- read.table(url)

25 Random Data Let s create a random dataset of 100 observations on 3 variables. Let s make a random sample from a N 3 (0,Σ) distribution where Σ = set.seed(555) sqrtsigma <- matrix(c(12, 0, 5, 0, 13, 0, 5, 0, 1), byrow=t, ncol=3) x <- matrix(rnorm(300), ncol=3) x <- x%*%sqrtsigma

26 Random Data Let s check our random dataset sqrtsigma%*%sqrtsigma [,1] [,2] [,3] [1,] [2,] [3,] round(cov(x)) [,1] [,2] [,3] [1,] [2,] [3,]

27 Saving and Using Graphics Then let s make a scatterplot graph of the first two variables (columns), save it, and then use it. setwd( c:/work/china/gt/isye6740_course ) set.seed(555) sqrtsigma <- matrix(c(12, 0, 5, 0, 13, 0, 5, 0, 1), byrow=t, ncol=3) x <- matrix(rnorm(300), ncol=3) x <- x%*%sqrtsigma plot(x[,1],x[,2]) saveplot( ex0101a,type="eps") saveplot( ex0101a,type="jpg")

28 Saving and Using Graphics Now in a T E X file in that directory, I use \begin{center} \includegraphics[width=5in,height=5in]{ex0101a.eps} \end{center} and in an HTML file in that directory, I use <img src="ex0101a.jpg" alt="x1 vs x2" width="800" height="800" border="0">

29 Saving and Using Graphics Example. In the LAT E X file that produces what you re seeing, the next 3 executable lines, which will be invisible, are the three lines on the previous slide. x[, 2] x[, 1]

30 More on Random Data and Graphics Let s generate a random dataset of 100 observations on 2 variables, where each observation is randomly from either a N 2 (0, Σ 1 ) distribution or a N 2 (0,Σ 2 ) distribution, with a fixed and independent probability of p 1 of being from the first distribution. Let Σ 1 = [ ] Σ 2 = So how do you get the square root matrix? [ ] Initialize S1, then svd.s1 <- svd(s1) sqrt.s1<-sqrt(svd.s1$d[1])*svd.s1$u[,1]%*%t(svd.s1$v[,1])+ sqrt(svd.s1$d[2])*svd.s1$u[,2]%*%t(svd.s1$v[,2])

31 To convert Z N 2 (0, I) to X N 2 (0, Σ 1 ), we can set but another way is X = ZΣ 1/2 1, X = ZT Σ1, where T Σ1 is the Cholesky factor of Σ 1. TS1 <- chol(s1)

32 The Random Data Now let s generate the random data from the two distributions and put them in a matrix with a third column of -1 and 1 to indicate the class. set.seed(5) n <- 500 X <- matrix(c(rnorm(2*n),rep(1,n)),nrow=n) S1 <- matrix(c(109, 45, 45, 34), byrow=t, ncol=2) TS1 <- chol(s1) S2 <- matrix(c( 53, -38, -38, 148), byrow=t, ncol=2) TS2 <- chol(s2) p1 <- 0.6 n1 <- rbinom(1,n,p1) X[1:n1,1:2] <- X[1:n1,1:2]%*%TS1 X[1:n1,3] <- rep(-1,n1) X[(n1+1):n,1:2] <- X[(n1+1):n,1:2]%*%TS2 rindex <- sample(n) X <- X[rindex,]

33 Now let s plot the data and make the color of the plotting character depend on the class of the observation. We ll use colors 2 (red) and 3 (green), with green for the group = -1. plot(x[,1],x[,2],xlim=c(min(x[,1],x[,2]),max(x[,1],x[,2])), ylim=c(min(x[,1],x[,2]),max(x[,1],x[,2])), xlab=expression(italic(x)[1]),ylab=expression(italic(x)[2]), col=(x[,3]<0)+2) legend("topright",legend=c("group 1","Group -1"),pch=c(1,1),col=c(2,3 saveplot( ex0102,type="eps")

34 This yields X Group 1 Group X 1

35 Packages in R A useful R package for statistical learning is class. This contains, among other functions, a function to do k-nearest neighbors.

Computational Statistics General Background Information

Computational Statistics General Background Information Computational Statistics General Background Information Brief introduction to R. R functions. Monte Carlo methods in statistics. Uniform random number generation. Random number generation in R. 1 A Little

More information

Short Introduction to R

Short Introduction to R Short Introduction to R Paulino Pérez 1 José Crossa 2 1 ColPos-México 2 CIMMyT-México June, 2015. CIMMYT, México-SAGPDB Short Introduction to R 1/51 Contents 1 Introduction 2 Simple objects 3 User defined

More information

Description/History Objects/Language Description Commonly Used Basic Functions. More Specific Functionality Further Resources

Description/History Objects/Language Description Commonly Used Basic Functions. More Specific Functionality Further Resources R Outline Description/History Objects/Language Description Commonly Used Basic Functions Basic Stats and distributions I/O Plotting Programming More Specific Functionality Further Resources www.r-project.org

More information

STAT 571A Advanced Statistical Regression Analysis. Introduction to R NOTES

STAT 571A Advanced Statistical Regression Analysis. Introduction to R NOTES STAT 571A Advanced Statistical Regression Analysis Introduction to R NOTES 2015 University of Arizona Statistics GIDP. All rights reserved, except where previous rights exist. No part of this material

More information

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar

More information

A brief introduction to R

A brief introduction to R A brief introduction to R Cavan Reilly September 29, 2017 Table of contents Background R objects Operations on objects Factors Input and Output Figures Missing Data Random Numbers Control structures Background

More information

Introduction to R. UCLA Statistical Consulting Center R Bootcamp. Irina Kukuyeva September 20, 2010

Introduction to R. UCLA Statistical Consulting Center R Bootcamp. Irina Kukuyeva September 20, 2010 UCLA Statistical Consulting Center R Bootcamp Irina Kukuyeva ikukuyeva@stat.ucla.edu September 20, 2010 Outline 1 Introduction 2 Preliminaries 3 Working with Vectors and Matrices 4 Data Sets in R 5 Overview

More information

Stochastic Models. Introduction to R. Walt Pohl. February 28, Department of Business Administration

Stochastic Models. Introduction to R. Walt Pohl. February 28, Department of Business Administration Stochastic Models Introduction to R Walt Pohl Universität Zürich Department of Business Administration February 28, 2013 What is R? R is a freely-available general-purpose statistical package, developed

More information

This document is designed to get you started with using R

This document is designed to get you started with using R An Introduction to R This document is designed to get you started with using R We will learn about what R is and its advantages over other statistics packages the basics of R plotting data and graphs What

More information

Mails : ; Document version: 14/09/12

Mails : ; Document version: 14/09/12 Mails : leslie.regad@univ-paris-diderot.fr ; gaelle.lelandais@univ-paris-diderot.fr Document version: 14/09/12 A freely available language and environment Statistical computing Graphics Supplementary

More information

Introduction to scientific programming in R

Introduction to scientific programming in R Introduction to scientific programming in R John M. Drake & Pejman Rohani 1 Introduction This course will use the R language programming environment for computer modeling. The purpose of this exercise

More information

Introduction to R. Introduction to Econometrics W

Introduction to R. Introduction to Econometrics W Introduction to R Introduction to Econometrics W3412 Begin Download R from the Comprehensive R Archive Network (CRAN) by choosing a location close to you. Students are also recommended to download RStudio,

More information

Introduction to R Benedikt Brors Dept. Intelligent Bioinformatics Systems German Cancer Research Center

Introduction to R Benedikt Brors Dept. Intelligent Bioinformatics Systems German Cancer Research Center Introduction to R Benedikt Brors Dept. Intelligent Bioinformatics Systems German Cancer Research Center What is R? R is a statistical computing environment with graphics capabilites It is fully scriptable

More information

MBV4410/9410 Fall Bioinformatics for Molecular Biology. Introduction to R

MBV4410/9410 Fall Bioinformatics for Molecular Biology. Introduction to R MBV4410/9410 Fall 2018 Bioinformatics for Molecular Biology Introduction to R Outline Introduce R Basic operations RStudio Bioconductor? Goal of the lecture Introduce you to R Show how to run R, basic

More information

Topics for today Input / Output Using data frames Mathematics with vectors and matrices Summary statistics Basic graphics

Topics for today Input / Output Using data frames Mathematics with vectors and matrices Summary statistics Basic graphics Topics for today Input / Output Using data frames Mathematics with vectors and matrices Summary statistics Basic graphics Introduction to S-Plus 1 Input: Data files For rectangular data files (n rows,

More information

Introduction to R, Github and Gitlab

Introduction to R, Github and Gitlab Introduction to R, Github and Gitlab 27/11/2018 Pierpaolo Maisano Delser mail: maisanop@tcd.ie ; pm604@cam.ac.uk Outline: Why R? What can R do? Basic commands and operations Data analysis in R Github and

More information

Advanced Econometric Methods EMET3011/8014

Advanced Econometric Methods EMET3011/8014 Advanced Econometric Methods EMET3011/8014 Lecture 2 John Stachurski Semester 1, 2011 Announcements Missed first lecture? See www.johnstachurski.net/emet Weekly download of course notes First computer

More information

Statistical Programming Worksheet 4

Statistical Programming Worksheet 4 Statistical Programming Worksheet 4 1. Cholesky Decomposition. (a) Write a function with argument n to generate a random symmetric n n-positive definite matrix. To do this: generate an n n matrix C whose

More information

The value of f(t) at t = 0 is the first element of the vector and is obtained by

The value of f(t) at t = 0 is the first element of the vector and is obtained by MATLAB Tutorial This tutorial will give an overview of MATLAB commands and functions that you will need in ECE 366. 1. Getting Started: Your first job is to make a directory to save your work in. Unix

More information

Basics of R. > x=2 (or x<-2) > y=x+3 (or y<-x+3)

Basics of R. > x=2 (or x<-2) > y=x+3 (or y<-x+3) Basics of R 1. Arithmetic Operators > 2+2 > sqrt(2) # (2) >2^2 > sin(pi) # sin(π) >(1-2)*3 > exp(1) # e 1 >1-2*3 > log(10) # This is a short form of the full command, log(10, base=e). (Note) For log 10

More information

Functions and data structures. Programming in R for Data Science Anders Stockmarr, Kasper Kristensen, Anders Nielsen

Functions and data structures. Programming in R for Data Science Anders Stockmarr, Kasper Kristensen, Anders Nielsen Functions and data structures Programming in R for Data Science Anders Stockmarr, Kasper Kristensen, Anders Nielsen Objects of the game In R we have objects which are functions and objects which are data.

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Getting Started in R

Getting Started in R Getting Started in R Phil Beineke, Balasubramanian Narasimhan, Victoria Stodden modified for Rby Giles Hooker January 25, 2004 1 Overview R is a free alternative to Splus: a nice environment for data analysis

More information

Stat 290: Lab 2. Introduction to R/S-Plus

Stat 290: Lab 2. Introduction to R/S-Plus Stat 290: Lab 2 Introduction to R/S-Plus Lab Objectives 1. To introduce basic R/S commands 2. Exploratory Data Tools Assignment Work through the example on your own and fill in numerical answers and graphs.

More information

EPIB Four Lecture Overview of R

EPIB Four Lecture Overview of R EPIB-613 - Four Lecture Overview of R R is a package with enormous capacity for complex statistical analysis. We will see only a small proportion of what it can do. The R component of EPIB-613 is divided

More information

LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT

LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT NAVAL POSTGRADUATE SCHOOL LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT Statistics (OA3102) Lab #2: Sampling, Sampling Distributions, and the Central Limit Theorem Goal: Use R to demonstrate sampling

More information

Introduction to R. Nishant Gopalakrishnan, Martin Morgan January, Fred Hutchinson Cancer Research Center

Introduction to R. Nishant Gopalakrishnan, Martin Morgan January, Fred Hutchinson Cancer Research Center Introduction to R Nishant Gopalakrishnan, Martin Morgan Fred Hutchinson Cancer Research Center 19-21 January, 2011 Getting Started Atomic Data structures Creating vectors Subsetting vectors Factors Matrices

More information

Introduction to R. Daniel Berglund. 9 November 2017

Introduction to R. Daniel Berglund. 9 November 2017 Introduction to R Daniel Berglund 9 November 2017 1 / 15 R R is available at the KTH computers If you want to install it yourself it is available at https://cran.r-project.org/ Rstudio an IDE for R is

More information

R is a programming language of a higher-level Constantly increasing amount of packages (new research) Free of charge Website:

R is a programming language of a higher-level Constantly increasing amount of packages (new research) Free of charge Website: Introduction to R R R is a programming language of a higher-level Constantly increasing amount of packages (new research) Free of charge Website: http://www.r-project.org/ Code Editor: http://rstudio.org/

More information

Getting Started in R

Getting Started in R Getting Started in R Giles Hooker May 28, 2007 1 Overview R is a free alternative to Splus: a nice environment for data analysis and graphical exploration. It uses the objectoriented paradigm to implement

More information

MATH 5520 Basics of MATLAB

MATH 5520 Basics of MATLAB MATH 5520 Basics of MATLAB Dmitriy Leykekhman Spring 2011 Topics Sources. Entering Matrices. Basic Operations with Matrices. Build in Matrices. Build in Scalar and Matrix Functions. if, while, for m-files

More information

MATH 3511 Basics of MATLAB

MATH 3511 Basics of MATLAB MATH 3511 Basics of MATLAB Dmitriy Leykekhman Spring 2012 Topics Sources. Entering Matrices. Basic Operations with Matrices. Build in Matrices. Build in Scalar and Matrix Functions. if, while, for m-files

More information

An Introduction to R- Programming

An Introduction to R- Programming An Introduction to R- Programming Hadeel Alkofide, Msc, PhD NOT a biostatistician or R expert just simply an R user Some slides were adapted from lectures by Angie Mae Rodday MSc, PhD at Tufts University

More information

An introduction to R WS 2013/2014

An introduction to R WS 2013/2014 An introduction to R WS 2013/2014 Dr. Noémie Becker (AG Metzler) Dr. Sonja Grath (AG Parsch) Special thanks to: Dr. Martin Hutzenthaler (previously AG Metzler, now University of Frankfurt) course development,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively

More information

Exercise 2.23 Villanova MAT 8406 September 7, 2015

Exercise 2.23 Villanova MAT 8406 September 7, 2015 Exercise 2.23 Villanova MAT 8406 September 7, 2015 Step 1: Understand the Question Consider the simple linear regression model y = 50 + 10x + ε where ε is NID(0, 16). Suppose that n = 20 pairs of observations

More information

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information

Basic R Part 1. Boyce Thompson Institute for Plant Research Tower Road Ithaca, New York U.S.A. by Aureliano Bombarely Gomez

Basic R Part 1. Boyce Thompson Institute for Plant Research Tower Road Ithaca, New York U.S.A. by Aureliano Bombarely Gomez Basic R Part 1 Boyce Thompson Institute for Plant Research Tower Road Ithaca, New York 14853-1801 U.S.A. by Aureliano Bombarely Gomez A Brief Introduction to R: 1. What is R? 2. Software and documentation.

More information

Introduction to R (BaRC Hot Topics)

Introduction to R (BaRC Hot Topics) Introduction to R (BaRC Hot Topics) George Bell September 30, 2011 This document accompanies the slides from BaRC s Introduction to R and shows the use of some simple commands. See the accompanying slides

More information

R basics workshop Sohee Kang

R basics workshop Sohee Kang R basics workshop Sohee Kang Math and Stats Learning Centre Department of Computer and Mathematical Sciences Objective To teach the basic knowledge necessary to use R independently, thus helping participants

More information

R: BASICS. Andrea Passarella. (plus some additions by Salvatore Ruggieri)

R: BASICS. Andrea Passarella. (plus some additions by Salvatore Ruggieri) R: BASICS Andrea Passarella (plus some additions by Salvatore Ruggieri) BASIC CONCEPTS R is an interpreted scripting language Types of interactions Console based Input commands into the console Examine

More information

R Primer for Introduction to Mathematical Statistics 8th Edition Joseph W. McKean

R Primer for Introduction to Mathematical Statistics 8th Edition Joseph W. McKean R Primer for Introduction to Mathematical Statistics 8th Edition Joseph W. McKean Copyright 2017 by Joseph W. McKean at Western Michigan University. All rights reserved. Reproduction or translation of

More information

Extremely short introduction to R Jean-Yves Sgro Feb 20, 2018

Extremely short introduction to R Jean-Yves Sgro Feb 20, 2018 Extremely short introduction to R Jean-Yves Sgro Feb 20, 2018 Contents 1 Suggested ahead activities 1 2 Introduction to R 2 2.1 Learning Objectives......................................... 2 3 Starting

More information

Introduction to MATLAB. Arturo Donate

Introduction to MATLAB. Arturo Donate Introduction to MATLAB Arturo Donate Introduction What is MATLAB? Environment MATLAB Basics Toolboxes Comparison Conclusion Programming What is MATLAB? Matrix laboratory programming environment high-performance

More information

1 Matrices and Vectors and Lists

1 Matrices and Vectors and Lists University of Wollongong School of Mathematics and Applied Statistics STAT231 Probability and Random Variables 2014 Second Lab - Week 4 If you can t finish the log-book questions in lab, proceed at home.

More information

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5. PIV Programming Last Class: 1. Introduction of μpiv 2. Considerations of Microscopy in μpiv 3. Depth of Correlation 4. Physics of Particles in Micro PIV 5. Measurement Errors 6. Special Processing Methods

More information

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming

More information

Dynamics and Vibrations Mupad tutorial

Dynamics and Vibrations Mupad tutorial Dynamics and Vibrations Mupad tutorial School of Engineering Brown University ENGN40 will be using Matlab Live Scripts instead of Mupad. You can find information about Live Scripts in the ENGN40 MATLAB

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression

EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression OBJECTIVES 1. Prepare a scatter plot of the dependent variable on the independent variable 2. Do a simple linear regression

More information

Introduction to R. Course in Practical Analysis of Microarray Data Computational Exercises

Introduction to R. Course in Practical Analysis of Microarray Data Computational Exercises Introduction to R Course in Practical Analysis of Microarray Data Computational Exercises 2010 March 22-26, Technischen Universität München Amin Moghaddasi, Kurt Fellenberg 1. Installing R. Check whether

More information

Lecture 1: Getting Started and Data Basics

Lecture 1: Getting Started and Data Basics Lecture 1: Getting Started and Data Basics The first lecture is intended to provide you the basics for running R. Outline: 1. An Introductory R Session 2. R as a Calculator 3. Import, export and manipulate

More information

A Brief Introduction to R

A Brief Introduction to R A Brief Introduction to R Babak Shahbaba Department of Statistics, University of California, Irvine, USA Chapter 1 Introduction to R 1.1 Installing R To install R, follow these steps: 1. Go to http://www.r-project.org/.

More information

GS Analysis of Microarray Data

GS Analysis of Microarray Data GS01 0163 Analysis of Microarray Data Keith Baggerly and Kevin Coombes Section of Bioinformatics Department of Biostatistics and Applied Mathematics UT M. D. Anderson Cancer Center kabagg@mdanderson.org

More information

Goals of this course. Crash Course in R. Getting Started with R. What is R? What is R? Getting you setup to use R under Windows

Goals of this course. Crash Course in R. Getting Started with R. What is R? What is R? Getting you setup to use R under Windows Oxford Spring School, April 2013 Effective Presentation ti Monday morning lecture: Crash Course in R Robert Andersen Department of Sociology University of Toronto And Dave Armstrong Department of Political

More information

An introduction to WS 2015/2016

An introduction to WS 2015/2016 An introduction to WS 2015/2016 Dr. Noémie Becker (AG Metzler) Dr. Sonja Grath (AG Parsch) Special thanks to: Prof. Dr. Martin Hutzenthaler (previously AG Metzler, now University of Duisburg-Essen) course

More information

Lecture 3: Basics of R Programming

Lecture 3: Basics of R Programming Lecture 3: Basics of R Programming This lecture introduces how to do things with R beyond simple commands. We will explore programming in R. What is programming? It is the act of instructing a computer

More information

1 Pencil and Paper stuff

1 Pencil and Paper stuff Spring 2008 - Stat C141/ Bioeng C141 - Statistics for Bioinformatics Course Website: http://www.stat.berkeley.edu/users/hhuang/141c-2008.html Section Website: http://www.stat.berkeley.edu/users/mgoldman

More information

Stokes Modelling Workshop

Stokes Modelling Workshop Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16 Matlab As part of this crash

More information

Intro to R. Some history. Some history

Intro to R. Some history. Some history Intro to R Héctor Corrada Bravo CMSC858B Spring 2012 University of Maryland Computer Science http://www.nytimes.com/2009/01/07/technology/business-computing/07program.html?_r=2&pagewanted=1 http://www.forbes.com/forbes/2010/0524/opinions-software-norman-nie-spss-ideas-opinions.html

More information

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

Tutorial (Unix Version)

Tutorial (Unix Version) Tutorial (Unix Version) S.f.Statistik, ETHZ February 26, 2010 Introduction This tutorial will give you some basic knowledge about working with R. It will also help you to familiarize with an environment

More information

Sub-setting Data. Tzu L. Phang

Sub-setting Data. Tzu L. Phang Sub-setting Data Tzu L. Phang 2016-10-13 Subsetting in R Let s start with a (dummy) vectors. x

More information

MATLAB Introductory Course Computer Exercise Session

MATLAB Introductory Course Computer Exercise Session MATLAB Introductory Course Computer Exercise Session This course is a basic introduction for students that did not use MATLAB before. The solutions will not be collected. Work through the course within

More information

Lab 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

POL 345: Quantitative Analysis and Politics

POL 345: Quantitative Analysis and Politics POL 345: Quantitative Analysis and Politics Precept Handout 1 Week 2 (Verzani Chapter 1: Sections 1.2.4 1.4.31) Remember to complete the entire handout and submit the precept questions to the Blackboard

More information

A. Matrix-wise and element-wise operations

A. Matrix-wise and element-wise operations USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data

More information

Upper left area. It is R Script. Here you will write the code. 1. The goal of this problem set is to learn how to use HP filter in R.

Upper left area. It is R Script. Here you will write the code. 1. The goal of this problem set is to learn how to use HP filter in R. Instructions Setting up R Follow these steps if you are new with R: 1. Install R using the following link http://cran.us.r-project.org/ Make sure to select the version compatible with your operative system.

More information

Yet Another R FAQ, or How I Learned to Stop Worrying and Love Computing 1. Roger Koenker CEMMAP and University of Illinois, Urbana-Champaign

Yet Another R FAQ, or How I Learned to Stop Worrying and Love Computing 1. Roger Koenker CEMMAP and University of Illinois, Urbana-Champaign Yet Another R FAQ, or How I Learned to Stop Worrying and Love Computing 1 Roger Koenker CEMMAP and University of Illinois, Urbana-Champaign It was a splendid mind. For if thought is like the keyboard of

More information

Making plots in R [things I wish someone told me when I started grad school]

Making plots in R [things I wish someone told me when I started grad school] Making plots in R [things I wish someone told me when I started grad school] Kirk Lohmueller Department of Ecology and Evolutionary Biology UCLA September 22, 2017 In honor of Talk Like a Pirate Day...

More information

Overview. Linear Algebra Notation. MATLAB Data Types Data Visualization. Probability Review Exercises. Asymptotics (Big-O) Review

Overview. Linear Algebra Notation. MATLAB Data Types Data Visualization. Probability Review Exercises. Asymptotics (Big-O) Review Tutorial 1 1 / 21 Overview Linear Algebra Notation Data Types Data Visualization Probability Review Exercises Asymptotics (Big-O) Review 2 / 21 Linear Algebra Notation Notation and Convention 3 / 21 Linear

More information

Regression III: Advanced Methods

Regression III: Advanced Methods Lecture 2: Software Introduction Regression III: Advanced Methods William G. Jacoby Department of Political Science Michigan State University jacoby@msu.edu Getting Started with R What is R? A tiny R session

More information

Laboratory 1 Introduction to MATLAB for Signals and Systems

Laboratory 1 Introduction to MATLAB for Signals and Systems Laboratory 1 Introduction to MATLAB for Signals and Systems INTRODUCTION to MATLAB MATLAB is a powerful computing environment for numeric computation and visualization. MATLAB is designed for ease of use

More information

Install RStudio from - use the standard installation.

Install RStudio from   - use the standard installation. Session 1: Reading in Data Before you begin: Install RStudio from http://www.rstudio.com/ide/download/ - use the standard installation. Go to the course website; http://faculty.washington.edu/kenrice/rintro/

More information

A Short Introduction to R

A Short Introduction to R A Short Introduction to R 1.1 The R initiative There are many commercial statistical softwares available. Well-known examples include SAS, SPSS, S-Plus, Minitab, Statgraphics, GLIM, and Genstat. Usually

More information

Appendix A: A Sample R Session

Appendix A: A Sample R Session Appendix A: The purpose of this appendix is to become accustomed to the R and the way if responds to line commands. R can be downloaded from http://cran.r-project.org/ Be sure to download the version of

More information

R Command Summary. Steve Ambler Département des sciences économiques École des sciences de la gestion. April 2018

R Command Summary. Steve Ambler Département des sciences économiques École des sciences de la gestion. April 2018 R Command Summary Steve Ambler Département des sciences économiques École des sciences de la gestion Université du Québec à Montréal c 2018 : Steve Ambler April 2018 This document describes some of the

More information

STAT 540: R: Sections Arithmetic in R. Will perform these on vectors, matrices, arrays as well as on ordinary numbers

STAT 540: R: Sections Arithmetic in R. Will perform these on vectors, matrices, arrays as well as on ordinary numbers Arithmetic in R R can be viewed as a very fancy calculator Can perform the ordinary mathematical operations: + - * / ˆ Will perform these on vectors, matrices, arrays as well as on ordinary numbers With

More information

Basic R Part 1 BTI Plant Bioinformatics Course

Basic R Part 1 BTI Plant Bioinformatics Course Basic R Part 1 BTI Plant Bioinformatics Course Spring 2013 Sol Genomics Network Boyce Thompson Institute for Plant Research by Jeremy D. Edwards What is R? Statistical programming language Derived from

More information

R Programming Basics - Useful Builtin Functions for Statistics

R Programming Basics - Useful Builtin Functions for Statistics R Programming Basics - Useful Builtin Functions for Statistics Vectorized Arithmetic - most arthimetic operations in R work on vectors. Here are a few commonly used summary statistics. testvect = c(1,3,5,2,9,10,7,8,6)

More information

STAT 213: R/RStudio Intro

STAT 213: R/RStudio Intro STAT 213: R/RStudio Intro Colin Reimer Dawson Last Revised February 10, 2016 1 Starting R/RStudio Skip to the section below that is relevant to your choice of implementation. Installing R and RStudio Locally

More information

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The

More information

Lecture 3: Basics of R Programming

Lecture 3: Basics of R Programming Lecture 3: Basics of R Programming This lecture introduces you to how to do more things with R beyond simple commands. Outline: 1. R as a programming language 2. Grouping, loops and conditional execution

More information

Practice for Learning R and Learning Latex

Practice for Learning R and Learning Latex Practice for Learning R and Learning Latex Jennifer Pan August, 2011 Latex Environments A) Try to create the following equations: 1. 5+6 α = β2 2. P r( 1.96 Z 1.96) = 0.95 ( ) ( ) sy 1 r 2 3. ˆβx = r xy

More information

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo MATLAB is very powerful and varied software package for scientific computing. It is based upon matrices and m files. It is invoked by typing % matlab

More information

An Introduction to R 1.1 Getting started

An Introduction to R 1.1 Getting started An Introduction to R 1.1 Getting started Dan Navarro (daniel.navarro@adelaide.edu.au) School of Psychology, University of Adelaide ua.edu.au/ccs/people/dan DSTO R Workshop, 29-Apr-2015 There s a book http://ua.edu.au/ccs/teaching/lsr/

More information

Basic types and definitions. Chapter 3 of Thompson

Basic types and definitions. Chapter 3 of Thompson Basic types and definitions Chapter 3 of Thompson Booleans [named after logician George Boole] Boolean values True and False are the result of tests are two numbers equal is one smaller than the other

More information

Introduction to R. base -> R win32.exe (this will change depending on the latest version)

Introduction to R. base -> R win32.exe (this will change depending on the latest version) Dr Raffaella Calabrese, Essex Business School 1. GETTING STARTED Introduction to R R is a powerful environment for statistical computing which runs on several platforms. R is available free of charge.

More information

LECTURE NOTES FOR ECO231 COMPUTER APPLICATIONS I. Part Two. Introduction to R Programming. RStudio. November Written by. N.

LECTURE NOTES FOR ECO231 COMPUTER APPLICATIONS I. Part Two. Introduction to R Programming. RStudio. November Written by. N. LECTURE NOTES FOR ECO231 COMPUTER APPLICATIONS I Part Two Introduction to R Programming RStudio November 2016 Written by N.Nilgün Çokça Introduction to R Programming 5 Installing R & RStudio 5 The R Studio

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Chen Huang Computer Science and Engineering SUNY at Buffalo What is MATLAB? MATLAB (stands for matrix laboratory ) It is a language and an environment for technical computing Designed

More information

STAT 113: R/RStudio Intro

STAT 113: R/RStudio Intro STAT 113: R/RStudio Intro Colin Reimer Dawson Last Revised September 1, 2017 1 Starting R/RStudio There are two ways you can run the software we will be using for labs, R and RStudio. Option 1 is to log

More information

The goal of this handout is to allow you to install R on a Windows-based PC and to deal with some of the issues that can (will) come up.

The goal of this handout is to allow you to install R on a Windows-based PC and to deal with some of the issues that can (will) come up. Fall 2010 Handout on Using R Page: 1 The goal of this handout is to allow you to install R on a Windows-based PC and to deal with some of the issues that can (will) come up. 1. Installing R First off,

More information

Package gmt. September 12, 2017

Package gmt. September 12, 2017 Version 2.0-1 Date 2017-09-12 Package gmt September 12, 2017 Title Interface Between GMT Map-Making Software and R Imports utils SystemRequirements gmt LazyData yes Interface between the GMT map-making

More information

R in Linguistic Analysis. Week 2 Wassink Autumn 2012

R in Linguistic Analysis. Week 2 Wassink Autumn 2012 R in Linguistic Analysis Week 2 Wassink Autumn 2012 Today R fundamentals The anatomy of an R help file but first... How did you go about learning the R functions in the reading? More help learning functions

More information

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

University of Alberta

University of Alberta A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

More information

MATLAB Lecture 1. Introduction to MATLAB

MATLAB Lecture 1. Introduction to MATLAB MATLAB Lecture 1. Introduction to MATLAB 1.1 The MATLAB environment MATLAB is a software program that allows you to compute interactively with matrices. If you want to know for instance the product of

More information

TMA4255 Applied Statistics R-intro, integrated with Exercise 2

TMA4255 Applied Statistics R-intro, integrated with Exercise 2 TMA4255 Applied Statistics R-intro, integrated with Exercise 2 1. Start R or Rstudio on your laptop, or remote desktop to cauchy.math.ntnu.no and log in with win-ntnu-no\yourusername and password. If you

More information

A VERY BRIEF INTRODUCTION TO R

A VERY BRIEF INTRODUCTION TO R CS 432/532 INTRODUCTION TO WEB SCIENCE A VERY BRIEF INTRODUCTION TO R SCOTT G. AINSWORTH OLD DOMINION UNIVERSITY WHO AM I? Scott G. Ainsworth Former sailor Worked for several consulting firms Computer

More information