Refresh- Caitlin Collins, Thibaut Jombart MRC Centre for Outbreak Analysis and Modelling Imperial College London Genetic data analysis using 30-10-2014.

Slides:



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

CC SQL Utilities.
A very short introduction to R Pia Wohland. R is… -A statistical software -Programming language -Free! -Very good in handling and manipulating data sets.
R Packages Davor Cubranic SCARL, Dept. of Statistics.
R Packages Davor Cubranic SCARL, Dept. of Statistics.
R for Macroecology Aarhus University, Spring 2011.
Training on R For 3 rd and 4 th Year Honours Students, Dept. of Statistics, RU Empowered by Higher Education Quality Enhancement Project (HEQEP) Department.
Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Basics of Using R Xiao He 1. AGENDA 1.What is R? 2.Basic operations 3.Different types of data objects 4.Importing data 5.Basic data manipulation 2.
R for Research Data Analysis using R Day1: Basic R Baburao Kamble University of Nebraska-Lincoln.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
How to Use the R Programming Language for Statistical Analyses Part I: An Introduction to R Jennifer Urbano Blackford, Ph.D. Department of Psychiatry Kennedy.
1 Programming Concepts Module Code : CMV6107 Class Contact Hours: 45 hours (Lecture 15 hours) (Laboratory/Tutorial 30 hours) Module Value: 1 Textbook:
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
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.
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Intro to R R is a free version of S-plus R is a free version of S-plus Can be used interactively but script or syntax files are commonly used to record.
Data Objects in R Vector1 dimensionAll elements have the same data types Data types: numeric, character logic, factor Matrix2 dimensions Array2 or more.
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.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
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,
R Programming Yang, Yufei. Normal distribution.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
The Report Generator Viewing Student Outcomes. Install the Report Generator In a browser, go to Click.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Introduction to CADStat. CADStat and R R is a powerful and free statistical package [
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring.
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,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Introduction to R and Data Science Tools in the Microsoft Stack Jamey Johnston.
Preface IIntroduction Course Objectives I-2 Course Content I-3 1Introduction to Oracle Reports Developer Objectives 1-2 Business Intelligence 1-3 Enterprise.
Introduction to R Chris Free. Introduction to R Free! Superior (if not comparable) to commercial alternatives Available on all platforms Not just for.
16BIT IITR Data Collection Module If you have not already done so, download and install R from download.
1 Using an Integrated Development Environment. Integrated Development Environments An Integrated Development Environment, or IDE, permits you to edit,
Working with data in R 2 Fish 552: Lecture 3. Recommended Reading An Introduction to R (R Development Core Team) –
Introduction to R and Data Science Tools in the Microsoft Stack Jamey Johnston.
Introduction to R Dr. Satish Nargundkar. What is R? R is a free software environment for statistical computing and graphics. It compiles and runs on a.
Introduction to R and Data Science Tools in the Microsoft Stack
Programming in R Intro, data and programming structures
Introduction to R Samal Dharmarathna.
Introduction to R Carolina Salge March 29, 2017.
Intro to R & MS Data Science Tools
Introduction to R Studio
Scripts & Functions Scripts and functions are contained in .m-files
Microsoft Word 2003 Illustrated Complete
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Lab 1 Introductions to R Sean Potter.
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
1. Open Visual Studio 2008.
Basics of R, Ch Functions Help Managing your Objects
ACE Secure Data Portal - Accounts Tab - Statements
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
MIS2502: Data Analytics Introduction to R and RStudio
Setting up R Project Link to download R: Link to download R console:
R Course 1st Lecture.
Data analysis with R and the tidyverse
Presentation transcript:

Refresh- Caitlin Collins, Thibaut Jombart MRC Centre for Outbreak Analysis and Modelling Imperial College London Genetic data analysis using

Outline Getting started o Installing R, loading libraries, getting help Data o Reading in data, data structures in R Objects o Classes, accessors Commands to know o Logical operations, subsetting Useful links o R intro: o adegenet on the web: 2Outline

Getting sta ted 3

Installing Get the software—for free! o Check your version o > R.version.string o Are you using version ? If not: > install.packages(“installr”) > library(installr) > updateR() In RStudio… o Select menu: Tools > Global options… > R version > Change R editors o RStudio: o Tinn-R: o Emacs*: * requires compilation on Windows… 4Getting started

Modula- Core o Basic “necessary” packages Packages o > library() o >.libPaths() Libraries must be installed and loaded explicitly o > install.packages(“pkg”, dependencies = TRUE) o > library(pkg) o > require(pkg) # used inside functions To unload packages: o > detach("package:pkg", unload = TRUE) 5Getting started

P oblem solving 6

Conflicts Example: o > library(adegenet) o > library(Rcurl) Solution 1: o > detach("package:RCurl", unload = TRUE) o > detach("package:adegenet", unload = TRUE) o > library(Rcurl) # load the minor pkg first o > library(adegenet) # load the more important pkg second Solution 2.1: o > adegenet::pop(x) # one-time solution Solution 2.2: o > pop <- adegenet::pop # “permanent” solution o > pop(x) 7Problem solving

Help! Package-level o > ?pkg o > vignette(all = FALSE) # list vignettes from all *attached* pkgs Function-level o > help(“fn”) # search documentation for this package o > ?fn # same as above o > ??fn # extensive search (including in unloaded packages) o > ?plot.fn # searches for a specific version of a common fn (eg. plot) o > example(fn) # runs the example from the end of fn’s documentation More o Tutorials adegenet (basics): adegenet (DAPC): adegenet (genomics): adegenet (spatial-PCA): o Online resources adegenet : o Forums & mailing lists adegenet : R-sig-phylo: R-sig-genetics: o Google <3 8Problem solving

Errors Interpret o > ?fn # check the documentation o > warnings() # prints errors if multiple errors generated o > traceback() # prints the calls that led to the error o > debug(fn(x)) # execute a fn one statement at a time o > options(error = recover) # switches to browser mode where the error occurs Silence o > suppressWarnings(fn(x)) o > fn(x, silent = TRUE) More: o 9Problem solving

Objets d’ (data) 10

Reading in data Working directory o > getwd() o > setwd(“C:/Users/YourName/”) Load data o > foo <- get(load(“~/PathFromWD.Rdata”)) o > read.csv(“~/PathFromWD.csv”) o > read.table(“~/PathFromWD.csv”, header = TRUE) Check o > head(foo) o > dim(foo) o > names(foo) o > str(foo) o > summary(foo) 11Objets d’R

Structures: o Vectors o Matrices o Data frames o Lists Useful functions: o > class(x) o Example with matrix: o > matrix(x) o > is.matrix(x) o > as.matrix(x) 12Objets d’R Object classes

13Objets d’R Data types Types: o Character o Numeric o Integer o Logical o Factor Useful functions: o > class(x) # get class or type o > length(x) o > str(x) # get structure of x o > names(x) o > c(x1, x2, …) # combine  vector o > cbind(x1, x2, …) # bind columns o > rbind(x, x2, …) # bind rows o > ls() # list all current objects o > rm(x) # remove object x

S4s & accessors S3 o The basic R object system o Easy to interact with S4 objects o More formal, rigorous system for objects, classes, methods o Use slots to compartmentalise interactions Accessed by “accessors” $ ) o Examples of S4 objects: genind, genpop, genlight Useful functions for S4 objects: o Example with genlight object: o > x <- new(“genlight”, input) # create objects o > getClassDef(“genlight”) # examine structure of objects of this class o > showClass(x)# get class o > slotNames(x)# retrieve all names of slots o > # access the slot containing loci names o > y <- as.matrix(x)[,c(1,2)] # make “y” a subset of x containing columns 1 & 2 14Objets d’R

Commands to know 15

Logical operators > !x # NOT x > x & y # x AND y (element-wise) > x && y # x AND y (left-to-right, 1 st element only) > x | y # x OR y (element-wise) > x || y # x OR y (left-to-right, 1 st element only) > x == y # is x EQUAL to y?  TRUE/FALSE > x %in% y # element-wise: is x n in y?  TRUE/FALSE > !x %in% y # element-wise: is x n NOT in y?  T/F > which(x %in% y) #  indices of the x in y > all(x == 1) # are ALL elements of x EQUAL to 1? > any(x==1) # are ANY elements of x EQUAL to 1? > which(x==1) # which elements of x are EQUAL to 1? 16Commands to know

Subsetting > y <- x[1] # get the 1 st element of a vector > y <- x[c(1:10, 100), 7] # get the first 10 rows and the 100 th row of column 7 > y <- x[[1]] # get the 1 st element of a list > y <- x[[3]][[2]] # get the 2 nd item from within the 3 rd item of a list > y <- x$loc.names # get the item/ slot of x named “loc.names” > y <- x[[“loc.names]] # same as above > nom <- “loc.names”; y <- x[[nom]] # same as above > y <- x[!is.na(x)] # get all elements of x that are not NA > y = 20)] # get all elements of x except those greater than or equal to 20 > y = 20)] # same as above > y = 20) # same as above > y <- sample(x, 50, replace = TRUE) # get a random sample of 50 values from x, allowing for replacement 17Commands to know

Thank you! 18

Questions? 19