SlideShare une entreprise Scribd logo
1  sur  25
Tutorial on “R” Programming
Language
Eric A. Suess, Bruce E. Trumbo,
and Carlo Cosenza
CSU East Bay, Department of Statistics
and Biostatistics
Outline
•
•
•
•
•
•
•
•

Communication with R
R software
R Interfaces
R code
Packages
Graphics
Parallel processing/distributed computing
Commerical R REvolutions
Communication with R
• In my opinion, the R/S language has become
the most common language for
communication in the fields of Statistics and
and Data Analysis.
• Books are being written now with R presented
directly placed within the text.
• SV use R, for example
• Excellent for teaching.
R Software
• To download R
• http://www.r-project.org/
• CRAN
• Manuals
• The R Journal
• Books
R Software
R Interfaces
•
•
•
•
•
•
•

RWinEdt
Tinn-R
JGR (Java Gui for R)
Emacs + ESS
Rattle
AKward
Playwith (for graphics)
R code
> 2+2
[1] 4
> 2+2^2
[1] 6
> (2+2)^2
[1] 16

> sqrt(2)
[1] 1.414214
> log(2)
[1] 0.6931472
>x=5
> y = 10
> z <- x+y
>z
[1] 15
R Code
> seq(1,5, by=.5)
[1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
> v1 = c(6,5,4,3,2,1)
> v1
[1] 6 5 4 3 2 1
> v2 = c(10,9,8,7,6,5)
>
> v3 = v1 + v2
> v3
[1] 16 14 12 10 8 6
R code
> max(v3);min(v3)
[1] 16
[1] 6
> length(v3)
[1] 6
> mean(v3)
[1] 11
> sd(v3)
[1] 3.741657
R code
> v4 = v3[v3>10]
> v4
[1] 16 14 12
> n = 1:10000; a = (1 + 1/n)^n
> cbind(n,a)[c(1:5,10^(1:4)),]
n
a
[1,] 1 2.000000
[2,] 2 2.250000
[3,] 3 2.370370
[4,] 4 2.441406
[5,] 5 2.488320
[6,] 10 2.593742
[7,] 100 2.704814
[8,] 1000 2.716924
[9,] 10000 2.718146
R code
# LLN
cummean = function(x){
n = length(x)
y = numeric(n)
z = c(1:n)
y = cumsum(x)
y = y/z
return(y)
}
n = 10000
z = rnorm(n)
x = seq(1,n,1)
y = cummean(z)
X11()
plot(x,y,type= 'l',main= 'Convergence Plot')
R code
# CLT
n = 30
k = 1000

# sample size
# number of samples

mu = 5; sigma = 2; SEM = sigma/sqrt(n)
x = matrix(rnorm(n*k,mu,sigma),n,k) # This gives a matrix with the samples
# down the columns.
x.mean = apply(x,2,mean)
x.down = mu - 4*SEM; x.up = mu + 4*SEM; y.up = 1.5
hist(x.mean,prob= T,xlim= c(x.down,x.up),ylim= c(0,y.up),main= 'Sampling
distribution of the sample mean, Normal case')
par(new= T)
x = seq(x.down,x.up,0.01)
y = dnorm(x,mu,SEM)
plot(x,y,type= 'l',xlim= c(x.down,x.up),ylim= c(0,y.up))
R code
# Birthday Problem
m = 100000; n = 25 # iterations; people in room
x = numeric(m)
# vector for numbers of matches
for (i in 1:m)
{
b = sample(1:365, n, repl=T) # n random birthdays in ith room
x[i] = n - length(unique(b)) # no. of matches in ith room
}
mean(x == 0); mean(x)
# approximates P{X=0}; E(X)
cutp = (0:(max(x)+1)) - .5
# break points for histogram
hist(x, breaks=cutp, prob=T) # relative freq. histogram
R help
• help.start() Take a look
– An Introduction to R
– R Data Import/Export
– Packages

• data()
• ls()
R code
Data Manipulation with R
(Use R)
Phil Spector
R Packages
• There are many
contributed packages that
can be used to extend R.
• These libraries are created
and maintained by the
authors.
R Package - simpleboot
mu = 25; sigma = 5; n = 30
x = rnorm(n, mu, sigma)
library(simpleboot)
reps = 10000
X11()
median.boot = one.boot(x, median, R = reps)
#print(median.boot)
boot.ci(median.boot)
hist(median.boot,main="median")
R Package – ggplot2
• The fundamental building block of a plot is
based on aesthetics and facets
• Aesthetics are graphical attributes that effect
how the data are displayed. Color, Size, Shape
• Facets are subdivisions of graphical data.
• The graph is realized by adding layers, geoms,
and statistics.
R Package – ggplot2
library(ggplot2)
oldFaithfulPlot = ggplot(faithful, aes(eruptions,waiting))
oldFaithfulPlot + layer(geom="point")
oldFaithfulPlot + layer(geom="point") + layer(geom="smooth")
R Package – ggplot2
Ggplot2: Elegant Graphics
for Data Analysis (Use R)
Hadley Wickham
R Package - BioC
• BioConductor is an open source and open
development software project for the analysis
and comprehension of genomic data.
• http://www.bioconductor.org
• Download > Software > Installation Instructions
source("http://bioconductor.org/biocLite.R")
biocLite()
R Package - affyPara
library(affyPara)
library(affydata)
data(Dilution)
Dilution
cl <- makeCluster(2, type='SOCK')
bgcorrect.methods()
affyBatchBGC <- bgCorrectPara(Dilution,
method="rma", verbose=TRUE)
R Package - snow
• Parallel processing has become more common
within R
• snow, multicore, foreach, etc.
R Package - snow
•

Birthday Problem simulation in parallel

cl <- makeCluster(4, type='SOCK')
birthday <- function(n) {
ntests <- 1000
pop <- 1:365
anydup <- function(i)
any(duplicated(
sample(pop, n,replace=TRUE)))
sum(sapply(seq(ntests), anydup)) / ntests}
x <- foreach(j=1:100) %dopar% birthday (j)
stopCluster(cl)
Ref: http://www.rinfinance.com/RinFinance2009/presentations/UIC-Lewis%204-25-09.pdf
REvolution Computing
• REvolution R is an enhanced distribution of R
• Optimized, validated and supported
• http://www.revolution-computing.com/

Contenu connexe

Tendances

R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming FundamentalsRagia Ibrahim
 
R programming groundup-basic-section-i
R programming groundup-basic-section-iR programming groundup-basic-section-i
R programming groundup-basic-section-iDr. Awase Khirni Syed
 
Introduction to Rstudio
Introduction to RstudioIntroduction to Rstudio
Introduction to RstudioOlga Scrivner
 
Why R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformWhy R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformSyracuse University
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data scienceSovello Hildebrand
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching moduleSander Timmer
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language Rfbenault
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environmentYogendra Chaubey
 
The History and Use of R
The History and Use of RThe History and Use of R
The History and Use of RAnalyticsWeek
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programmingNimrita Koul
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
Introduction to R - from Rstudio to ggplot
Introduction to R - from Rstudio to ggplotIntroduction to R - from Rstudio to ggplot
Introduction to R - from Rstudio to ggplotOlga Scrivner
 
Introduction to Data Mining with R and Data Import/Export in R
Introduction to Data Mining with R and Data Import/Export in RIntroduction to Data Mining with R and Data Import/Export in R
Introduction to Data Mining with R and Data Import/Export in RYanchang Zhao
 
R-programming-training-in-mumbai
R-programming-training-in-mumbaiR-programming-training-in-mumbai
R-programming-training-in-mumbaiUnmesh Baile
 

Tendances (20)

R language
R languageR language
R language
 
R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming Fundamentals
 
R programming groundup-basic-section-i
R programming groundup-basic-section-iR programming groundup-basic-section-i
R programming groundup-basic-section-i
 
Machine Learning in R
Machine Learning in RMachine Learning in R
Machine Learning in R
 
Introduction to Rstudio
Introduction to RstudioIntroduction to Rstudio
Introduction to Rstudio
 
R - the language
R - the languageR - the language
R - the language
 
LSESU a Taste of R Language Workshop
LSESU a Taste of R Language WorkshopLSESU a Taste of R Language Workshop
LSESU a Taste of R Language Workshop
 
Why R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformWhy R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics Platform
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data science
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language R
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
The History and Use of R
The History and Use of RThe History and Use of R
The History and Use of R
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programming
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
Introduction to R - from Rstudio to ggplot
Introduction to R - from Rstudio to ggplotIntroduction to R - from Rstudio to ggplot
Introduction to R - from Rstudio to ggplot
 
Introduction to Data Mining with R and Data Import/Export in R
Introduction to Data Mining with R and Data Import/Export in RIntroduction to Data Mining with R and Data Import/Export in R
Introduction to Data Mining with R and Data Import/Export in R
 
R-programming-training-in-mumbai
R-programming-training-in-mumbaiR-programming-training-in-mumbai
R-programming-training-in-mumbai
 
R programming language
R programming languageR programming language
R programming language
 

En vedette

YHORG Presentation 23 February 2016
YHORG Presentation 23 February 2016YHORG Presentation 23 February 2016
YHORG Presentation 23 February 2016Richard Vidgen
 
2 R Tutorial Programming
2 R Tutorial Programming2 R Tutorial Programming
2 R Tutorial ProgrammingSakthi Dasans
 
R Introduction
R IntroductionR Introduction
R Introductionschamber
 
1 R Tutorial Introduction
1 R Tutorial Introduction1 R Tutorial Introduction
1 R Tutorial IntroductionSakthi Dasans
 
Introduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing EnvironmentIntroduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing Environmentizahn
 
Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...
Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...
Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...Goran S. Milovanovic
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programmingizahn
 
Introduction to R
Introduction to RIntroduction to R
Introduction to RStacy Irwin
 
Data Science - Part II - Working with R & R studio
Data Science - Part II -  Working with R & R studioData Science - Part II -  Working with R & R studio
Data Science - Part II - Working with R & R studioDerek Kane
 

En vedette (14)

YHORG Presentation 23 February 2016
YHORG Presentation 23 February 2016YHORG Presentation 23 February 2016
YHORG Presentation 23 February 2016
 
R presentation
R presentationR presentation
R presentation
 
2 R Tutorial Programming
2 R Tutorial Programming2 R Tutorial Programming
2 R Tutorial Programming
 
R Introduction
R IntroductionR Introduction
R Introduction
 
1 R Tutorial Introduction
1 R Tutorial Introduction1 R Tutorial Introduction
1 R Tutorial Introduction
 
Introduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing EnvironmentIntroduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing Environment
 
Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...
Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...
Introduction to R for Data Science :: Session 7 [Multiple Linear Regression i...
 
R- Introduction
R- IntroductionR- Introduction
R- Introduction
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
R programming
R programmingR programming
R programming
 
Step By Step Guide to Learn R
Step By Step Guide to Learn RStep By Step Guide to Learn R
Step By Step Guide to Learn R
 
R introduction v2
R introduction v2R introduction v2
R introduction v2
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Data Science - Part II - Working with R & R studio
Data Science - Part II -  Working with R & R studioData Science - Part II -  Working with R & R studio
Data Science - Part II - Working with R & R studio
 

Similaire à Rtutorial

Data analysis with R
Data analysis with RData analysis with R
Data analysis with RShareThis
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptxkarthikks82
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RRsquared Academy
 
INTRODUCTION AND HISTORY OF R PROGRAMMING.pdf
INTRODUCTION AND HISTORY OF R PROGRAMMING.pdfINTRODUCTION AND HISTORY OF R PROGRAMMING.pdf
INTRODUCTION AND HISTORY OF R PROGRAMMING.pdfranapoonam1
 
Introduction to SparkR
Introduction to SparkRIntroduction to SparkR
Introduction to SparkRKien Dang
 
Introduction to R
Introduction to RIntroduction to R
Introduction to Ragnonchik
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingAlberto Labarga
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programaciónSoftware Guru
 

Similaire à Rtutorial (20)

Big datacourse
Big datacourseBig datacourse
Big datacourse
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Python grass
Python grassPython grass
Python grass
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptx
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
 
Seminar psu 20.10.2013
Seminar psu 20.10.2013Seminar psu 20.10.2013
Seminar psu 20.10.2013
 
Perm winter school 2014.01.31
Perm winter school 2014.01.31Perm winter school 2014.01.31
Perm winter school 2014.01.31
 
INTRODUCTION AND HISTORY OF R PROGRAMMING.pdf
INTRODUCTION AND HISTORY OF R PROGRAMMING.pdfINTRODUCTION AND HISTORY OF R PROGRAMMING.pdf
INTRODUCTION AND HISTORY OF R PROGRAMMING.pdf
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
Introduction to SparkR
Introduction to SparkRIntroduction to SparkR
Introduction to SparkR
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
BasicGraphsWithR
BasicGraphsWithRBasicGraphsWithR
BasicGraphsWithR
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 

Dernier

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 

Dernier (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Rtutorial

  • 1. Tutorial on “R” Programming Language Eric A. Suess, Bruce E. Trumbo, and Carlo Cosenza CSU East Bay, Department of Statistics and Biostatistics
  • 2. Outline • • • • • • • • Communication with R R software R Interfaces R code Packages Graphics Parallel processing/distributed computing Commerical R REvolutions
  • 3. Communication with R • In my opinion, the R/S language has become the most common language for communication in the fields of Statistics and and Data Analysis. • Books are being written now with R presented directly placed within the text. • SV use R, for example • Excellent for teaching.
  • 4. R Software • To download R • http://www.r-project.org/ • CRAN • Manuals • The R Journal • Books
  • 6. R Interfaces • • • • • • • RWinEdt Tinn-R JGR (Java Gui for R) Emacs + ESS Rattle AKward Playwith (for graphics)
  • 7. R code > 2+2 [1] 4 > 2+2^2 [1] 6 > (2+2)^2 [1] 16 > sqrt(2) [1] 1.414214 > log(2) [1] 0.6931472 >x=5 > y = 10 > z <- x+y >z [1] 15
  • 8. R Code > seq(1,5, by=.5) [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 > v1 = c(6,5,4,3,2,1) > v1 [1] 6 5 4 3 2 1 > v2 = c(10,9,8,7,6,5) > > v3 = v1 + v2 > v3 [1] 16 14 12 10 8 6
  • 9. R code > max(v3);min(v3) [1] 16 [1] 6 > length(v3) [1] 6 > mean(v3) [1] 11 > sd(v3) [1] 3.741657
  • 10. R code > v4 = v3[v3>10] > v4 [1] 16 14 12 > n = 1:10000; a = (1 + 1/n)^n > cbind(n,a)[c(1:5,10^(1:4)),] n a [1,] 1 2.000000 [2,] 2 2.250000 [3,] 3 2.370370 [4,] 4 2.441406 [5,] 5 2.488320 [6,] 10 2.593742 [7,] 100 2.704814 [8,] 1000 2.716924 [9,] 10000 2.718146
  • 11. R code # LLN cummean = function(x){ n = length(x) y = numeric(n) z = c(1:n) y = cumsum(x) y = y/z return(y) } n = 10000 z = rnorm(n) x = seq(1,n,1) y = cummean(z) X11() plot(x,y,type= 'l',main= 'Convergence Plot')
  • 12. R code # CLT n = 30 k = 1000 # sample size # number of samples mu = 5; sigma = 2; SEM = sigma/sqrt(n) x = matrix(rnorm(n*k,mu,sigma),n,k) # This gives a matrix with the samples # down the columns. x.mean = apply(x,2,mean) x.down = mu - 4*SEM; x.up = mu + 4*SEM; y.up = 1.5 hist(x.mean,prob= T,xlim= c(x.down,x.up),ylim= c(0,y.up),main= 'Sampling distribution of the sample mean, Normal case') par(new= T) x = seq(x.down,x.up,0.01) y = dnorm(x,mu,SEM) plot(x,y,type= 'l',xlim= c(x.down,x.up),ylim= c(0,y.up))
  • 13. R code # Birthday Problem m = 100000; n = 25 # iterations; people in room x = numeric(m) # vector for numbers of matches for (i in 1:m) { b = sample(1:365, n, repl=T) # n random birthdays in ith room x[i] = n - length(unique(b)) # no. of matches in ith room } mean(x == 0); mean(x) # approximates P{X=0}; E(X) cutp = (0:(max(x)+1)) - .5 # break points for histogram hist(x, breaks=cutp, prob=T) # relative freq. histogram
  • 14. R help • help.start() Take a look – An Introduction to R – R Data Import/Export – Packages • data() • ls()
  • 15. R code Data Manipulation with R (Use R) Phil Spector
  • 16. R Packages • There are many contributed packages that can be used to extend R. • These libraries are created and maintained by the authors.
  • 17. R Package - simpleboot mu = 25; sigma = 5; n = 30 x = rnorm(n, mu, sigma) library(simpleboot) reps = 10000 X11() median.boot = one.boot(x, median, R = reps) #print(median.boot) boot.ci(median.boot) hist(median.boot,main="median")
  • 18. R Package – ggplot2 • The fundamental building block of a plot is based on aesthetics and facets • Aesthetics are graphical attributes that effect how the data are displayed. Color, Size, Shape • Facets are subdivisions of graphical data. • The graph is realized by adding layers, geoms, and statistics.
  • 19. R Package – ggplot2 library(ggplot2) oldFaithfulPlot = ggplot(faithful, aes(eruptions,waiting)) oldFaithfulPlot + layer(geom="point") oldFaithfulPlot + layer(geom="point") + layer(geom="smooth")
  • 20. R Package – ggplot2 Ggplot2: Elegant Graphics for Data Analysis (Use R) Hadley Wickham
  • 21. R Package - BioC • BioConductor is an open source and open development software project for the analysis and comprehension of genomic data. • http://www.bioconductor.org • Download > Software > Installation Instructions source("http://bioconductor.org/biocLite.R") biocLite()
  • 22. R Package - affyPara library(affyPara) library(affydata) data(Dilution) Dilution cl <- makeCluster(2, type='SOCK') bgcorrect.methods() affyBatchBGC <- bgCorrectPara(Dilution, method="rma", verbose=TRUE)
  • 23. R Package - snow • Parallel processing has become more common within R • snow, multicore, foreach, etc.
  • 24. R Package - snow • Birthday Problem simulation in parallel cl <- makeCluster(4, type='SOCK') birthday <- function(n) { ntests <- 1000 pop <- 1:365 anydup <- function(i) any(duplicated( sample(pop, n,replace=TRUE))) sum(sapply(seq(ntests), anydup)) / ntests} x <- foreach(j=1:100) %dopar% birthday (j) stopCluster(cl) Ref: http://www.rinfinance.com/RinFinance2009/presentations/UIC-Lewis%204-25-09.pdf
  • 25. REvolution Computing • REvolution R is an enhanced distribution of R • Optimized, validated and supported • http://www.revolution-computing.com/