Introduction to R Introduction to Systems Biology Course Chris Plaisier Institute for Systems Biology.

Slides:



Advertisements
Similar presentations
Introduction to R Brody Sandel. Topics Approaching your analysis Basic structure of R Basic programming Plotting Spatial data.
Advertisements

R Packages Davor Cubranic SCARL, Dept. of Statistics.
R for Macroecology Aarhus University, Spring 2011.
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Chapter Chapter 4. Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Computer Science 101 Introduction to Programming.
Python Programming Fundamentals
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Introduction to Python
732A44 Programming in R.  Self-studies of the course book  2 Lectures (1 in the beginning, 1 in the end)  Labs (computer). Compulsory submission of.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Python: An Introduction
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
Introduction to Eclipse. What is Eclipse? An Integrated Development Environment Provides many features to ease C++ programming (and others, e.g. C/Java)
9/2/ CS171 -Math & Computer Science Department at Emory University.
Outline Comparison of Excel and R R Coding Example – RStudio Environment – Getting Help – Enter Data – Calculate Mean – Basic Plots – Save a Coding Script.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Introduction to R Introductions What is R? RStudio Layout Summary Statistics Your First R Graph 17 September 2014 Sherubtse Training.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Chris Knight Beginners’ workshop.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Pinellas County Schools
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Introduction to R Chris Free. Introduction to R Free! Superior (if not comparable) to commercial alternatives Available on all platforms Not just for.
Introduction to R and Data Science Tools in the Microsoft Stack Jamey Johnston.
Block 1: Introduction to R
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Topics Introduction to Repetition Structures
MATLAB DENC 2533 ECADD LAB 9.
Lab 1 Introductions to R Sean Potter.
Code is on the Website Outline Comparison of Excel and R
Coding Concepts (Basics)
C Programming Getting started Variables Basic C operators Conditionals
R Course 1st Lecture.
Data analysis with R and the tidyverse
> Introduction to Nelson Rios, Tulane University
Introduction to Python
Programming for Business Computing Introduction
Presentation transcript:

Introduction to R Introduction to Systems Biology Course Chris Plaisier Institute for Systems Biology

The beginner's perspective Jason's Fix it up blog Speaking the lingo xkcd.com

Why use R? R is FREE!!! Many built-in functions and installable packages that will cover nearly every possible need R is an interpreted language – Code doesn’t have to be compiled Interactive console makes testing and debugging easy Cons to using R – Slower than compiled languages – Can have runtime errors

Bioconductor!

Why use R? Python RPerl C/C++ programming languages

Tools R The engine* Rstudio The pretty face** * Many alternatives exist. Smallest learning curve. ** A few alternatives exist. This happens to be the easiest at the moment.

Introducing Rstudio console (just like Rterm) workspace: your variables history: last command files plots packages help

Rstudio Features Code completion Command history search Command history to R script / file Function extraction from Rscript Sweave support

Configuring Rstudio

Choosing a CRAN Mirror CRAN mirrors contain the R packages that can extend the functionality of R Choose a mirror located close to you as that will most likely give you the fastest downloads

Choosing Repositories Repositories host the packages – CRAN, CRANextra, BioCsoft, BioCann, BioCexp, BioCext, Omegahat, R-Forge and rforge.net Use this code to set your repositories setRepositories()

Packages Tab

How do Packages Work? Packages tab lets you see what packages are installed A package must be loaded before you can use it – In Rstudio this is accomplished by clicking the checkbox next to the package name in the package tab We will be using different packages throughout this tutorial

Working Directory 1 2

Ready to Code! The working directory is where Rstudio will look first for scripts Keeping everything in a self contained directory helps organize code and analyses Check you current working directory with getwd()

R as a Calculator

Basic Math / Basic Logic + addition - subtraction * multiplication / division % modulus (remainder) ^ to the power ?Arithmetic ! NOT & bitwise AND | bitwise OR && shortcircuit AND || shortcircuit OR == equality != NOT equality ?Logic Also try ?Syntax, ?Comparison

Make New R Script

script tab pane

Run Script Loaded in Rstudio

Saving Your Workspace In R you can save your entire workspace, variables and all in its current state Then you can reload this at a later time or can provie this to collaborators Workspace data files are saved with the extension ‘.Rdata’

Getting Help Inside of R – Simplify make a fake dataset – help( ) – ? – ?? On the web – and R only search engine – CRAN – Google topic with CRAN

Creating Variables Named containers for data Names can be anything you like except for 'special' words Better if names describe what the stored data is Creating / Setting variables is a matter of equality: var = somedata

Data Types in R R's atomic data type is the vector o numeric  floating point  integer o logical o character functions lists o let you combine other data types > a <- 101 > length(a) [1] 1 > a[1] [1] 101 > a[2] [1] NA > a[2] <- 202 > length(a) [1] 2

Coding xkcd #844

Arrays / Matrices 5x1 Ikea Expedit "Vector" 4x4 Ikea Expedit "Matrix"

Vignettes Some packages have vignettes – A vignettes is an example of how to run the code and a lot of additional text explaining a lot more that you may want to know List all available vignettes: vignette() Display the vignette as a pdf by executing vignette(‘ ’) To play with the vignette code vig = vignette(‘ ’) edit(vig)

Programmatic Structure if... then... else for... while...

For Loop Repeats a line or lines (known as a block) of code until: – (for loop) a count limit is reached for (i in 1:10) {... code... } the above loop runs 10 times '{' and '}' enclose code looped the variable i updated in the loop to values in the sequence 1:10

A Simple For Loop # P-values from our analysis p.values = c(0.1, 0.05, 0.003, 0.4, 0.9) # A vector to store the negative log p-values neglog10.p.values = 1:5 # Transform the p-values for(p in 1:length(p.values)) { neglog10.p.values[p] = -log10(p.values[p]) } neglog10.p.values.2 = -log10(p.values)

While Loop Repeats a line or lines (known as a block) of code until: – (while loop) a logical condition is reached while (stop != TRUE) {... code... } the above loop runs until code sets stop = TRUE warning: if not properly written while loops can run infinitely

A Simple While Loop # Numbers from our analysis v1 = c(21, 22, 53, 74, 85, 96, 97, 58, 49, 30, 85) # Iterator i = 1 # Look for first instance of 85 while(v1[i] != 85) { i = i + 1 } # Print out where we found it print(paste('v1[',i,'] = 85',sep=''))

Functions Bits of code that do one thing and (preferrably) do it well Functions break up your code into more manageable and reusable parts Defining (e.g. in a script): fun = function(arguments) {... code... } Calling: party = fun(food,beer,folks)

A Simple Function fn1 <- function(N) { for(i in as.numeric(1:N)) { y <- i*i } } fn2 <- function(N) { i = 1 while(i <= N) { y <- i*i i <- i + 1 } system.time(fn1(60000)) system.time(fn2(60000))

Student’s T-test

Comparing the Means of Two Groups Sleep dataset in R is a comparison of two soporific drugs on students sleep habits

Doing a Student’s T-test t.test(sleep[1:10,’extra’],sleep[11:20,’extra’]) or t.test(extra ~ group, data = sleep)

Correlation

Testing for a Correlation cor.test(c(1:10), c(11:20))

Testing for a Correlation cor.test(c(1:10), -c(11:20))

What else is built-in? library(help="stats")

Thanks Lee Pang Chris Bare Baliga Lab