learning
play

Learning An Introduction for New Users & Advanced Techniques - PowerPoint PPT Presentation

Learning An Introduction for New Users & Advanced Techniques Professional Development Opportunity for the Flow Cytometry Core Facility July 27 th & August 24 th , 2018 LKG Consulting Email: consulting.lkg@gmail.com Website:


  1. Learning An Introduction for New Users & Advanced Techniques Professional Development Opportunity for the Flow Cytometry Core Facility July 27 th & August 24 th , 2018 LKG Consulting Email: consulting.lkg@gmail.com Website: www.consultinglkg.com

  2. The goal of this workshop is to introduce (or re- introduce) you to R Programming Language through reference tools and interactive examples. At the end of this workshop you will NOT be an R master (sorry), but you will be have a bunch of knowledge and tricks to help you on your ongoing R adventures.

  3. A little about me… Laura Gray-Steinhauer www.ualberta.ca/~lkgray BSc in Mathematics, Statistics and Environmental Studies (UVIC, 2005) MSc in Forest Biology and Management (UofA, 2008) PhD in Forest Biology and Management (UofA, 2011) Designated Professional Statistician with The Statistical Society of Canada (2014) Research : Climate Change, Policy Evaluation, Adaptation, Mitigation, Risk management for forest resources, Conservation…

  4. Learning R: An Introduction for New Users & Advanced Techniques Workshop Schedule 8:15 – 8:30 Arrive to the Lab & Start up the computers 8:30 – 8:45 Welcome to the Workshop (housekeeping & today’s goals) Introduction to R 8:45 – 9:05 Unit 1 : Getting started in R (script files, working directories, RStudio, etc.) 9:05 – 9:30 Unit 2 : Data Preparation in R (import/export, missing values, modes, classes, etc.) 9:30 – 10:30 Work period (questions are welcome) 10:30 – 10:45 Break 10:45 – 11:15 Unit 3 : Data Management in R (tidyr and dplyr packages, etc.) 11:15 – 12:15 Work period (questions are welcome) 12:15 – 1:00 Lunch Advanced R 1:00 – 1:30 Unit 4 : Control Structures (loops, apply functions, etc.) 1:30 – 1:45 Unit 5 : Functions (build your own) 1:45 – 2:45 Work period (questions are welcome) 2:45 – 3:00 Break 3:00 – 3:30 Unit 6 : Graphics (ggplot2 package) 3:30 – 5:00 Work period (questions welcome) After 5:00 Enjoy your weekend!

  5. Workbook • Yours to keep! • Goes into MANY more examples than we will have time to go through in this course. • R code is identified by Century Gothic font (everything else is Arial) • Arbitrary object names are bold to indicate these could change depending on what you name your variables. • Referenced data is provided on my personal website: www.ualberta.ca/~lkgray • Please contact me to obtain permission to redistribute content outside of the workshop attendees. consulting.lkg@gmail.com

  6. Introduction to R Unit 1: Getting Started in R

  7. R Project Website https://cran.r-project.org/index.html

  8. R In It’s simplest form…. A calculator • Open R Workspace and enter the following code into the Console window – What happens? Working with vectors: Working with numbers: Working with tables & matrices: 2 + 3 X =c( 1,4,3,5,7 ) K =as.data.frame(cbind( X,Y, A = 2 + 3 Y =c( 5,7,9,4,8 ) Z )) A mean( X ) X = X * 10 sd( X ) a (oops, R is case sensitive) K (oops, nothing happened?) X * 10 B =7 K $ X = K $ X * 10 Z = Y + 3 A + B t( K ) Z C = A + B plot( K ) boxplot( X,Y,Z ) C t.test( X,Y ) t.test( X,Z )

  9. Script files (1 st thing to set up) • #1 Feature – SAVABLE! • This means you can come back to your script files and re-run your code without having to type. • Always have a record of what you have done • Modifications are easy to execute • Get into the habit of creating or opening a script file being the first thing you do when you open R.

  10. Working Directory (2 nd thing to set up) • Keeps all your work organized

  11. Working Directory (2 nd thing to set up)

  12. Tell R where to look Working Directory (2 nd thing to set up) setwd (“ File path ”) Recommended for this workshop • Ensure forward slashes “/” are used without “+”

  13. The most powerful aspect of R…. Packages! • R is an open-source platform – open contributions (peer reviewed) • Most software you have to wait years for the new and latest tests and models to be incorporated into the software you purchased – BUT with R most new techniques and updates are generally available within months • Also there are a TON of subject matter specific packages available (see Appendix 1 in your workbook for flow packages) • When you install R you get the base package only which allows you to execute many basic statistical tests and graphic commands, but packages are where you get the power • See section 1.4 on how to install R packages (we will do this later today)

  14. R Help Files Description: What the function does The package the function is housed in { } Usage : Default settings for the function options Arguments : Details of what the options control Value : Details of what information is created when the command is executed OR further details of the function options References : Where you can find more information about the function Examples : Code you can copy/paste into your R Console and step through line-by-line to get a See Also : hyperlinks for alternative functions that better idea of what the command is doing may be useful

  15. Mac Tips (Section 1.7) Text Editor • For the most part works the same as Windows • Script file = Text Editor • Working directories = available in drop-down menu • Execute code by highlighting code and pressing Command R • Some differences in function names • choose.files() vs choose.file() • windows() vs. quartz()

  16. RStudio (IDE: Integrated Development Environment) Preferred among programmers, we will use it in this workshop https://www.rstudio.com/

  17. RStudio (IDE: Integrated Development Environment) Preferred among programmers, we will use it in this workshop Script Panel Console Plots/Packages/Help Files Environment/History Panel • Create “Projects” as working directories • Customize environment aesthetics in Tools> Global Options

  18. Introduction to R Unit 2: Data Preparation in R

  19. Object-based programming Saves information so you can use it later e.g. scaler, vector, data table, matrix, ANOVA table, etc. You create this! You name it! Object <-output • When you are naming objects try to keep things simple yet informative (if everything is called data you might get confused). • CAN use “_” and ”.” as well as numbers within your naming conventions, • CANNOT use special symbols (%,&,*,#,!), “,” • CANNOT start an object name with a number.

  20. Object-based programming What you are asking R to do for you e.g. create a new variable, calculate a mean, etc. Object <-output • Output is most often a function() • Functions are also considered objects, BUT they are special objects that accept other arguments to complete the desired action function( data , argument1, argument2)

  21. Ask R: Convert: Objects Classes (Section 2.5) is.vector() as.vector() is.matrix() as.matrix() is.data.frame() as.data.frame() is.list() as.list() Vector – the basic data object, a list of information e.g. data.v =c( 1,2,3,4 ) data.v2 =c( "A","B","C" ) Scaler – a vector of length=1 e.g. A=2 Matrix – a 2-dimensional vector. All columns in a matrix must be numeric and the same length e.g. data.m =matrix( data.v , nrow= 2 , ncol= 2 , byrow= FALSE , dimnames=list(c(" Row1","Row2 "), c(" Col1","Col2 "))) Data Frame – is a general form of a matrix, but in a data frame different columns can have different modes. e.g. x =c( "Adam","Beth","Chris","Danielle" ) # Student names y =c( 78,90,56,49) # Test scores z =c( TRUE,TRUE,TRUE,FALSE ) # Passed? mydata =data.frame( x,y,z ) # make a datatable colnames( mydata )=c(" student","testScore","Passed ") # assign column names mydata ## view data table List – An ordered collection of objects (components). A list allows you to gather a variety of (possibly unrelated) objects under one name e.g. # example of a list with 4 components – a string, a numeric vector, a matrix, and a scaler W = list(name=" RcourseExamples ", mynumbers= data.v , mymatrix= data.m ,myscaler= A ) W ## view list

  22. Ask R: Convert: Object Modes (Section 2.4) is.numeric() as.numeric() is.chracter() as.character() is.factor() as.factor() is.logical() as.logical() • All objects have a data mode which is Investigate data structure: a mutually exclusive classification str() according to the object’s basic structure. • Numeric – a number value with decimal places. • If decimal places are present numeric can default to type integer . • Complex – an imaginary numeric value • Square root of a negative number • Character – a variable with values other than numbers or a single “.” value present • Text string • If R identifies repeating character values character values can be classified as type factor which include an imbedded order known as levels. • Logical – a Boolean value • True or False • Recursive objects (objects that have multiple pieces or perform actions) have modes such as list or function .

  23. Object Modes (Section 2.4) • This decision tree ignores the complex mode (only used if dealing with imaginary numbers)

  24. JasperMigration.csv

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend