beginners’&workshop& · 2015-12-01 · what’s&in&this&workshop! •...
TRANSCRIPT
![Page 2: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/2.jpg)
What is R? • Sta%s%cs package
• General modelling tool
• Data visualisa%on and analysis tool
• Programming language
• Glorified pocket calculator
• “Environment for sta%s%cal compu%ng and graphics” h?p://r4stats.com/ar%cles/popularity/
![Page 3: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/3.jpg)
Why use R?
• Lots of help available
• Free
• Big user base
• Increasingly used for doing science • Jobs!
• CuLng edge and growing func%onality
• If you learn only one new piece of compu%ng soNware aNer Excel, learn R
![Page 4: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/4.jpg)
What’s in this workshop
• Basic interac%on with R
• Where to turn for help
• Moving rapidly to more complex analyses
• Where to learn more
![Page 5: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/5.jpg)
What’s not in this workshop • Advanced programming • See e.g. ?Control, ?"function" and resources (later)
• ‘How do I analyse X?’ • Google (e.g. ‘%me series R’) and resources (later)
• The fundamentals of sta%s%cs • See resources given later, esp. Crawley books
• Working in R environments other than Rstudio (www.rstudio.com)
Default Windows GUI Default Mac GUI R commander Command line
![Page 6: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/6.jpg)
![Page 7: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/7.jpg)
R as a calculator
> 9+2-‐1 [1] 10 > 5*0.5 [1] 2.5 > 27/3 [1] 9 > 9^2 [1] 81 > 9^(1/2) [1] 3 > sqrt(9) [1] 3 > log(5) [1] 1.609438
![Page 8: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/8.jpg)
R help documenta>on
> log(5) [1] 1.609438 Check what the log() func%on is doing (e.g. which base?) > ?log
General informa%on
Package
Arguments and defaults
What those arguments need to be
What’s covered
![Page 9: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/9.jpg)
> log(5) [1] 1.609438 Check what the log() func%on is doing (e.g. which base?) > ?log If you really care
Where it’s come from
Some%mes very useful, some%mes not Run from here or use example(log)
What you get back
Useful link
R help documenta>on
![Page 10: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/10.jpg)
R help documenta>on
> log(5) [1] 1.609438 Check what the log() func%on is doing (e.g. which base?) > ?log
![Page 11: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/11.jpg)
R as a calculator > log(5) [1] 1.609438 Check what the log() func%on is doing (e.g. which base?) > ?log > log(5, base=10) [1] 0.69897 > log10(5) [1] 0.69897 What happens if you get it wrong? > log("Fred") Error in log(“Fred") : non-‐numeric argument to mathema%cal func%on > log func%on (x, base = exp(1)) .Primi%ve("log") So if natural log isn’t ln(5), what is ln used for? > ?ln
![Page 12: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/12.jpg)
R as a calculator
Comparisons > 54 > 45 Greater than [1] TRUE > 2 < 1 Less than [1] FALSE > 15 == 15 Exactly equal [1] TRUE > 50 >= 50 Greater than or equal [1] TRUE > 5 > 1 & 9 <= 15 Are both statements true? [1] TRUE > 24 == 3 | 1 == 1 Is either statement true? [1] TRUE > ?Comparison > ?Syntax
![Page 13: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/13.jpg)
Keeping track of what you’re doing
• Store code in a text file (.R)
• Write in comments #like this
• Run commands a line at a %me • Ctl R (Windows) Ctl Return (Windows) • ⌘↵ (Mac)
• Highlight code and run in the same way
• Run a whole file using the source() func%on
• Navigate history using arrows
![Page 14: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/14.jpg)
Keeping track of what you’re doing
• Try running the first 32 lines one at a %me or in one go
url.show("h?p://is.gd/Rwkshp15")
• Try saving the file somewhere useful
• Try wri%ng some more commented and uncommented lines
• Use R as a web browser to see the file containing this workshop’s code:
• Copy it to a new R script file (.R)
![Page 15: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/15.jpg)
Further sec>ons • Assign values to a variable <-‐
• Create vectors c()
• Simple sta%s%cs
• Extrac%ng bits of variables []
• loop for (var in seq){}
• Data frames read.table(); write.table(); [,]
• Simple plots plot(y~x); pairs(), hist()
• Build linear models lm(y~x); anova()
• Modelling exercise rpart(y~x); randomForest(y~x)
![Page 16: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/16.jpg)
• Sta%s%cs • Crawley Books • Courses
• Masters’ lectures now! • h?ps://www.coursera.org/course/sta%s%cs
Places to go for more informa>on
• h?p://cran.r-‐project.org/web/views/ • Task views
• Specific books • Many online with UoM access e.g. 52 in UseR! series:
h?p://link.springer.com/bookseries/6991 • Data manipula+on with R by Phil Spector very broadly useful
• R programming • R site documents (start with ‘Documents with fewer than 100 pages’) • h?p://cran.r-‐project.org/other-‐docs.html
• Courses • h?ps://www.coursera.org/course/rprog
![Page 17: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/17.jpg)
• Manipula%ng data (summarising, spliLng, etc.) • dplyr , %dyr
• Work with data frames, ±intui%ve, fast • vigne?e("introduc%on", package="dplyr”)
Packages to consider
• Manipula%ng strings • stringr
• Consistent interface • Doesn’t get round the need to use ‘regular expressions’
• Beau%ful plots • ggplot2
• Requires familiarisa%on • Help files weak, but online resources great
• Specifics • bioconductor.org (if necessary), seqinr (bioinforma%cs) • ape (Phylogene%cs) • lmer, nlme (more advanced linear and nonlinear models) • …
![Page 18: Beginners’&workshop& · 2015-12-01 · What’s&in&this&workshop! • Basic!interac%on!with!R! • Where!to!turn!for!help! • Moving!rapidly!to!more!complex!analyses! • Where!to!learn!more!](https://reader033.vdocuments.mx/reader033/viewer/2022050109/5f4703e94bb95626d129ad04/html5/thumbnails/18.jpg)
Places to go for help
• R help list archives h?p://www.r-‐project.org/ > Mailing lists > R-‐help web interface > Searchable archives
• R help documenta%on ? ?? help(package="base") demo() example("func%on") vigne?e()
• R support groups • FLS (FLSRGROUP listerv) or email
[email protected] • Manchester R User group
h?p://www.meetup.com/Manchester-‐R/
• Google • stackoverflow.com (programming) crossvalidated (Stats)