Workshop in Methods and Indiana Statistical Consulting Center Introduction to R

Size: px
Start display at page:

Download "Workshop in Methods and Indiana Statistical Consulting Center Introduction to R"

Transcription

1 Workshop in Methods and Indiana Statistical Consulting Center Introduction to R R Basics Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R R Basics 1 / 12

2 A Short History of R The R Project for Statistical Computing R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R. WIM and ISCC Intro to R R Basics 2 / 12

3 The Comprehensive R Archive Network (CRAN) The CRAN website is where you can: Download the latest version of R Find additional packages Search documentation manuals Get access to the user listservs Search for help WIM and ISCC Intro to R R Basics 3 / 12

4 The R Graphical User Interface (GUI) Command Window Script Window Plot Window WIM and ISCC Intro to R R Basics 4 / 12

5 Working Directory What is my current working directory? getwd() Mac Menu: Misc Get Working Directory Windows Menu: File Change dir... WIM and ISCC Intro to R R Basics 5 / 12

6 Working Directory What is my current working directory? getwd() Mac Menu: Misc Get Working Directory Windows Menu: File Change dir... Changing the working directory setwd() Mac Menu: Misc Change Working Directory... Windows Menu: File Change dir... WIM and ISCC Intro to R R Basics 5 / 12

7 A Note on Path Names In R, you can specify a path name with either forward slash or backslash. However, if you use backslashes, you must use two of them. These will both set the working directory: e.g. setwd( C:/Program Files/R/R ) or setwd( C:\\ Program Files\\ R\\ R ) WIM and ISCC Intro to R R Basics 6 / 12

8 Clearing the Console Clear the Console (Command Window): Mac Menu: Edit Clear Console Windows Menu: Edit Clear console WIM and ISCC Intro to R R Basics 7 / 12

9 Clearing the Console Clear the Console (Command Window): Mac Menu: Edit Clear Console Windows Menu: Edit Clear console Removing variables from memory: rm() or remove() e.g. create a variable X < 4 Remove variable X: rm(x) To remove all variables in the current memory: rm(list=ls()) WIM and ISCC Intro to R R Basics 7 / 12

10 Getting Help Several help commands: If you know the function name: help()? If you are not sure: help.search() WIM and ISCC Intro to R R Basics 8 / 12

11 Documentation Let s open a sample documentation file:?sum Elements of a documentation file: Function name and the package containing it e.g. sum{base} indicates the sum() function in the base package Description Usage Arguments Details Value: describes what the function will return, may contain a list of object components (for example,?lm) Additional Notes and References See Also indicates related functions Example(s) WIM and ISCC Intro to R R Basics 9 / 12

12 Online Resources and Help R listservs Quick-R tutorial: R Tutor: UCLA Statistical Computing: Google! WIM and ISCC Intro to R R Basics 10 / 12

13 Packages Packages are available for many different types of analyses over 2000 listed on the CRAN website! The basic R program contains some basic packages, including base, graphics, stats, utils Installing a package: On Mac: Packages & Data Package Installer Find the package you want with Package Search and hit Install Selected Try to find and install the package MASS. After installing a package, you MUST call it into active memory with the library() command in order to use its functions. e.g. library(mass) WIM and ISCC Intro to R R Basics 11 / 12

14 Exercise 1 1 From the command window find your current working directory. Change the working directory to be the My Documents folder under your Username. 2 Save the commands for finding and changing the working directory in a script file. 3 Using the various help commands, try to find the documentation for the following functions: plot a function for creating tables from a set of data a function for finding the eigenvalues of a matrix 4 Locate and install the package psych for use later in the workshop. WIM and ISCC Intro to R R Basics 12 / 12

15 Workshop in Methods and Indiana Statistical Consulting Center Introduction to R Working with Data Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R Working with Data 1 / 15

16 Manually Creating or Entering Data in R Combine items into vector or list: c() e.g. A < c(1,2,3,4,5,6) e.g. c(1,2,3,4,5,6) > A e.g. A = c(1,2,3,4,5,6) WIM and ISCC Intro to R Working with Data 2 / 15

17 Manually Creating or Entering Data in R Combine items into vector or list: c() e.g. A < c(1,2,3,4,5,6) e.g. c(1,2,3,4,5,6) > A e.g. A = c(1,2,3,4,5,6) Repeat a number or a sequence of numbers: rep() e.g. rep(1,5) e.g. rep(c(2,5,7), 3) WIM and ISCC Intro to R Working with Data 2 / 15

18 Manually Creating or Entering Data in R Combine items into vector or list: c() e.g. A < c(1,2,3,4,5,6) e.g. c(1,2,3,4,5,6) > A e.g. A = c(1,2,3,4,5,6) Repeat a number or a sequence of numbers: rep() e.g. rep(1,5) e.g. rep(c(2,5,7), 3) Sequence generation: seq() e.g. seq(1, 10) e.g. seq(1, 10,.5) WIM and ISCC Intro to R Working with Data 2 / 15

19 Manually Creating or Entering Data in R Combine R objects by columns: cbind() A <- rep(1, 4) B <- rep(2, 4) AB <- cbind(a, B) Combine R objects by rows: rbind() A <- rep(1, 4) B <- rep(2, 4) AB <- rbind(a, B) WIM and ISCC Intro to R Working with Data 3 / 15

20 Manually Creating or Entering Data in R Create a matrix: matrix() Let s look at the Usage of matrix(): matrix(data=na, nrow=1, ncol=1, byrow=false, dimnames=null) Create a column vector: matrix(c(2,3,2,6,2,8), ncol=1) WIM and ISCC Intro to R Working with Data 4 / 15

21 Manually Creating or Entering Data in R Create a matrix: matrix() Let s look at the Usage of matrix(): matrix(data=na, nrow=1, ncol=1, byrow=false, dimnames=null) Create a column vector: matrix(c(2,3,2,6,2,8), ncol=1) Create a 2x3 matrix: matrix(c(2,3,2,6,2,8), nrow=2, ncol=3) WIM and ISCC Intro to R Working with Data 4 / 15

22 Manually Creating or Entering Data in R Create a matrix: matrix() Let s look at the Usage of matrix(): matrix(data=na, nrow=1, ncol=1, byrow=false, dimnames=null) Create a column vector: matrix(c(2,3,2,6,2,8), ncol=1) Create a 2x3 matrix: matrix(c(2,3,2,6,2,8), nrow=2, ncol=3) Create a 2x3 matrix filling in across the row first: matrix(c(2,3,2,6,2,8), nrow=2, ncol=3, byrow=true) WIM and ISCC Intro to R Working with Data 4 / 15

23 Manually Creating or Entering Data in R Create a matrix: matrix() Let s look at the Usage of matrix(): matrix(data=na, nrow=1, ncol=1, byrow=false, dimnames=null) Create a column vector: matrix(c(2,3,2,6,2,8), ncol=1) Create a 2x3 matrix: matrix(c(2,3,2,6,2,8), nrow=2, ncol=3) Create a 2x3 matrix filling in across the row first: matrix(c(2,3,2,6,2,8), nrow=2, ncol=3, byrow=true) Create a 2x3 matrix with row and column names: matrix(c(2,3,2,6,2,8), nrow=2, ncol=3, dimnames = list(c( row1, row2 ),c( Col1, Col2, Col3 ))) WIM and ISCC Intro to R Working with Data 4 / 15

24 Types of Data Structures Matrix is.matrix() as.matrix() Data Frame is.data.frame() as.data.frame() List is.list() as.list() WIM and ISCC Intro to R Working with Data 5 / 15

25 Reading a Data File into R Most general function: read.table() e.g. read.table( /Users/Leslie/Documents/R Workshop/SwissNotes.csv, sep=,, header=true) filename is in quotes, double or single must include file extension filename is case sensitive sep defines the separator, like,, \t or be sure to correctly identify header=true or header=false read.table() creates a data frame WIM and ISCC Intro to R Working with Data 6 / 15

26 Reading a Data File into R Most general function: read.table() e.g. read.table( /Users/Leslie/Documents/R Workshop/SwissNotes.csv, sep=,, header=true) filename is in quotes, double or single must include file extension filename is case sensitive sep defines the separator, like,, \t or be sure to correctly identify header=true or header=false read.table() creates a data frame For csv files: read.csv() e.g. read.csv( /Users/Leslie/Documents/R Workshop/SwissNotes.csv, header=true) For tab delimited files: read.delim() WIM and ISCC Intro to R Working with Data 6 / 15

27 Reading a Data File into R The function file.choose() can be used to let you search for a file: > Y<-read.table(file=file.choose()) file.choose() pops up an open file dialogue box WIM and ISCC Intro to R Working with Data 7 / 15

28 Variable Names To identify the list of variable names in your data set: >data <- read.table( /Users/Leslie/Documents/R Workshop/ SwissNotes.csv, sep=",",header=true) >names(data) [1] "Length" "LeftHeight" "RightHeight" "LowerInner.Frame" [5] "UpperInner.Frame" "Diagonal" "Type" If your data file does not contain variable names, you can create them with the command names(). > names(data) <- c("length", "LeftHeight", "RightHeight", "LowerInner.Frame", "UpperInner.Frame", "Diagonal", "Type") WIM and ISCC Intro to R Working with Data 8 / 15

29 A Side Note - Data Description Data compiled by Bernard Flury Dataset contains measurements on 200 Swiss bank notes, 100 genuine and 100 counterfeit notes. WIM and ISCC Intro to R Working with Data 9 / 15

30 The attach() and detach() Commands The attach() function allows you to take the set of variables in a data set and attach each one to its own object in the R search path. In the SwissNote data, if I want to refer to the variable Type, I can use > data$type or >data[,type] If I use attach(), I can refer to Type on its own, like its own variable: > attach(data) > Type [1] Genuine Genuine Genuine... WIM and ISCC Intro to R Working with Data 10 / 15

31 The attach() and detach() Commands The detach() command reverses attach(), and detaches objects from the search path. Variables are now only part of their original data set. They are no longer separate objects. > detach(data) > Type Error: object "Type" not found WIM and ISCC Intro to R Working with Data 11 / 15

32 Subsets of Data In general, you can refer to any entry in an object by [row, column] e.g. > data[1,5] [1] 9.7 WIM and ISCC Intro to R Working with Data 12 / 15

33 Subsets of Data In general, you can refer to any entry in an object by [row, column] e.g. > data[1,5] [1] 9.7 To select an entire row, leave the column blank e.g. > data[1, ] WIM and ISCC Intro to R Working with Data 12 / 15

34 Subsets of Data In general, you can refer to any entry in an object by [row, column] e.g. > data[1,5] [1] 9.7 To select an entire row, leave the column blank e.g. > data[1, ] To select a set of rows: Rows 1-10: data[1:10,] Rows 3, 6, and 7: data[c(3,6,7),] All rows except the first row data[-1,] WIM and ISCC Intro to R Working with Data 12 / 15

35 Subsets of Data In general, you can refer to any entry in an object by [row, column] e.g. > data[1,5] [1] 9.7 To select an entire row, leave the column blank e.g. > data[1, ] To select a set of rows: Rows 1-10: data[1:10,] Rows 3, 6, and 7: data[c(3,6,7),] All rows except the first row data[-1,] Similar commands can be used for columns or sets of columns. WIM and ISCC Intro to R Working with Data 12 / 15

36 Subsets of Data Data can also be selected by names of variables. For example, if I just want the LeftHeight data for all the bank notes: > data[,"leftheight"] [1] Note that this is similar to > data$leftheight WIM and ISCC Intro to R Working with Data 13 / 15

37 Subsets of Data We can also specify a condition to select data. For example, if I just want the data for only Genuine bank notes > data[data$type=="genuine",] Equivalently, > attach(data) > data[type=="genuine",] Length LeftHeight RightHeight LowerInner.Frame WIM and ISCC Intro to R Working with Data 14 / 15

38 Exercise 2 1 Enter the following data into R: CHI FRA GER JPN SWE USA Is the data set you created in (1) a data.frame or matrix? What happens if you switch the format? 3 On OnCourse in the Data Sets folder, download the data file cardiac2.txt. This is a tab delimited data set. Read this data into R. 4 cardiac2.txt includes several measurements taken to predict cardiac events, including heart attacks. Select the data for the male participants only. 5 For the male participants, select only the data for basal hear rate (bhr) and peak heart rate (pkhr). WIM and ISCC Intro to R Working with Data 15 / 15

39 Workshop in Methods and Indiana Statistical Consulting Center Introduction to R Data Visualization Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R DataVisualization 1 / 16

40 The plot() Function plot() is the primary plotting function. Calling plot will open a new plotting window Let s look at the documentation of plot():?plot WIM and ISCC Intro to R DataVisualization 2 / 16

41 The plot() Function Let s try a basic plot of two variables, LeftHeight and RightHeight > plot(leftheight,rightheight) RightHeight LeftHeight WIM and ISCC Intro to R DataVisualization 3 / 16

42 The plot() Function Let s change the symbols to squares specifying the parameter pch = For details on color options, see the Color Specification section in?par. > plot(leftheight,rightheight, pch=22) RightHeight LeftHeight WIM and ISCC Intro to R DataVisualization 4 / 16

43 The plot() Function Let s change the color of the symbols with the parameter col = To see a list of possible color names: > colors() Let s do our scatterplot with red circles. > plot(leftheight,rightheight, col="red") RightHeight LeftHeight WIM and ISCC Intro to R DataVisualization 5 / 16

44 The plot() Function Say we decide we don t want a scatterplot. With the type parameter, we have the following options: "p" for points, "l" for lines, "b" for both, "c" for the lines part alone of "b", "o" for both overplotted, "h" for histogram like (or high-density) vertical lines, "s" for stair steps, "S" for other steps, see Details below, "n" for no plotting. WIM and ISCC Intro to R DataVisualization 6 / 16

45 The plot() Function For example, if we decide we want points and lines, we can try > plot(leftheight,rightheight, type="o") RightHeight LeftHeight WIM and ISCC Intro to R DataVisualization 7 / 16

46 Scatterplots for Multiple Groups We know in our data we have two types of bank notes, Genuine and Counterfeit. How can we distinguish them in the plot? We can use plot together with points to separately plot the two groups in the same plot. > plot(leftheight[type=="genuine"], RightHeight[Type=="Genuine"], col="red") > points(leftheight[type=="counterfeit"], RightHeight[Type=="Counterfeit"], col="blue") RightHeight[Type == "Genuine"] LeftHeight[Type == "Genuine"] WIM and ISCC Intro to R DataVisualization 8 / 16

47 Scatterplots for Multiple Groups Notice the labels on the x and y axis are simply whatever we identified the x and y data to be. We can change the axis labels and other plot titles. In your plot command call, you can do the following: Specify the x-axis label: xlab = X Label Specify the y-axis label: ylab = Y Label Specify the plot title: main = Main Title Specify a subtitle: sub = Subtitle WIM and ISCC Intro to R DataVisualization 9 / 16

48 Plot Titles and Labels > plot(leftheight[type=="genuine"], RightHeight[Type=="Genuine"], col="red", main="plot of Bank Note Heights", sub = "Measurements are in mm", xlab="height of Left Side", ylab="height of Right Side") > points(leftheight[type=="counterfeit"], RightHeight[Type=="Counterfeit"], col="blue") Plot of Bank Note Heights Height of Right Side Height of Left Side Measurements are in mm WIM and ISCC Intro to R DataVisualization 10 / 16

49 Adding a Legend > legend("topleft",c("genuine Notes","Counterfeit Notes"), pch=c(21,21),col=c("red","blue")) Plot of Bank Note Heights Height of Right Side Genuine Notes Counterfeit Notes Height of Left Side Measurements are in mm WIM and ISCC Intro to R DataVisualization 11 / 16

50 Adding Lines to a Scatterplot We can use the abline() function to add different types of straight lines to our plot. Horizontal line: abline(h= ) Vertical Line: abline(v= ) Line given by slope (b) and intercept (a): abline(a =, b = ) Line given by slope (b) and intercept (a): abline(coef = c(a, b)) WIM and ISCC Intro to R DataVisualization 12 / 16

51 Adding Lines to a Scatterplot > abline(coef=c( , )) Plot of Bank Note Heights Height of Right Side Genuine Notes Counterfeit Notes Height of Left Side Measurements are in mm WIM and ISCC Intro to R DataVisualization 13 / 16

52 Histograms Histograms are another popular plotting option. > hist(length) Histogram of Length Frequency Length WIM and ISCC Intro to R DataVisualization 14 / 16

53 Exploring Data with the pairs() Function Using the SwissNote data > pairs(data) Length LeftHeight RightHeight LowerInner.Frame UpperInner.Frame Diagonal Type WIM and ISCC Intro to R DataVisualization 15 / 16

54 Exercise 3 Using the cardiac data set, create the following plots: 1 Create a scatterplot of age versus peak heart rate (pkhr). Be sure to label your axes and title the plot. 2 Using information available on the points documentation page, adjust your scatterplot to have symbols that are filled blue diamonds with a green border. 3 In your age versus peak heart rate scatterplot, plot the males and females with different symbols and different colors. Add a legend to your plot. 4 Create histograms for the basal blood pressure (basebp) data and the systolic blood pressure (sbp) data. WIM and ISCC Intro to R DataVisualization 16 / 16

55 Workshop in Methods and Indiana Statistical Consulting Center Introduction to R Basic Data Analysis: Descriptive Statistics Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R Descriptive Statistics 1 / 11

56 Mean or Average mean() > mean(data[, Length ]) > mean(data) WIM and ISCC Intro to R Descriptive Statistics 2 / 11

57 Mean or Average mean() > mean(data[, Length ]) > mean(data) rowmeans() > rowmeans(data[,1:6]) WIM and ISCC Intro to R Descriptive Statistics 2 / 11

58 Mean or Average mean() > mean(data[, Length ]) > mean(data) rowmeans() > rowmeans(data[,1:6]) colmeans() > colmeans(data[,-7]) WIM and ISCC Intro to R Descriptive Statistics 2 / 11

59 Variability Variance: var() > var(data[, Length ]) > var(data) WIM and ISCC Intro to R Descriptive Statistics 3 / 11

60 Variability Variance: var() > var(data[, Length ]) > var(data) Covariance: cov() > cov(data) WIM and ISCC Intro to R Descriptive Statistics 3 / 11

61 Variability Variance: var() > var(data[, Length ]) > var(data) Covariance: cov() > cov(data) Correlation: cor() > cor(data[,1:6]) WIM and ISCC Intro to R Descriptive Statistics 3 / 11

62 Five-number Summary > summary(data[1:3]) Length LeftHeight RightHeight Min. :213.8 Min. :129.0 Min. : st Qu.: st Qu.: st Qu.:129.7 Median :214.9 Median :130.2 Median :130.0 Mean :214.9 Mean :130.1 Mean : rd Qu.: rd Qu.: rd Qu.:130.2 Max. :216.3 Max. :131.0 Max. :131.1 WIM and ISCC Intro to R Descriptive Statistics 4 / 11

63 Creating Tables The function table() allows for crosstabulation of factors or categorical variables. Using the cardiac data: > table(cardiac[,7:9]),, newmi = 0 chestpain gender ,, newmi = 1 chestpain gender WIM and ISCC Intro to R Descriptive Statistics 5 / 11

64 Descriptive Statistics: Using the psych package The psych package offers a summary function describe for gathering descriptive statistics for your data: > describe(data) var n mean sd median trimmed... Length LeftHeight RightHeight LowerInner.Frame UpperInner.Frame Diagonal Type* WIM and ISCC Intro to R Descriptive Statistics 6 / 11

65 Comparing Two Groups: The Univariate t-test The function t.test() can perform 1-sample and 2-sample (paired or independent) t-tests. 1-sample t-test > t.test(x, alternative= two.sided, mu = 0, conf.level=0.95) WIM and ISCC Intro to R Descriptive Statistics 7 / 11

66 Comparing Two Groups: The Univariate t-test The function t.test() can perform 1-sample and 2-sample (paired or independent) t-tests. 1-sample t-test > t.test(x, alternative= two.sided, mu = 0, conf.level=0.95) 2 independent samples t-test > t.test(x, y, alternative= two.sided, mu = 0, paired=false, var.equal=false, conf.level=0.95) WIM and ISCC Intro to R Descriptive Statistics 7 / 11

67 Comparing Two Groups: The Univariate t-test The function t.test() can perform 1-sample and 2-sample (paired or independent) t-tests. 1-sample t-test > t.test(x, alternative= two.sided, mu = 0, conf.level=0.95) 2 independent samples t-test > t.test(x, y, alternative= two.sided, mu = 0, paired=false, var.equal=false, conf.level=0.95) 2 paired samples t-test > t.test(x, y, alternative= two.sided, mu = 0, paired=true, var.equal=true, conf.level=0.95) WIM and ISCC Intro to R Descriptive Statistics 7 / 11

68 Example: 2 Independent Samples t-test Let x be the Diagonal measurements for the Genuine banks notes and y be the Diagonal measurements for the Counterfeit bank notes. H 0 : µ x = µ y v. H 1 : µ x > µ y > x<-data[type=="genuine","diagonal"] > y<-data[type=="counterfeit","diagonal"] > t.test(x,y,alternative="greater",mu=0, paired=false,var.equal=true) WIM and ISCC Intro to R Descriptive Statistics 8 / 11

69 Example: 2 Independent Samples t-test > t.test(x,y,alternative="greater",mu=0, paired=false,var.equal=true) Two Sample t-test data: x and y t = , df = 198, p-value < 2.2e-16 alternative hypothesis: true difference in means is greater than 0 95 percent confidence interval: Inf sample estimates: mean of x mean of y WIM and ISCC Intro to R Descriptive Statistics 9 / 11

70 Generating Random Numbers R contains functions for generating random numbers from many well-known distributions. A random number from a standard normal distribution: > rnorm(1, mean = 0, sd = 1) [1] A set of random numbers from a uniform distribution: > runif(3, min=0, max=1) [1] WIM and ISCC Intro to R Descriptive Statistics 10 / 11

71 Exercise 4 Using the cardiac data: 1 Find the descriptive statistics for all variables the cardiac data. Note that the first 6 variables are continuous and the last 6 are categorical. 2 Using the appropriate t-tests, test the following hypotheses H0 : µ age = 72 v. H 1 : µ age < 72 For peak heart rate (pkhr), H0 : µ male = µ female v. H 1 : µ male > µ female For peak heart rate, H 0 : µ no chest pain = µ chest pain v. H 1 : µ no chest pain µ chest pain WIM and ISCC Intro to R Descriptive Statistics 11 / 11

72 Workshop in Methods and Indiana Statistical Consulting Center Introduction to R Supplemental Material: Matrix Algebra Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R Matrix Algebra 1 / 1

73 Matrices > A <- rbind(c(2,1),c(1,3)) > A [,1] [,2] [1,] 2 1 [2,] 1 3 > B <- rbind(c(1,4,2),c(5,0,3)) > B [,1] [,2] [,3] [1,] [2,] > C <- rbind(c(1,4),c(3,2)) > C [,1] [,2] [1,] 1 4 [2,] 3 2 WIM and ISCC Intro to R Matrix Algebra 2 / 1

74 Add or Subtract Matrices > A+C [,1] [,2] [1,] 3 5 [2,] 4 5 > A-C [,1] [,2] [1,] 1-3 [2,] -2 1 WIM and ISCC Intro to R Matrix Algebra 3 / 1

75 Matrix Multiplication To multiply the corresponding elements in two matrices of the same dimensions: > A*C [,1] [,2] [1,] 2 4 [2,] 3 6 To do matrix multiplication of two matrices > A%*%C [,1] [,2] [1,] 5 10 [2,] > C%*%B [,1] [,2] [,3] [1,] [2,] WIM and ISCC Intro to R Matrix Algebra 4 / 1

76 Matrix Transpose > t(a) [,1] [,2] [1,] 2 1 [2,] 1 3 > t(b) [,1] [,2] [1,] 1 5 [2,] 4 0 [3,] 2 3 WIM and ISCC Intro to R Matrix Algebra 5 / 1

77 Inverse Matrix To find the inverse of a square matrix, if an inverse exists, > solve(a) [,1] [,2] [1,] [2,] > solve(c) [,1] [,2] [1,] [2,] WIM and ISCC Intro to R Matrix Algebra 6 / 1

78 Matrix Diagonals To extract the diagonal elements of a matrix: > diag(a) [1] 2 3 > diag(b) [1] 1 0 We can use diag() to create a diagonal matrix, like an identity matrix > diag(rep(1,3)) [,1] [,2] [,3] [1,] [2,] [3,] WIM and ISCC Intro to R Matrix Algebra 7 / 1

79 Singular Value Decomposition > svd(c) $d [1] $u [,1] [,2] [1,] [2,] $v [,1] [,2] [1,] [2,] WIM and ISCC Intro to R Matrix Algebra 8 / 1

80 Eigenvectors and Eigenvalues > eigen(a) $values [1] $vectors [,1] [,2] [1,] [2,] WIM and ISCC Intro to R Matrix Algebra 9 / 1

81 Workshop in Methods and Indiana Statistical Consulting Center Introduction to R Supplemental Material: Function Writing & Control Programming Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R Functions & Programming 1 / 1

82 if loop > n <- rnorm(1) > if (n < 0){ n <- abs(n) } WIM and ISCC Intro to R Functions & Programming 2 / 1

83 for loop > foo <- rep(0,10) > for (i in seq(1,10)){ foo[i] <- i+1 } > foo [1] WIM and ISCC Intro to R Functions & Programming 3 / 1

84 while loop > n <- 1 > while (n < 10){ n <- n+1 } WIM and ISCC Intro to R Functions & Programming 4 / 1

85 Define a New Function test.function <- function(input arguments){ commands to execute } WIM and ISCC Intro to R Functions & Programming 5 / 1

86 source() a Function into Working Memory source("pathname/test.function.r") WIM and ISCC Intro to R Functions & Programming 6 / 1

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

Matrix algebra. Basics

Matrix algebra. Basics Matrix.1 Matrix algebra Matrix algebra is very prevalently used in Statistics because it provides representations of models and computations in a much simpler manner than without its use. The purpose of

More information

Using R. Liang Peng Georgia Institute of Technology January 2005

Using R. Liang Peng Georgia Institute of Technology January 2005 Using R Liang Peng Georgia Institute of Technology January 2005 1. Introduction Quote from http://www.r-project.org/about.html: R is a language and environment for statistical computing and graphics. It

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

R syntax guide. Richard Gonzalez Psychology 613. August 27, 2015

R syntax guide. Richard Gonzalez Psychology 613. August 27, 2015 R syntax guide Richard Gonzalez Psychology 613 August 27, 2015 This handout will help you get started with R syntax. There are obviously many details that I cannot cover in these short notes but these

More information

1 Lab 1. Graphics and Checking Residuals

1 Lab 1. Graphics and Checking Residuals R is an object oriented language. We will use R for statistical analysis in FIN 504/ORF 504. To download R, go to CRAN (the Comprehensive R Archive Network) at http://cran.r-project.org Versions for Windows

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

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

An Introductory Guide to R

An Introductory Guide to R An Introductory Guide to R By Claudia Mahler 1 Contents Installing and Operating R 2 Basics 4 Importing Data 5 Types of Data 6 Basic Operations 8 Selecting and Specifying Data 9 Matrices 11 Simple Statistics

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

University of Wollongong School of Mathematics and Applied Statistics. STAT231 Probability and Random Variables Introductory Laboratory

University of Wollongong School of Mathematics and Applied Statistics. STAT231 Probability and Random Variables Introductory Laboratory 1 R and RStudio University of Wollongong School of Mathematics and Applied Statistics STAT231 Probability and Random Variables 2014 Introductory Laboratory RStudio is a powerful statistical analysis package.

More information

An Introduction to the R Commander

An Introduction to the R Commander An Introduction to the R Commander BIO/MAT 460, Spring 2011 Christopher J. Mecklin Department of Mathematics & Statistics Biomathematics Research Group Murray State University Murray, KY 42071 christopher.mecklin@murraystate.edu

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

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

7/18/16. Review. Review of Homework. Lecture 3: Programming Statistics in R. Questions from last lecture? Problems with Stata? Problems with Excel?

7/18/16. Review. Review of Homework. Lecture 3: Programming Statistics in R. Questions from last lecture? Problems with Stata? Problems with Excel? Lecture 3: Programming Statistics in R Christopher S. Hollenbeak, PhD Jane R. Schubart, PhD The Outcomes Research Toolbox Review Questions from last lecture? Problems with Stata? Problems with Excel? 2

More information

Introduction to R 21/11/2016

Introduction to R 21/11/2016 Introduction to R 21/11/2016 C3BI Vincent Guillemot & Anne Biton R: presentation and installation Where? https://cran.r-project.org/ How to install and use it? Follow the steps: you don t need advanced

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

R for IR. Created by Narren Brown, Grinnell College, and Diane Saphire, Trinity University

R for IR. Created by Narren Brown, Grinnell College, and Diane Saphire, Trinity University R for IR Created by Narren Brown, Grinnell College, and Diane Saphire, Trinity University For presentation at the June 2013 Meeting of the Higher Education Data Sharing Consortium Table of Contents I.

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

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

Introduction to Minitab 1

Introduction to Minitab 1 Introduction to Minitab 1 We begin by first starting Minitab. You may choose to either 1. click on the Minitab icon in the corner of your screen 2. go to the lower left and hit Start, then from All Programs,

More information

Intro to R h)p://jacobfenton.s3.amazonaws.com/r- handson.pdf. Jacob Fenton CAR Director InvesBgaBve ReporBng Workshop, American University

Intro to R h)p://jacobfenton.s3.amazonaws.com/r- handson.pdf. Jacob Fenton CAR Director InvesBgaBve ReporBng Workshop, American University Intro to R h)p://jacobfenton.s3.amazonaws.com/r- handson.pdf Jacob Fenton CAR Director InvesBgaBve ReporBng Workshop, American University Overview Import data Move around the file system, save an image

More information

STAT 540 Computing in Statistics

STAT 540 Computing in Statistics STAT 540 Computing in Statistics Introduces programming skills in two important statistical computer languages/packages. 30-40% R and 60-70% SAS Examples of Programming Skills: 1. Importing Data from External

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

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

GEN BUS 806 R COMMANDS

GEN BUS 806 R COMMANDS GEN BUS 806 R COMMANDS The following list of commands and information intends to assist you in getting familiar with the commands used in R common to the panel data analysis in GEN BUS 806 Useful Websites

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 (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

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

8. MINITAB COMMANDS WEEK-BY-WEEK

8. MINITAB COMMANDS WEEK-BY-WEEK 8. MINITAB COMMANDS WEEK-BY-WEEK In this section of the Study Guide, we give brief information about the Minitab commands that are needed to apply the statistical methods in each week s study. They are

More information

LAB 1 INSTRUCTIONS DESCRIBING AND DISPLAYING DATA

LAB 1 INSTRUCTIONS DESCRIBING AND DISPLAYING DATA LAB 1 INSTRUCTIONS DESCRIBING AND DISPLAYING DATA This lab will assist you in learning how to summarize and display categorical and quantitative data in StatCrunch. In particular, you will learn how to

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

No Name What it does? 1 attach Attach your data frame to your working environment. 2 boxplot Creates a boxplot.

No Name What it does? 1 attach Attach your data frame to your working environment. 2 boxplot Creates a boxplot. No Name What it does? 1 attach Attach your data frame to your working environment. 2 boxplot Creates a boxplot. 3 confint A metafor package function that gives you the confidence intervals of effect sizes.

More information

file:///users/williams03/a/workshops/2015.march/final/intro_to_r.html

file:///users/williams03/a/workshops/2015.march/final/intro_to_r.html Intro to R R is a functional programming language, which means that most of what one does is apply functions to objects. We will begin with a brief introduction to R objects and how functions work, and

More information

Basic matrix math in R

Basic matrix math in R 1 Basic matrix math in R This chapter reviews the basic matrix math operations that you will need to understand the course material and how to do these operations in R. 1.1 Creating matrices in R Create

More information

Tutorial: SeqAPass Boxplot Generator

Tutorial: SeqAPass Boxplot Generator 1 Tutorial: SeqAPass Boxplot Generator 1. Access SeqAPASS by opening https://seqapass.epa.gov/seqapass/ using Mozilla Firefox web browser 2. Open the About link on the login page or upon logging in to

More information

A (very) brief introduction to R

A (very) brief introduction to R A (very) brief introduction to R You typically start R at the command line prompt in a command line interface (CLI) mode. It is not a graphical user interface (GUI) although there are some efforts to produce

More information

36-402/608 HW #1 Solutions 1/21/2010

36-402/608 HW #1 Solutions 1/21/2010 36-402/608 HW #1 Solutions 1/21/2010 1. t-test (20 points) Use fullbumpus.r to set up the data from fullbumpus.txt (both at Blackboard/Assignments). For this problem, analyze the full dataset together

More information

Index. Bar charts, 106 bartlett.test function, 159 Bottles dataset, 69 Box plots, 113

Index. Bar charts, 106 bartlett.test function, 159 Bottles dataset, 69 Box plots, 113 Index A Add-on packages information page, 186 187 Linux users, 191 Mac users, 189 mirror sites, 185 Windows users, 187 aggregate function, 62 Analysis of variance (ANOVA), 152 anova function, 152 as.data.frame

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

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

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

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

Empirical Reasoning Center R Workshop (Summer 2016) Session 1. 1 Writing and executing code in R. 1.1 A few programming basics

Empirical Reasoning Center R Workshop (Summer 2016) Session 1. 1 Writing and executing code in R. 1.1 A few programming basics Empirical Reasoning Center R Workshop (Summer 2016) Session 1 This guide reviews the examples we will cover in today s workshop. It should be a helpful introduction to R, but for more details, the ERC

More information

II.Matrix. Creates matrix, takes a vector argument and turns it into a matrix matrix(data, nrow, ncol, byrow = F)

II.Matrix. Creates matrix, takes a vector argument and turns it into a matrix matrix(data, nrow, ncol, byrow = F) II.Matrix A matrix is a two dimensional array, it consists of elements of the same type and displayed in rectangular form. The first index denotes the row; the second index denotes the column of the specified

More information

Handout #1. The abbreviations of FIVE references are PE, MPS, BR, FCDAE, and PRA. There is additional reference about the use of R (BR).

Handout #1. The abbreviations of FIVE references are PE, MPS, BR, FCDAE, and PRA. There is additional reference about the use of R (BR). Handout #1 Title: FAE Course: Econ 368/01 Spring/2015 Instructor: Dr. I-Ming Chiu The abbreviations of FIVE references are PE, MPS, BR, FCDAE, and PRA. There is additional reference about the use of R

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

R Workshop Guide. 1 Some Programming Basics. 1.1 Writing and executing code in R

R Workshop Guide. 1 Some Programming Basics. 1.1 Writing and executing code in R R Workshop Guide This guide reviews the examples we will cover in today s workshop. It should be a helpful introduction to R, but for more details, you can access a more extensive user guide for R on 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

Statistics 251: Statistical Methods

Statistics 251: Statistical Methods Statistics 251: Statistical Methods Summaries and Graphs in R Module R1 2018 file:///u:/documents/classes/lectures/251301/renae/markdown/master%20versions/summary_graphs.html#1 1/14 Summary Statistics

More information

Introduction to R Commander

Introduction to R Commander Introduction to R Commander 1. Get R and Rcmdr to run 2. Familiarize yourself with Rcmdr 3. Look over Rcmdr metadata (Fox, 2005) 4. Start doing stats / plots with Rcmdr Tasks 1. Clear Workspace and History.

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

Lab 1: Getting started with R and RStudio Questions? or

Lab 1: Getting started with R and RStudio Questions? or Lab 1: Getting started with R and RStudio Questions? david.montwe@ualberta.ca or isaacren@ualberta.ca 1. Installing R and RStudio To install R, go to https://cran.r-project.org/ and click on the Download

More information

Why use R? Getting started. Why not use R? Introduction to R: It s hard to use at first. To perform inferential statistics (e.g., use a statistical

Why use R? Getting started. Why not use R? Introduction to R: It s hard to use at first. To perform inferential statistics (e.g., use a statistical Why use R? Introduction to R: Using R for statistics ti ti and data analysis BaRC Hot Topics November 2013 George W. Bell, Ph.D. http://jura.wi.mit.edu/bio/education/hot_topics/ To perform inferential

More information

Fathom Dynamic Data TM Version 2 Specifications

Fathom Dynamic Data TM Version 2 Specifications Data Sources Fathom Dynamic Data TM Version 2 Specifications Use data from one of the many sample documents that come with Fathom. Enter your own data by typing into a case table. Paste data from other

More information

Regression Lab 1. The data set cholesterol.txt available on your thumb drive contains the following variables:

Regression Lab 1. The data set cholesterol.txt available on your thumb drive contains the following variables: Regression Lab The data set cholesterol.txt available on your thumb drive contains the following variables: Field Descriptions ID: Subject ID sex: Sex: 0 = male, = female age: Age in years chol: Serum

More information

Stat 528 (Autumn 2008) Density Curves and the Normal Distribution. Measures of center and spread. Features of the normal distribution

Stat 528 (Autumn 2008) Density Curves and the Normal Distribution. Measures of center and spread. Features of the normal distribution Stat 528 (Autumn 2008) Density Curves and the Normal Distribution Reading: Section 1.3 Density curves An example: GRE scores Measures of center and spread The normal distribution Features of the normal

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

Why use R? Getting started. Why not use R? Introduction to R: Log into tak. Start R R or. It s hard to use at first

Why use R? Getting started. Why not use R? Introduction to R: Log into tak. Start R R or. It s hard to use at first Why use R? Introduction to R: Using R for statistics ti ti and data analysis BaRC Hot Topics October 2011 George Bell, Ph.D. http://iona.wi.mit.edu/bio/education/r2011/ To perform inferential statistics

More information

Basics of Plotting Data

Basics of Plotting Data Basics of Plotting Data Luke Chang Last Revised July 16, 2010 One of the strengths of R over other statistical analysis packages is its ability to easily render high quality graphs. R uses vector based

More information

Chapter 2: Descriptive Statistics: Tabular and Graphical Methods

Chapter 2: Descriptive Statistics: Tabular and Graphical Methods Chapter 2: Descriptive Statistics: Tabular and Graphical Methods Example 1 C2_1

More information

Reading and wri+ng data

Reading and wri+ng data An introduc+on to Reading and wri+ng data Noémie Becker & Benedikt Holtmann Winter Semester 16/17 Course outline Day 4 Course outline Review Data types and structures Reading data How should data look

More information

Computer lab 2 Course: Introduction to R for Biologists

Computer lab 2 Course: Introduction to R for Biologists Computer lab 2 Course: Introduction to R for Biologists April 23, 2012 1 Scripting As you have seen, you often want to run a sequence of commands several times, perhaps with small changes. An efficient

More information

Numerical Methods 5633

Numerical Methods 5633 Numerical Methods 5633 Lecture 1 Marina Krstic Marinkovic marina.marinkovic@cern.ch School of Mathematics Trinity College Dublin Marina Krstic Marinkovic 1 / 15 5633-Numerical Methods R programming https://www.r-project.org/

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

Introduction to Resources and Block 2: EDA Introduction to R software

Introduction to Resources and Block 2: EDA Introduction to R software ACADEMIC YEAR 2017-18 DATA ANALYSIS OF TRANSPORT AND LOGISTICS MSCTL - UPC Introduction to Resources and Block 2: EDA Introduction to R software Lecturer: Lídia Montero September 2017 Version 1.1 MASTER

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

Package qrfactor. February 20, 2015

Package qrfactor. February 20, 2015 Type Package Package qrfactor February 20, 2015 Title Simultaneous simulation of Q and R mode factor analyses with Spatial data Version 1.4 Date 2014-01-02 Author George Owusu Maintainer

More information

LAB #1: DESCRIPTIVE STATISTICS WITH R

LAB #1: DESCRIPTIVE STATISTICS WITH R NAVAL POSTGRADUATE SCHOOL LAB #1: DESCRIPTIVE STATISTICS WITH R Statistics (OA3102) Lab #1: Descriptive Statistics with R Goal: Introduce students to various R commands for descriptive statistics. Lab

More information

Practical 2: Plotting

Practical 2: Plotting Practical 2: Plotting Complete this sheet as you work through it. If you run into problems, then ask for help - don t skip sections! Open Rstudio and store any files you download or create in a directory

More information

Lab 1. Introduction to R & SAS. R is free, open-source software. Get it here:

Lab 1. Introduction to R & SAS. R is free, open-source software. Get it here: Lab 1. Introduction to R & SAS R is free, open-source software. Get it here: http://tinyurl.com/yfet8mj for your own computer. 1.1. Using R like a calculator Open R and type these commands into the R Console

More information

Using R for statistics and data analysis

Using R for statistics and data analysis Introduction ti to R: Using R for statistics and data analysis BaRC Hot Topics October 2011 George Bell, Ph.D. http://iona.wi.mit.edu/bio/education/r2011/ Why use R? To perform inferential statistics (e.g.,

More information

Introduction to R: Using R for statistics and data analysis

Introduction to R: Using R for statistics and data analysis Why use R? Introduction to R: Using R for statistics and data analysis George W Bell, Ph.D. BaRC Hot Topics November 2014 Bioinformatics and Research Computing Whitehead Institute http://barc.wi.mit.edu/hot_topics/

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

Step-by-step user instructions to the hamlet-package

Step-by-step user instructions to the hamlet-package Step-by-step user instructions to the hamlet-package Teemu Daniel Laajala May 26, 2018 Contents 1 Analysis workflow 2 2 Loading data into R 2 2.1 Excel format data.......................... 4 2.2 CSV-files...............................

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

Getting Started. Slides R-Intro: R-Analytics: R-HPC:

Getting Started. Slides R-Intro:   R-Analytics:   R-HPC: Getting Started Download and install R + Rstudio http://www.r-project.org/ https://www.rstudio.com/products/rstudio/download2/ TACC ssh username@wrangler.tacc.utexas.edu % module load Rstats %R Slides

More information

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

R (and S, and S-Plus, another program based on S) is an interactive, interpretive, function language. 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

More information

Installing and Using R

Installing and Using R The National Animal Nutrition Program (NANP) Modeling Committee A National Research Support Project (NRSP-9) Supported by the Experiment Station Committee on Organization and Policy, The State Agricultural

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

Business Statistics: R tutorials

Business Statistics: R tutorials Business Statistics: R tutorials Jingyu He September 29, 2017 Install R and RStudio R is a free software environment for statistical computing and graphics. Download free R and RStudio for Windows/Mac:

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

Introduction to R: Using R for statistics and data analysis

Introduction to R: Using R for statistics and data analysis Why use R? Introduction to R: Using R for statistics and data analysis George W Bell, Ph.D. BaRC Hot Topics November 2015 Bioinformatics and Research Computing Whitehead Institute http://barc.wi.mit.edu/hot_topics/

More information

R Demonstration Summary Statistics and the Law of Large Numbers

R Demonstration Summary Statistics and the Law of Large Numbers R Demonstration Summary Statistics and the Law of Large Numbers Objective: The purpose of this session is to use some of the R functionality you have recently learned to demonstrate the Law of Large Numbers.

More information

Correlation. January 12, 2019

Correlation. January 12, 2019 Correlation January 12, 2019 Contents Correlations The Scattterplot The Pearson correlation The computational raw-score formula Survey data Fun facts about r Sensitivity to outliers Spearman rank-order

More information

8.1 R Computational Toolbox Tutorial 3

8.1 R Computational Toolbox Tutorial 3 8.1 R Computational Toolbox Tutorial 3 Introduction to Computational Science: Modeling and Simulation for the Sciences, 2 nd Edition Angela B. Shiflet and George W. Shiflet Wofford College 2014 by Princeton

More information

Brief cheat sheet of major functions covered here. shoe<-c(8,7,8.5,6,10.5,11,7,6,12,10)

Brief cheat sheet of major functions covered here. shoe<-c(8,7,8.5,6,10.5,11,7,6,12,10) 1 Class 2. Handling data in R Creating, editing, reading, & exporting data frames; sorting, subsetting, combining Goals: (1) Creating matrices and dataframes: cbind and as.data.frame (2) Editing data:

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

Stat 579: More Preliminaries, Reading from Files

Stat 579: More Preliminaries, Reading from Files Stat 579: More Preliminaries, Reading from Files Ranjan Maitra 2220 Snedecor Hall Department of Statistics Iowa State University. Phone: 515-294-7757 maitra@iastate.edu September 1, 2011, 1/10 Some more

More information

An introduction to R 1 / 29

An introduction to R 1 / 29 An introduction to R 1 / 29 What is R? R is an integrated suite of software facilities for data manipulation, calculation and graphical display. Among other things it has: an effective data handling and

More information

GRAD6/8104; INES 8090 Spatial Statistic Spring 2017

GRAD6/8104; INES 8090 Spatial Statistic Spring 2017 Lab #1 Basics in Spatial Statistics (Due Date: 01/30/2017) PURPOSES 1. Get familiar with statistics and GIS 2. Learn to use open-source software R for statistical analysis Before starting your lab, create

More information

Module 1: Introduction RStudio

Module 1: Introduction RStudio Module 1: Introduction RStudio Contents Page(s) Installing R and RStudio Software for Social Network Analysis 1-2 Introduction to R Language/ Syntax 3 Welcome to RStudio 4-14 A. The 4 Panes 5 B. Calculator

More information

IQR = number. summary: largest. = 2. Upper half: Q3 =

IQR = number. summary: largest. = 2. Upper half: Q3 = Step by step box plot Height in centimeters of players on the 003 Women s Worldd Cup soccer team. 157 1611 163 163 164 165 165 165 168 168 168 170 170 170 171 173 173 175 180 180 Determine the 5 number

More information

Author: Leonore Findsen, Qi Wang, Sarah H. Sellke, Jeremy Troisi

Author: Leonore Findsen, Qi Wang, Sarah H. Sellke, Jeremy Troisi 0. Downloading Data from the Book Website 1. Go to http://bcs.whfreeman.com/ips8e 2. Click on Data Sets 3. Click on Data Sets: PC Text 4. Click on Click here to download. 5. Right Click PC Text and choose

More information

Statistical Software Camp: Introduction to R

Statistical Software Camp: Introduction to R Statistical Software Camp: Introduction to R Day 1 August 24, 2009 1 Introduction 1.1 Why Use R? ˆ Widely-used (ever-increasingly so in political science) ˆ Free ˆ Power and flexibility ˆ Graphical capabilities

More information

Introduction to R. Biostatistics 615/815 Lecture 23

Introduction to R. Biostatistics 615/815 Lecture 23 Introduction to R Biostatistics 615/815 Lecture 23 So far We have been working with C Strongly typed language Variable and function types set explicitly Functional language Programs are a collection of

More information

Common Sta 101 Commands for R. 1 One quantitative variable. 2 One categorical variable. 3 Two categorical variables. Summary statistics

Common Sta 101 Commands for R. 1 One quantitative variable. 2 One categorical variable. 3 Two categorical variables. Summary statistics Common Sta 101 Commands for R 1 One quantitative variable summary(x) # most summary statitstics at once mean(x) median(x) sd(x) hist(x) boxplot(x) # horizontal = TRUE for horizontal plot qqnorm(x) qqline(x)

More information

R package

R package R package www.r-project.org Download choose the R version for your OS install R for the first time Download R 3 run R MAGDA MIELCZAREK 2 help help( nameofthefunction )? nameofthefunction args(nameofthefunction)

More information

S CHAPTER return.data S CHAPTER.Data S CHAPTER

S CHAPTER return.data S CHAPTER.Data S CHAPTER 1 S CHAPTER return.data S CHAPTER.Data MySwork S CHAPTER.Data 2 S e > return ; return + # 3 setenv S_CLEDITOR emacs 4 > 4 + 5 / 3 ## addition & divison [1] 5.666667 > (4 + 5) / 3 ## using parentheses [1]

More information

Minitab 17 commands Prepared by Jeffrey S. Simonoff

Minitab 17 commands Prepared by Jeffrey S. Simonoff Minitab 17 commands Prepared by Jeffrey S. Simonoff Data entry and manipulation To enter data by hand, click on the Worksheet window, and enter the values in as you would in any spreadsheet. To then save

More information