itmat pcbi-r-course-1
DESCRIPTION
First part of 3-part course on teaching the R statistical package.TRANSCRIPT
![Page 2: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/2.jpg)
Injecting a bit of reality
![Page 3: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/3.jpg)
Taking it a bit further…
Waxing floors is not fun, and may not seem relevant, but have some faith Daniel-san
![Page 4: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/4.jpg)
Outline
• We will teach you some basic uses of R– “Do & Tell” method where you will be asked to do
an exercise and once done, we will explain what just happened.
– Will cover basics, plotting and microarray analysis• We will not teach you statistics.
![Page 5: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/5.jpg)
What is ?R is a language and environment for statistical computing and graphics.
– http://www.r-project.org
You can do stuff like this
![Page 6: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/6.jpg)
Install & Run R
• You should have already installed R, but if you had trouble please see us after class
• Start R– On Windows, use Tinn-R– On Mac, use the source R application– On Linux, use the console
![Page 7: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/7.jpg)
Help is plentiful
Help in three ways
Too much! Get me out!
![Page 8: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/8.jpg)
More Helphelp.start()
– Start an HTML help session
help(mean)– Looks up the mean()
function's help page– ?mean
help.search(mean) – Displays all help pages that
contain text “mean”– ??mean
![Page 9: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/9.jpg)
Whet your appetite…
![Page 10: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/10.jpg)
The Basics
• Please enter each of the following lines into your R session:
![Page 11: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/11.jpg)
![Page 12: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/12.jpg)
![Page 13: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/13.jpg)
![Page 14: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/14.jpg)
Basic Algebra
You will also see this form:
![Page 15: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/15.jpg)
Variables
• “x” and “y” are variables. • They are pointers to some value• They can also be pointers to some function
![Page 16: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/16.jpg)
Vectors
Enter this in your session: Results
![Page 17: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/17.jpg)
Small tangent: What is “c (1,2,3)”?
• Use the help()
![Page 18: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/18.jpg)
Accessing Vector MembersIn R, Vectors start indexes at 1. Most programming languages start indexing at zero
Also, NOT WHAT YOU THINK IT IS! It is a INDEX VECTOR, meaning that you access the members of a vector with a vector
![Page 19: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/19.jpg)
Small Tangent 2: Creating Sequences
• Create regular sequences using a colon
• Colon has high operator precedence
• Also see the seq() function
![Page 20: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/20.jpg)
Vectors
• Are a list of items of the same data type
Short for “double precision floating point number”
![Page 21: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/21.jpg)
Doing Stuff with Vectors
• Math operations occur on each element in sequence
• Returns a vector of the same size
![Page 22: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/22.jpg)
Factors
• Simply a vector of items that mean something– Disease classifications, drug dosage, US states,
months, hapmap ethnic group– Can be ordered– Can have multiple levels• GO Functions
![Page 23: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/23.jpg)
Array and Matrix
• Multi-dimensional generalizations of vectors– k-dimensions where k > 0– Assigned by the dim attribute
• Can be indexed by two or more indices– If a single index value (can be a vector) is given,
then dim is ignored and underlying vector values are accessed directly
– Unless the given index values is also an array• Matrix is a two-dimensional array
![Page 24: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/24.jpg)
Example
An INDEX ARRAY
![Page 25: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/25.jpg)
List
• An ordered collection of named components
![Page 26: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/26.jpg)
List Access
![Page 27: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/27.jpg)
Data Frame
• Bastard step child of List and Matrix– Essentially a list of vectors of same length
• Closest representation to an Excel file in R• Easiest way to make one is to read in a CSV file
![Page 28: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/28.jpg)
![Page 29: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/29.jpg)
![Page 30: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/30.jpg)
Functions
• We’ve already used them• Functions take in arguments and perform
some action using those arguments. • Actions do not affect the input arguments
![Page 31: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/31.jpg)
Example
![Page 32: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/32.jpg)
Write to CSV file
Extra column of the row indices
![Page 33: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/33.jpg)
Save your work!
• R keeps track of your data and functions
• You can start from where you left off if you save these to some file
![Page 34: Itmat pcbi-r-course-1](https://reader036.vdocuments.us/reader036/viewer/2022081603/5589649cd8b42ab94b8b45f6/html5/thumbnails/34.jpg)
Start from your save point