- ST Computer Intensive Statistical Analytics I Appendix: R basics
|
|
- Doreen Stevenson
- 5 years ago
- Views:
Transcription
1 ST appendix - Eric Wolsztynski, UCC p.1/40 - ST Computer Intensive Statistical Analytics I Appendix: Eric Wolsztynski
2 ST appendix - Eric Wolsztynski, UCC p.2/40 What is R? R is a free software environment for statistical computing and graphics In short, R allows to analyse data and write programs R is derived from S, a commercialised statistical solution Visit for resources and documentation The basic R distribution contains about 25 packages Many other packages may be installed (or created)
3 ST appendix - Eric Wolsztynski, UCC p.3/40 R documentation and tutorials Disclaimer: the present guide is only a short, practical introduction to R. Parts of this document use and summarise sections of the Introduction to R manual from the CRAN. Web: huge amount of guides, short and long Starting by the CRAN website is recommended cf. in particular the R manuals page on the CRAN Youtube: 3zWo4sUs&list=PLOU2XLYxmsIK9qQfztXeybpHvru-TrqAP Offline: some really good books (see references)
4 ST appendix - Eric Wolsztynski, UCC p.4/40 Launching R... and quitting R R version ( ) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN Platform: i386-apple-darwin9.8.0/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type license() or licence() for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type contributors() for more information and citation() on how to cite R or R packages in publications. Type demo() for some demos, help() for on-line help, or help.start() for an HTML browser interface to help. Type q() to quit R.
5 ST appendix - Eric Wolsztynski, UCC p.5/40 Instructing R One can use the R console (limited) or the R editor Save and open R scripts using the editor (extension file.r) Editor: select and run a block of instructions (lines) at once using Ctrl-R (Windows) or Cmd-Enter (Mac) Other editors (providing coloured keywords, highlighting, etc.) are available for R (TinnR, Emacs, etc.)
6 ST appendix - Eric Wolsztynski, UCC p.6/40 Getting help for and from R Web search (using keyword cran often helps) Browse packages (CRAN): The R Reference Index contains all help files of the R standard and recommended packages in printable form R> help.start() brings up the html help page?name opens up the help on a specific function. Example: R>?plot Browse the See Also section of R help pages
7 ST appendix - Eric Wolsztynski, UCC p.7/40 R syntax and data handling R syntax and data handling
8 ST appendix - Eric Wolsztynski, UCC p.8/40 R syntax and data handling Some short examples to run in the console window R is case sensitive R> a = 2 R> a (displays the value a = 2) R> A (returns an error: A is not a declared variable) Use R as a calculator: R> 3+5*2; exp(log(10)); 2/0 Load a specific library (containing functions and data): R> library(kernsmooth) Load an existing dataset: R> data(airpassengers) R> plot(airpassengers)
9 ST appendix - Eric Wolsztynski, UCC p.9/40 R syntax and data handling General philosophy In R, statistical analysis is usually carried out incrementally (i.e. in steps) Intermediate results are stored in objects that are re-used in further steps The displayed output of a function (e.g. linear regression) often remains succinct, while the more detailed result is stored in an object
10 ST appendix - Eric Wolsztynski, UCC p.10/40 R syntax and data handling Basics of R syntax Assignment: use either = or <- Without assignment, a value is printed and then lost Standard mathematical operators: +,, /, log, exp, etc. Standard logical operators: <, <=,! (NOT), == (equality) Comments must begin with # R objects have a type, which is a named data structure, such as logical, integer, real, vector, list, array, or a more elaborate structure Example: R> a = 2; is.real(a); is.logical(a); is.list(a)
11 ST appendix - Eric Wolsztynski, UCC p.11/40 R syntax and data handling R object types Vectors are uni-dimensional ordered collection of numbers Arrays (including matrices) are multi-dimensional vectors (M[i,j]) Factors are used for categorical data (for use e.g. in GLM) Lists are vectors of elements of different types Data frames are matrix-like structures containing elements of different types Functions implement re-usable sets of instructions from input arguments. Usage: output = function(argument)
12 ST appendix - Eric Wolsztynski, UCC p.12/40 R syntax and data handling R object classes All R objects also have a class Vectors are usually numeric, complex, logical, character or list: try e.g. class(sqrt(-17+0i)) Other possible classes are matrix, array, factor and data.frame It is possible to create new classes, usually as data.frames This allows object-oriented programming with R, like in Java or C++ Some generic R functions are class-specific, such as plot and summary: they behave differently in function of the class of their argument
13 ST appendix - Eric Wolsztynski, UCC p.13/40 R syntax and data handling Vector operations (1) x = c(0.1, 2, 4.3, 3.1, 5) Synopsis: vector[index] x[2] then returns the second value in that vector x[1:3] returns the first three values x[-(1:3)] gives all but the first three elements x[x>3] selects the subset of values in x greater than 3 N = length(x) stores the length of x For assignment, the assigned value must be either a single value or of same length as the index vector: x[is.na(x)] = 0 x[x<0] = -x[x<0] (equivalent to x = abs(x))
14 ST appendix - Eric Wolsztynski, UCC p.14/40 R syntax and data handling Vector operations (2) Standard arithmetic applies to vectors of equal length, e.g.: v <- 2*x + y + 1 sum((x-mean(x))ˆ2)/(length(x)-1) Regular sequences can be generated easily: s1 = seq(-5, 5, by=.2) s2 = seq(from=-5, length=51, by=.2) xx = rep(x, times = 2) xxx = rep(x, each = 3) Vectors may also contain characters or strings: fruit <- c(5, 10, 4) names(fruit) <- c( orange, banana, apple ) lunch <- fruit[c( apple, orange )]
15 ST appendix - Eric Wolsztynski, UCC p.15/40 R syntax and data handling Matrix operations (1) Create a vector x = c(1, 2, 3, 4, 5, 6, 7, 8, 9) Now make it a 3 3 matrix: matrix(x, ncol = 3) If we prefer arranging by rows: M = matrix(x, ncol = 3, byrow = TRUE) The matrix now has dimensions: dim(m); ncol(m); nrow(m) Note the difference in classes: class(x); class(m) Access any of the matrix components: M[2,3]; M[,1]; M[2,]; M[2, c(1:2)] cbind() and rbind() also produce matrices: cbind(c(1,2,3),c(4,5,6))
16 ST appendix - Eric Wolsztynski, UCC p.16/40 R syntax and data handling Matrix operations (2) Transpose matrices: t(m) or aperm(m, c(2,1)) diag(m), det(m), svd(m) (Single Value Decomposition) Matrix arithmetics (on compatible matrices A, B and vector x): Element-by-element product: A * B (if A and B are square) Matrix product: A %*% B Quadratic form using vector x: x %*% A %*% x crossprod(m, x) is the same as t(x) %*% y
17 ST appendix - Eric Wolsztynski, UCC p.17/40 R syntax and data handling Matrix operations (3) Solving linear equation Ax + b = 0: Given A and b such that b = A %*% x, solve(a,b) returns x (solution given up to some accuracy loss) solve(a) returns the inverse of a matrix x <- solve(a) %*% b is inefficient and potentially unstable eigen(s) computes eigenvalues and eigenvectors of symmetric matrix S Note that x %*% x is ambiguous (with x a column-vector). The best is to use crossprod(x) for x x x %o% x for x x (the outer product for an array)
18 ST appendix - Eric Wolsztynski, UCC p.18/40 R syntax and data handling Array operations Make a vector into an array using array(vector, dim=...): h = seq(1, 24, by=1) Z <- array(h, dim=c(3,4,2)) Z[1,1,1]; Z[1,2,2] Arithmetic operations on arrays are carried out element-by-element and respect constraints of dimensions: D <- 2*A*B + C + 1 works if A, B and C are similar arrays Transpose should be done using aperm Other array-specific operators exist, such as the outer product There exist some more tricky issues with arrays
19 ST appendix - Eric Wolsztynski, UCC p.19/40 R syntax and data handling Lists Synopsis: Lst <- list(name 1=object 1,..., name m=object m) Lst[[index]] # to access its components Create a list: Lst <- list(name= Fred, wife= Mary, no.children=3, child.ages=c(4,7,9)) In this example, Lst[[2]] = "Mary" and Lst[[4]][1] = 4 Components may also be accessed by their name using $, e.g. Lst$name = Fred or Lst$child.ages[1] = 4 length(lst) gives the number of top level components
20 ST appendix - Eric Wolsztynski, UCC p.20/40 R syntax and data handling Data frames A data frame is a list of class data.frame It can be seen as a matrix with columns of possibly different types/classes Character vectors are coerced to factors Vector components must all have equal length Matrix structures must all have equal row size Synopsis: D <- data.frame(name 1=arg 1,..., name m=arg m) D$name 1 # accesses its first component
21 ST appendix - Eric Wolsztynski, UCC p.21/40 R syntax and data handling Data frames Example: D <- data.frame(u=homes, v=incomes, w=children) D$w # displays values of vector children A list whose components conform to the restrictions of a data frame may be coerced into one using as.data.frame() read.table() reads in a table of values from an input file and returns an object of type data.frame: D = read.table(some csv file) attach() loads the components of a data frame in the local environment (i.e. memory), which can thus be used as separate variables. E.g. if D contains components u, v and w: attach(d) u+v-w
22 ST appendix - Eric Wolsztynski, UCC p.22/40 R syntax and data handling Data frames In this example, following instruction attach(d), any assignment to u (such as u = 3 or u = v+w) will change the value of u in the local environment (memory) but not in the original data file, nor even in the data frame D To make a change in the data frame itself, one needs to assign a value to the component itself, i.e. D$u: D$u = new vector The new value of this component will not be visible until the data frame is detached and attached again detach() removes the components of the input data frame from the local environment detach() does not remove the data frame from the memory
23 ST appendix - Eric Wolsztynski, UCC p.23/40 R syntax and data handling Formulae symbol example meaning y x y x1 y = ax 1 + b + y x1 + x2 y = ax 1 + bx 2 + c (include variable) + 0 y x1 + 0 y = ax 1 (exclude intercept) - 1 y x1-1 y = ax 1 (exclude intercept also) : y x1 : x2 include interaction between x 1 and x 2 * y x1 * x2 include these variables and their interaction (equiv. x1 + x2 + x1:x2) / y x1 / x2 nesting: include x 2 nested within x 1 ˆ y (x1 + x2)ˆ3 include these variables and all interactions up to 3 way I y I(x1*x2) as is: specify a new variable consisting of the product x 1 x 2 poly y poly(x1,3) polynomial regression: orthogonal polynomials
24 ST appendix - Eric Wolsztynski, UCC p.24/40 Files and plots Files and plots
25 ST appendix - Eric Wolsztynski, UCC p.25/40 Files and plots Reading data from files read.table() reads in a file in table format and returns a data frame object read.csv(), a variant of read.table() is particularly useful for reading CSV files scan() reads data from the console or from an input file into a vector or list scan() is often called within matrix() when uploading data: X <- matrix(scan( light.dat ), ncol=5, byrow=true) readlines() reads lines (all or some) of an input file
26 ST appendix - Eric Wolsztynski, UCC p.26/40 Files and plots Writing data to files write.table() creates a file and writes the data frame content in it write.csv(), a variant of write.table() creates a CSV file More advanced: file may be used to create a connection (or file), in a C-like approach; see?connections and examples within for more information
27 ST appendix - Eric Wolsztynski, UCC p.27/40 Files and plots Plot?plot provides information on the main plotting device Synopsis: plot(x, y,...), where y may be omitted if x is an appropriate structure... are optional arguments (graphical parameters, see?par): main - overall plot title type - type of plot (type="l" for line, "p" for points, etc.) xlab, ylab - x- and y-axis titles xlim, ylim - x- and y-axis limits col - plot colour (use strings ("red"), or else integers (2)) cf.?plot for more details
28 ST appendix - Eric Wolsztynski, UCC p.28/40 Files and plots Some useful tips x11() may be called before plot() to create a new window par() is used to organise (prepare) the plotting window: par(mfrow=c(2,3)) # 2 lines of 3 plots in window Look after line width or point size (respectively lwd and cex), main title, axis labels, etc.: x11() # opens new window par(pty= s ) # makes plot window square plot(x, y, main= plot of sales against investment, xlab= investment, ylab= sales, type= p, cex=2) or plot(x, y, main= plot of sales against investment, xlab= investment, ylab= sales, type= l, lwd=2)
29 ST appendix - Eric Wolsztynski, UCC p.29/40 Files and plots Plot more in the same window points(x, y,...) adds points on existing plot Usage of points() is very similar to that of plot() abline() plots a line: abline(h=3) # horizontal line at y=3 abline(v=2) # vertical line at x=2 abline(a=1,b=4) # draws line 4x+1 par(new=true) keeps current plot and plotting window, while allowing a new call to plot (which will not clean the window) par(new=true) resets axis scales and other settings!!
30 ST appendix - Eric Wolsztynski, UCC p.30/40 Files and plots More plots plot() behaves specifically to the class of its input argument R offers many other plotting solutions See e.g. and hist() draws histograms, density() kernel density estimates boxplot() plots boxplots persp(x, y, z,...) draws perspective plots of surfaces contour(x, y, z,...) creates a contour plot image(x,...) displays a grayscale/colored image
31 ST appendix - Eric Wolsztynski, UCC p.31/40 Files and plots An example with mathematical annotations x<-seq(-10,10,length=400) [from addictedtor.free.fr] y1<-dnorm(x); y2<-dnorm(x,m=3) par(mar=c(5,4,2,1)) plot(x, y2, xlim=c(-3,8), type="n", xlab=quote(z==frac(mu[1]-mu[2], sigma/sqrt(n))), ylab="density") polygon(c(1.96,1.96,x[240:400],10), c(0,dnorm(1.96,m=3),y2[240:400],0), col="grey80", lty=0) lines(x, y2); lines(x, y1) polygon(c(-1.96,-1.96,x[161:1],-10), c(0,dnorm(-1.96,m=0), y1[161:1],0), col="grey30", lty=0) polygon(c(1.96, 1.96, x[240:400], 10), c(0,dnorm(1.96,m=0), y1[240:400],0), col="grey30") legend(4.2,.4, fill=c("grey80","grey30"), legend=expression(p(abs(z)>1.96, H[1])==0.85, P(abs(Z)>1.96,H[0])==0.05), bty="n") text(0,.2, quote(h[0]:~~mu[1]==mu[2])) text(3,.2, quote(h[1]:~~mu[1]==mu[2]+delta))
32 ST appendix - Eric Wolsztynski, UCC p.32/40 Files and plots An example with mathematical annotations Density H 0 : µ 1 = µ 2 H 1 : µ 1 = µ 2 + δ P(Z > 1.96, H 1) = 0.85 P(Z > 1.96, H 0) = Z = µ 1 µ 2 σ n
33 ST appendix - Eric Wolsztynski, UCC p.33/40 Files and plots Plotting to files R allows copy-pasting figures (easier on Windows) jpg() and pdf() can be used to plot directly to a file: pdf(../slides/figs/ecdf plot.pdf ) Make sure to have your plot well calibrated before plotting to a file In particular, double-check the output figure size and readibility
34 ST appendix - Eric Wolsztynski, UCC p.34/40 R programming R programming
35 ST appendix - Eric Wolsztynski, UCC p.35/40 R programming Some advice R programming consists in writing elaborate R instructions in an R script, which can then be re-used at a later stage It is usually better to do it in an R-dedicated editor It is strongly recommended to keep your code clear and tidy Indenting blocks of instructions is quite often time-saving Any code should also be annotated by comments, using # Write code as if for someone else: anyone will struggle to understand his/her own code after some time, if this code is not well commented and organised
36 ST appendix - Eric Wolsztynski, UCC p.36/40 R programming If if is used as follows: if (test) expr 1 else expr 2 R> if(0) print( un ) else print( deux ) R> if(0) print( un ) else {print( deux ); a=3; print(a)} An extended use with large grouped instructions is as follows: if(test){ expr 1 expr 2... } else { expr 3 expr 4... }
37 ST appendix - Eric Wolsztynski, UCC p.37/40 R programming Loops The for loop: for (name in expr 1) expr 2 R> for (i in 1:10) { print(i) } R> x=0; bag=c(1,2,5); for (i in bag) { x=x+i; print(x) } Another example, scanning matrix M: for(i in 1:nrow(M)){ for(j in 1:ncol(M)){ print(m[i,j]) } } Other loops: repeat expr and while (condition) expr break() terminates any loop (must be used in repeat): R> i=10; repeat {i=i-1; if(i==0) break()} next() skips to the next loop cycle
38 ST appendix - Eric Wolsztynski, UCC p.38/40 R programming Functions (1) R functions define a sequence of instructions to be re-used Synopsis: name <- function(arg 1, arg 2,...) expression A call to the function is then name(expr 1, expr 2,...) Some simple examples: R> helloworld <- function(){ print( Hello World! ) } R> helloworld() # displays "Hello World!" R> plusone <- function(a){ return(a+1) } R> b = 2; c = plusone(b); c # displays 3
39 ST appendix - Eric Wolsztynski, UCC p.39/40 R programming Functions (2) It is convenient to write functions in a separate.r file Such definition files can be loaded at any point by source() Example: source( bin/myfuns.r ) loads all functions defined within myfuns.r in the R environment Function arguments can be given a default value: fun1 <- function(data, graph=true, limit=20) {... } Calls to the newly defined function fun1 may then be: ans <- fun1(d) ans <- fun1(d, limit=10)
40 ST appendix - Eric Wolsztynski, UCC p.40/40 R programming Functions (3) Always be cautious of the scope of existing variables! f <- function(x) { y <- 2*x print(x) print(y) print(z) } In this function, x is a formal parameter (defined as a function argument) y is a local variable (defined within the function body) z is a free variable (with a value defined elsewhere) Also, avoid using existing names to define new local variables!
Matrix algebra. Basics
Matrix.1 Matrix algebra Matrix algebra is very prevalently used in Statistics because it provides representations of models and computations in a much simpler manner than without its use. The purpose of
More informationAn introduction to R 1 / 29
An introduction to R 1 / 29 What is R? R is an integrated suite of software facilities for data manipulation, calculation and graphical display. Among other things it has: an effective data handling and
More informationMails : ; Document version: 14/09/12
Mails : leslie.regad@univ-paris-diderot.fr ; gaelle.lelandais@univ-paris-diderot.fr Document version: 14/09/12 A freely available language and environment Statistical computing Graphics Supplementary
More informationExtremely short introduction to R Jean-Yves Sgro Feb 20, 2018
Extremely short introduction to R Jean-Yves Sgro Feb 20, 2018 Contents 1 Suggested ahead activities 1 2 Introduction to R 2 2.1 Learning Objectives......................................... 2 3 Starting
More informationThis document is designed to get you started with using R
An Introduction to R This document is designed to get you started with using R We will learn about what R is and its advantages over other statistics packages the basics of R plotting data and graphs What
More informationStat 579: Objects in R Vectors
Stat 579: Objects in R Vectors Ranjan Maitra 2220 Snedecor Hall Department of Statistics Iowa State University. Phone: 515-294-7757 maitra@iastate.edu, 1/23 Logical Vectors I R allows manipulation of logical
More informationA Handbook of Statistical Analyses Using R. Brian S. Everitt and Torsten Hothorn
A Handbook of Statistical Analyses Using R Brian S. Everitt and Torsten Hothorn CHAPTER 7 Density Estimation: Erupting Geysers and Star Clusters 7.1 Introduction 7.2 Density Estimation The three kernel
More informationR version ( ) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN
Math 3070 1. Treibergs County Data: Histograms with variable Class Widths. Name: Example June 1, 2011 Data File Used in this Analysis: # Math 3070-1 County populations Treibergs # # Source: C Goodall,
More informationStatistical Data Analysis: R Tutorial
1 August 29, 2012 Statistical Data Analysis: R Tutorial Dr A. J. Bevan, Contents 1 Getting started 1 2 Basic calculations 2 3 More advanced calulations 3 4 Plotting data 4 5 The quantmod package 5 1 Getting
More informationIntroduction to R 21/11/2016
Introduction to R 21/11/2016 C3BI Vincent Guillemot & Anne Biton R: presentation and installation Where? https://cran.r-project.org/ How to install and use it? Follow the steps: you don t need advanced
More informationGS Analysis of Microarray Data
GS01 0163 Analysis of Microarray Data Keith Baggerly and Kevin Coombes Section of Bioinformatics Department of Biostatistics and Applied Mathematics UT M. D. Anderson Cancer Center kabagg@mdanderson.org
More informationStatistical Programming Camp: An Introduction to R
Statistical Programming Camp: An Introduction to R Handout 3: Data Manipulation and Summarizing Univariate Data Fox Chapters 1-3, 7-8 In this handout, we cover the following new materials: ˆ Using logical
More informationThe nor1mix Package. August 3, 2006
The nor1mix Package August 3, 2006 Title Normal (1-d) Mixture Models (S3 Classes and Methods) Version 1.0-6 Date 2006-08-02 Author: Martin Mächler Maintainer Martin Maechler
More informationSTA 250: Statistics Lab 1
STA 250: Statistics Lab 1 This lab work is intended to be an introduction to the software R. What follows is a description of the basic functionalities of R, along with a series of tasks that ou d have
More informationIntroduction to R. UCLA Statistical Consulting Center R Bootcamp. Irina Kukuyeva September 20, 2010
UCLA Statistical Consulting Center R Bootcamp Irina Kukuyeva ikukuyeva@stat.ucla.edu September 20, 2010 Outline 1 Introduction 2 Preliminaries 3 Working with Vectors and Matrices 4 Data Sets in R 5 Overview
More informationStatistical Software Camp: Introduction to R
Statistical Software Camp: Introduction to R Day 1 August 24, 2009 1 Introduction 1.1 Why Use R? ˆ Widely-used (ever-increasingly so in political science) ˆ Free ˆ Power and flexibility ˆ Graphical capabilities
More informationThe nor1mix Package. June 12, 2007
The nor1mix Package June 12, 2007 Title Normal (1-d) Mixture Models (S3 Classes and Methods) Version 1.0-7 Date 2007-03-15 Author Martin Mächler Maintainer Martin Maechler
More informationR Primer for Introduction to Mathematical Statistics 8th Edition Joseph W. McKean
R Primer for Introduction to Mathematical Statistics 8th Edition Joseph W. McKean Copyright 2017 by Joseph W. McKean at Western Michigan University. All rights reserved. Reproduction or translation of
More informationIntroduction to R Benedikt Brors Dept. Intelligent Bioinformatics Systems German Cancer Research Center
Introduction to R Benedikt Brors Dept. Intelligent Bioinformatics Systems German Cancer Research Center What is R? R is a statistical computing environment with graphics capabilites It is fully scriptable
More informationIST 3108 Data Analysis and Graphics Using R Week 9
IST 3108 Data Analysis and Graphics Using R Week 9 Engin YILDIZTEPE, Ph.D 2017-Spring Introduction to Graphics >y plot (y) In R, pictures are presented in the active graphical device or window.
More informationR is a programming language of a higher-level Constantly increasing amount of packages (new research) Free of charge Website:
Introduction to R R R is a programming language of a higher-level Constantly increasing amount of packages (new research) Free of charge Website: http://www.r-project.org/ Code Editor: http://rstudio.org/
More informationSTAT 540: R: Sections Arithmetic in R. Will perform these on vectors, matrices, arrays as well as on ordinary numbers
Arithmetic in R R can be viewed as a very fancy calculator Can perform the ordinary mathematical operations: + - * / ˆ Will perform these on vectors, matrices, arrays as well as on ordinary numbers With
More informationThe Very Basics of the R Interpreter
Chapter 2 The Very Basics of the R Interpreter OK, the computer is fired up. We have R installed. It is time to get started. 1. Start R by double-clicking on the R desktop icon. 2. Alternatively, open
More informationAz R adatelemzési nyelv
Az R adatelemzési nyelv alapjai II. Egészségügyi informatika és biostatisztika Gézsi András gezsi@mit.bme.hu Functions Functions Functions do things with data Input : function arguments (0,1,2, ) Output
More informationR: BASICS. Andrea Passarella. (plus some additions by Salvatore Ruggieri)
R: BASICS Andrea Passarella (plus some additions by Salvatore Ruggieri) BASIC CONCEPTS R is an interpreted scripting language Types of interactions Console based Input commands into the console Examine
More informationIntroduction to R. Hao Helen Zhang. Fall Department of Mathematics University of Arizona
Department of Mathematics University of Arizona hzhang@math.aricona.edu Fall 2019 What is R R is the most powerful and most widely used statistical software Video: A language and environment for statistical
More informationR Tutorial. Anup Aprem September 13, 2016
R Tutorial Anup Aprem aaprem@ece.ubc.ca September 13, 2016 Installation Installing R: https://www.r-project.org/ Recommended to also install R Studio: https://www.rstudio.com/ Vectors Basic element is
More informationA (very) short introduction to R
A (very) short introduction to R Paul Torfs & Claudia Brauer Hydrology and Quantitative Water Management Group, Wageningen University, The Netherlands 4 August 2017 1 Introduction R is a powerful language
More informationR (and S, and S-Plus, another program based on S) is an interactive, interpretive, function language.
R R (and S, and S-Plus, another program based on S) is an interactive, interpretive, function language. Available on Linux, Unix, Mac, and MS Windows systems. Documentation exists in several volumes, and
More informationTutorial (Unix Version)
Tutorial (Unix Version) S.f.Statistik, ETHZ February 26, 2010 Introduction This tutorial will give you some basic knowledge about working with R. It will also help you to familiarize with an environment
More informationPractical 2: Plotting
Practical 2: Plotting Complete this sheet as you work through it. If you run into problems, then ask for help - don t skip sections! Open Rstudio and store any files you download or create in a directory
More informationIntroduction to R, Github and Gitlab
Introduction to R, Github and Gitlab 27/11/2018 Pierpaolo Maisano Delser mail: maisanop@tcd.ie ; pm604@cam.ac.uk Outline: Why R? What can R do? Basic commands and operations Data analysis in R Github and
More informationStatistical Programming with R
Statistical Programming with R Lecture 9: Basic graphics in R Part 2 Bisher M. Iqelan biqelan@iugaza.edu.ps Department of Mathematics, Faculty of Science, The Islamic University of Gaza 2017-2018, Semester
More informationA (very) short introduction to R
A (very) short introduction to R Paul Torfs & Claudia Brauer Hydrology and Quantitative Water Management Group Wageningen University, The Netherlands 1 Introduction 16 April 2012 R is a powerful language
More informationA (very) short introduction to R
A (very) short introduction to R Paul Torfs & Claudia Brauer Hydrology and Quantitative Water Management Group Wageningen University, The Netherlands 1 Introduction 3 March 2014 R is a powerful language
More informationA Brief Introduction to R
A Brief Introduction to R Babak Shahbaba Department of Statistics, University of California, Irvine, USA Chapter 1 Introduction to R 1.1 Installing R To install R, follow these steps: 1. Go to http://www.r-project.org/.
More informationTypes of Plotting Functions. Managing graphics devices. Further High-level Plotting Functions. The plot() Function
3 / 23 5 / 23 Outline The R Statistical Environment R Graphics Peter Dalgaard Department of Biostatistics University of Copenhagen January 16, 29 1 / 23 2 / 23 Overview Standard R Graphics The standard
More informationGetting Started with R
Getting Started with R STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Tool Some of you may have used
More informationDSCI 325: Handout 18 Introduction to Graphics in R
DSCI 325: Handout 18 Introduction to Graphics in R Spring 2016 This handout will provide an introduction to creating graphics in R. One big advantage that R has over SAS (and over several other statistical
More informationIntroduction to MATLAB Programming
July 23, 2017 Appendix D Introduction to MATLAB Programming Contents D.1 Getting Started............................. 2 D.2 Basic m-file................................ 3 D.2.1 Printing..................................
More informationA (very) brief introduction to R
A (very) brief introduction to R You typically start R at the command line prompt in a command line interface (CLI) mode. It is not a graphical user interface (GUI) although there are some efforts to produce
More informationControl Flow Structures
Control Flow Structures STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Expressions 2 Expressions R code
More informationTutorial (Unix Version)
Tutorial (Unix Version) S.f.Statistik, ETHZ April 11, 2011 Introduction This tutorial will give you some basic knowledge about working with R. It will also help you to familiarize with an environment to
More informationVectors and Matrices Flow Control Plotting Functions Simulating Systems Installing Packages Getting Help Assignments. R Tutorial
R Tutorial Anup Aprem aaprem@ece.ubc.ca September 14, 2017 Installation Installing R: https://www.r-project.org/ Recommended to also install R Studio: https://www.rstudio.com/ Vectors Basic element is
More informationINTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX
INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar
More informationAn Introduction to R Graphics with examples
An Introduction to R Graphics with examples Feng Li November 18, 2008 1 R graphics system A picture is worth a thousand words! The R graphics system can be broken into four distinct levels: graphics packages;
More informationAdvanced Econometric Methods EMET3011/8014
Advanced Econometric Methods EMET3011/8014 Lecture 2 John Stachurski Semester 1, 2011 Announcements Missed first lecture? See www.johnstachurski.net/emet Weekly download of course notes First computer
More informationPackage qrfactor. February 20, 2015
Type Package Package qrfactor February 20, 2015 Title Simultaneous simulation of Q and R mode factor analyses with Spatial data Version 1.4 Date 2014-01-02 Author George Owusu Maintainer
More informationStatistical Programming with R
(connorharris@college.harvard.edu) CS50, Harvard University October 27, 2015 If you want to follow along with the demos, download R at cran.r-project.org or from your Linux package manager What is R? Programming
More informationprogramming R: Functions and Methods
programming R: Functions and Methods Adrian Waddell University of Waterloo Departement of Statistics and Actuarial Science September 8, 2010 About these Slides These slides were written on behalf of the
More informationLAB #1: DESCRIPTIVE STATISTICS WITH R
NAVAL POSTGRADUATE SCHOOL LAB #1: DESCRIPTIVE STATISTICS WITH R Statistics (OA3102) Lab #1: Descriptive Statistics with R Goal: Introduce students to various R commands for descriptive statistics. Lab
More informationIntroduction to R. Biostatistics 615/815 Lecture 23
Introduction to R Biostatistics 615/815 Lecture 23 So far We have been working with C Strongly typed language Variable and function types set explicitly Functional language Programs are a collection of
More informationII.Matrix. Creates matrix, takes a vector argument and turns it into a matrix matrix(data, nrow, ncol, byrow = F)
II.Matrix A matrix is a two dimensional array, it consists of elements of the same type and displayed in rectangular form. The first index denotes the row; the second index denotes the column of the specified
More informationSTATISTICAL LABORATORY, April 30th, 2010 BIVARIATE PROBABILITY DISTRIBUTIONS
STATISTICAL LABORATORY, April 3th, 21 BIVARIATE PROBABILITY DISTRIBUTIONS Mario Romanazzi 1 MULTINOMIAL DISTRIBUTION Ex1 Three players play 1 independent rounds of a game, and each player has probability
More informationIntroduction to MATLAB
CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical
More informationPackage munfold. R topics documented: February 8, Type Package. Title Metric Unfolding. Version Date Author Martin Elff
Package munfold February 8, 2016 Type Package Title Metric Unfolding Version 0.3.5 Date 2016-02-08 Author Martin Elff Maintainer Martin Elff Description Multidimensional unfolding using
More informationR Short Course Session 1
R Short Course Session 1 Daniel Zhao, PhD Sixia Chen, PhD Department of Biostatistics and Epidemiology College of Public Health, OUHSC 10/23/2015 Outline Overview of the 5 sessions Pre-requisite requirements
More informationPlotting: An Iterative Process
Plotting: An Iterative Process Plotting is an iterative process. First we find a way to represent the data that focusses on the important aspects of the data. What is considered an important aspect may
More informationPackage EnQuireR. R topics documented: February 19, Type Package Title A package dedicated to questionnaires Version 0.
Type Package Title A package dedicated to questionnaires Version 0.10 Date 2009-06-10 Package EnQuireR February 19, 2015 Author Fournier Gwenaelle, Cadoret Marine, Fournier Olivier, Le Poder Francois,
More informationPractice for Learning R and Learning Latex
Practice for Learning R and Learning Latex Jennifer Pan August, 2011 Latex Environments A) Try to create the following equations: 1. 5+6 α = β2 2. P r( 1.96 Z 1.96) = 0.95 ( ) ( ) sy 1 r 2 3. ˆβx = r xy
More informationDr. Junchao Xia Center of Biophysics and Computational Biology. Fall /6/ /13
BIO5312 Biostatistics R Session 02: Graph Plots in R Dr. Junchao Xia Center of Biophysics and Computational Biology Fall 2016 9/6/2016 1 /13 Graphic Methods Graphic methods of displaying data give a quick
More informationTransform and Tidy (Wrangle) Data with R - Required Read Bojan Duric
Transform and Tidy (Wrangle) Data with R - Required Read Bojan Duric This Notebook is selection of A Very (short) Introduction to R by Paul Torfs & Claudia Brauer and R for Data Scince " by Hadley Wickham
More informationIntro to R Graphics Center for Social Science Computation and Research, 2010 Stephanie Lee, Dept of Sociology, University of Washington
Intro to R Graphics Center for Social Science Computation and Research, 2010 Stephanie Lee, Dept of Sociology, University of Washington Class Outline - The R Environment and Graphics Engine - Basic Graphs
More informationShort Introduction to R
Short Introduction to R Paulino Pérez 1 José Crossa 2 1 ColPos-México 2 CIMMyT-México June, 2015. CIMMYT, México-SAGPDB Short Introduction to R 1/51 Contents 1 Introduction 2 Simple objects 3 User defined
More informationINTRODUCTION TO R. Basic Graphics
INTRODUCTION TO R Basic Graphics Graphics in R Create plots with code Replication and modification easy Reproducibility! graphics package ggplot2, ggvis, lattice graphics package Many functions plot()
More informationWhat is MATLAB and howtostart it up?
MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix
More informationBasic R Part 1. Boyce Thompson Institute for Plant Research Tower Road Ithaca, New York U.S.A. by Aureliano Bombarely Gomez
Basic R Part 1 Boyce Thompson Institute for Plant Research Tower Road Ithaca, New York 14853-1801 U.S.A. by Aureliano Bombarely Gomez A Brief Introduction to R: 1. What is R? 2. Software and documentation.
More informationIntroduction to R. Course in Practical Analysis of Microarray Data Computational Exercises
Introduction to R Course in Practical Analysis of Microarray Data Computational Exercises 2010 March 22-26, Technischen Universität München Amin Moghaddasi, Kurt Fellenberg 1. Installing R. Check whether
More informationR syntax guide. Richard Gonzalez Psychology 613. August 27, 2015
R syntax guide Richard Gonzalez Psychology 613 August 27, 2015 This handout will help you get started with R syntax. There are obviously many details that I cannot cover in these short notes but these
More informationLab 1 Introduction to R
Lab 1 Introduction to R Date: August 23, 2011 Assignment and Report Due Date: August 30, 2011 Goal: The purpose of this lab is to get R running on your machines and to get you familiar with the basics
More informationBasic R Part 1 BTI Plant Bioinformatics Course
Basic R Part 1 BTI Plant Bioinformatics Course Spring 2013 Sol Genomics Network Boyce Thompson Institute for Plant Research by Jeremy D. Edwards What is R? Statistical programming language Derived from
More informationPackage fso. February 19, 2015
Version 2.0-1 Date 2013-02-26 Title Fuzzy Set Ordination Package fso February 19, 2015 Author David W. Roberts Maintainer David W. Roberts Description Fuzzy
More informationLAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT
NAVAL POSTGRADUATE SCHOOL LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT Statistics (OA3102) Lab #2: Sampling, Sampling Distributions, and the Central Limit Theorem Goal: Use R to demonstrate sampling
More informationGetting Started with DADiSP
Section 1: Welcome to DADiSP Getting Started with DADiSP This guide is designed to introduce you to the DADiSP environment. It gives you the opportunity to build and manipulate your own sample Worksheets
More informationQuick R Tutorial for Beginners
Quick R Tutorial for Beginners Version 0.3 2015-12-3 Rintaro Saito, University of California San Diego Haruo Suzuki, Keio University 0. Introduction R is one of the best languages to perform statistical
More informationContinuous-time stochastic simulation of epidemics in R
Continuous-time stochastic simulation of epidemics in R Ben Bolker May 16, 2005 1 Introduction/basic code Using the Gillespie algorithm, which assumes that all the possible events that can occur (death
More informationGraphics #1. R Graphics Fundamentals & Scatter Plots
Graphics #1. R Graphics Fundamentals & Scatter Plots In this lab, you will learn how to generate customized publication-quality graphs in R. Working with R graphics can be done as a stepwise process. Rather
More informationR Graphics. Feng Li School of Statistics and Mathematics Central University of Finance and Economics
R Graphics Feng Li feng.li@cufe.edu.cn School of Statistics and Mathematics Central University of Finance and Economics Revised on June 2, 2015 Today we are going to learn... 1 Basic R Graphical System
More informationGraphics in R STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley
Graphics in R STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Base Graphics 2 Graphics in R Traditional
More informationMatlab Tutorial, CDS
29 September 2006 Arrays Built-in variables Outline Operations Linear algebra Polynomials Scripts and data management Help: command window Elisa (see Franco next slide), Matlab Tutorial, i.e. >> CDS110-101
More informationUsing Built-in Plotting Functions
Workshop: Graphics in R Katherine Thompson (katherine.thompson@uky.edu Department of Statistics, University of Kentucky September 15, 2016 Using Built-in Plotting Functions ## Plotting One Quantitative
More informationUniversity of Alberta
A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.
More informationTopics for today Input / Output Using data frames Mathematics with vectors and matrices Summary statistics Basic graphics
Topics for today Input / Output Using data frames Mathematics with vectors and matrices Summary statistics Basic graphics Introduction to S-Plus 1 Input: Data files For rectangular data files (n rows,
More informationIntroduction to Matlab
NDSU Introduction to Matlab pg 1 Becoming familiar with MATLAB The console The editor The graphics windows The help menu Saving your data (diary) Solving N equations with N unknowns Least Squares Curve
More informationlimma: A brief introduction to R
limma: A brief introduction to R Natalie P. Thorne September 5, 2006 R basics i R is a command line driven environment. This means you have to type in commands (line-by-line) for it to compute or calculate
More informationMBV4410/9410 Fall Bioinformatics for Molecular Biology. Introduction to R
MBV4410/9410 Fall 2018 Bioinformatics for Molecular Biology Introduction to R Outline Introduce R Basic operations RStudio Bioconductor? Goal of the lecture Introduce you to R Show how to run R, basic
More informationUniversity of Wollongong School of Mathematics and Applied Statistics. STAT231 Probability and Random Variables Introductory Laboratory
1 R and RStudio University of Wollongong School of Mathematics and Applied Statistics STAT231 Probability and Random Variables 2014 Introductory Laboratory RStudio is a powerful statistical analysis package.
More informationR Workshop Module 3: Plotting Data Katherine Thompson Department of Statistics, University of Kentucky
R Workshop Module 3: Plotting Data Katherine Thompson (katherine.thompson@uky.edu Department of Statistics, University of Kentucky October 15, 2013 Reading in Data Start by reading the dataset practicedata.txt
More informationWorkshop in Methods and Indiana Statistical Consulting Center Introduction to R
Workshop in Methods and Indiana Statistical Consulting Center Introduction to R R Basics Leslie M. Blaha 23 January 2010 WIM and ISCC Intro to R R Basics 1 / 12 A Short History of R The R Project for Statistical
More informationIntroduction to MATLAB LAB 1
Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions
More informationIntroduction to PartSim and Matlab
NDSU Introduction to PartSim and Matlab pg 1 PartSim: www.partsim.com Introduction to PartSim and Matlab PartSim is a free on-line circuit simulator that we use in Circuits and Electronics. It works fairly
More informationApplied Calculus. Lab 1: An Introduction to R
1 Math 131/135/194, Fall 2004 Applied Calculus Profs. Kaplan & Flath Macalester College Lab 1: An Introduction to R Goal of this lab To begin to see how to use R. What is R? R is a computer package for
More informationCreates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.
EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses
More informationMatlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:
1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write
More informationIntroduction to R. Daniel Berglund. 9 November 2017
Introduction to R Daniel Berglund 9 November 2017 1 / 15 R R is available at the KTH computers If you want to install it yourself it is available at https://cran.r-project.org/ Rstudio an IDE for R is
More informationComputer lab 2 Course: Introduction to R for Biologists
Computer lab 2 Course: Introduction to R for Biologists April 23, 2012 1 Scripting As you have seen, you often want to run a sequence of commands several times, perhaps with small changes. An efficient
More informationShort Version of Matlab Manual
Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.
More informationACHIEVEMENTS FROM TRAINING
LEARN WELL TECHNOCRAFT DATA SCIENCE/ MACHINE LEARNING SYLLABUS 8TH YEAR OF ACCOMPLISHMENTS AUTHORIZED GLOBAL CERTIFICATION CENTER FOR MICROSOFT, ORACLE, IBM, AWS AND MANY MORE. 8411002339/7709292162 WWW.DW-LEARNWELL.COM
More informationStats with R and RStudio Practical: basic stats for peak calling Jacques van Helden, Hugo varet and Julie Aubert
Stats with R and RStudio Practical: basic stats for peak calling Jacques van Helden, Hugo varet and Julie Aubert 2017-01-08 Contents Introduction 2 Peak-calling: question...........................................
More informationIntroduction to R for Beginners, Level II. Jeon Lee Bio-Informatics Core Facility (BICF), UTSW
Introduction to R for Beginners, Level II Jeon Lee Bio-Informatics Core Facility (BICF), UTSW Basics of R Powerful programming language and environment for statistical computing Useful for very basic analysis
More information