SlideShare a Scribd company logo
Introduction to R
nitesh chhabria
The R environment
!
R is integrated suite of software facilities for data
manipulation, calculation and graphical display.
its also open source - “cheers”
How to get and use R?
http://r-project.org/ is place where u can get the all the core packages.
How to start using it?
— Terminal :
> R // Type this command
— GUI :
Find the installed R application and double click it
Some basic commands
!
source(“file.r”) Used for executing commands stored in file.r
sink(“record.lis”)
All the subsequent outputs will be stored in record
file
ls()
Used to display the names of objects stored in
within R
rm(ob) Removes the object ob from memory
Vectors
!
R works on data structures. Vector is simplest of them.
> vec <- c(1, 2, 3, 4, 5) // <- is assignment operator and c is
function used for creating vectors
> vec
[1] 1 2 3 4 5
> vec +1 // can u guess what will be output?
[1] 2 3 4 5 6
Generating sequences
!
> vec1 <- 1:10 // Used for generating vector having
elements from 1 to 10.
> vec2 <- seq(-5, 5, by= 0.2) // Used for generation vector from -5 to 5
with difference of 0.2
> vec3 <- rep( vec1, times=10) // Will generate 10 copies of vec1
> temp <- vec > 3 // Will check condition for all the elements
in vec
> vec4 <- c(“hello”, “there”) // Will create vector of strings
!
!
Matrices
> X <- matrix(NA, nrow= 7 , ncol= 3)
> X
[,1] [,2] [,3]
[1,] NA NA NA
[2,] NA NA NA //This will create a matrix with values not available
[3,] NA NA NA . Indexing starts from 1
[4,] NA NA NA
[5,] NA NA NA
[6,] NA NA NA
[7,] NA NA NA
!
> X[row, col] syntax is used for accessing values of the cell
Lists
!
List is used to make parcel of unrelated items
> result <- list(mu = 0.3, sigma = 0.45, x =1:3)
> result$mu
0.3
> result$x
[1] 1 2 3
> result.new <- “hello there” // Will add the string in new variable
Regression
!
Linear regression is used to find the best fit curve from the
the given values so that the residual error is minimum.
Steps needed to find the best fit curve:
#collect data
#define model
#apply regression
#use the generated values to predict
Linear model in R
Modelling is technique to represent the data mathematically
General form:
response ~ op1 term1 op2 term 2 op3 term3...
Models and syntax:
-Independent Variables - Y , A , B
-Coefficients - β
!
Model Syntax
Y=βo +β1A Y~A
Y = β1A Y ~ -1 + A
Y = βo+ β1A + β2A2 Y ~ A + I(A^2)
Y = βo+ β1A + β2B Y~A+B
Y=βo +β1AB Y ~ A:B
Example
Data :
> conc
[1]0 10 20 30 40 50
> signal
[1] 4 22 44 60 82 95
!
Expected model:
signal = βo + β1×conc#
#
!
!
> lm(signal ~ conc)
Call:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lm(formula = signal ~ conc)
 
 
 
 
 
 
 
 
Coefficients: 
 
 
 
 
 
 
 
 
 
 
 
 
(Intercept) conc
 
 
 
 
 
 
 
 
 
 
 

 3.60 1.94
> lm.r <- lm(signal ~ conc) !
Carrying out regression
> layout(matrix(1:4, 2, 2)
!
> plot(lm.r)
!
!
!
!
!
Uniform vs Normal Distribution
Normal
Uniform
Uniform Distribution
> runif(5000) // Will generate 5000 uniform dist points
> plot(runif(5000)) // Will plot all the points and produce UD
> plot(density(runif(5000))) // Density of all the numbers
Some statics:
> summary(runif(5000))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0004056 0.2701000 0.5072000 0.5124000 0.7514000 0.9995000
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.0
density.default(x = runif(5000))
N = 5000 Bandwidth = 0.04717
Density
0 1000 2000 3000 4000 5000
0.00.20.40.60.81.0
Index
runif(5000)
Normal Distribution
> rnorm(5000) // Will generate 5000 uniform dist points
> plot(rnorm(5000)) // Will plot all the points and produce UD
> plot(density(rnorm(5000))) // Density of all the numbers
Some statics:
> summary(runif(5000))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-4.549000 -0.674800 0.005506 -0.001849 0.666600 3.629000
-4 -2 0 2 4
0.00.10.20.3
density.default(x = rnorm(5000))
N = 5000 Bandwidth = 0.1643
Density
0 1000 2000 3000 4000 5000
-4-2024
Index
rnorm(5000)
rnorm(5000)
Auto correlation function
> acf(rnorm(100))
0 5 10 15 20
-0.20.00.20.40.60.81.0
Lag
ACF
Series rnorm(100)
!
!
references:
http://www.montefiore.ulg.ac.be/~kvansteen/GBIO0009-1/ac20092010/Class8/Using%20R
%20for%20linear%20regression.pdf
An Introduction to R - W. N. Venables, D. M. Smith and the R Core Team
!
Thank You

More Related Content

What's hot

Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
Aleksandras Smirnovas
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations
Rupak Roy
 
Chp4(ref dynamic)
Chp4(ref dynamic)Chp4(ref dynamic)
Chp4(ref dynamic)
Mohd Effandi
 
Vector
VectorVector
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
Saugat Gautam
 
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게
박 민규
 
multiple linear regression
multiple linear regressionmultiple linear regression
multiple linear regression
Akhilesh Joshi
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
Kent Ohashi
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
Vivek Singh
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
Aroosa Rajput
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
Namgee Lee
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
Mahmoud Samir Fayed
 
Java program-to-calculate-area-and-circumference-of-circle
Java program-to-calculate-area-and-circumference-of-circleJava program-to-calculate-area-and-circumference-of-circle
Java program-to-calculate-area-and-circumference-of-circle
University of Essex
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84
Mahmoud Samir Fayed
 
Functional linear data structures in f#
Functional linear data structures in f#Functional linear data structures in f#
Functional linear data structures in f#
Jack Fox
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
Megha V
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
Mahmoud Samir Fayed
 
Chapter 6 arrays part-1
Chapter 6   arrays part-1Chapter 6   arrays part-1
Chapter 6 arrays part-1
Synapseindiappsdevelopment
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
John Cant
 

What's hot (20)

Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations
 
Chp4(ref dynamic)
Chp4(ref dynamic)Chp4(ref dynamic)
Chp4(ref dynamic)
 
Vector
VectorVector
Vector
 
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
 
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게
 
multiple linear regression
multiple linear regressionmultiple linear regression
multiple linear regression
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 
Java program-to-calculate-area-and-circumference-of-circle
Java program-to-calculate-area-and-circumference-of-circleJava program-to-calculate-area-and-circumference-of-circle
Java program-to-calculate-area-and-circumference-of-circle
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84
 
Functional linear data structures in f#
Functional linear data structures in f#Functional linear data structures in f#
Functional linear data structures in f#
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 
Chapter 6 arrays part-1
Chapter 6   arrays part-1Chapter 6   arrays part-1
Chapter 6 arrays part-1
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 

Viewers also liked

Timothy_Sisk
Timothy_SiskTimothy_Sisk
Timothy_Sisk
Timothy Sisk
 
Trafusarde
TrafusardeTrafusarde
Trafusarde
Trafusarde
 
Những thực phầm có lợi cho bệnh nhân khớp
Những thực phầm có lợi cho bệnh nhân khớpNhững thực phầm có lợi cho bệnh nhân khớp
Những thực phầm có lợi cho bệnh nhân khớpchas234
 
resume (1)
resume (1)resume (1)
resume (1)
amit kumar
 
Citizenship 2
Citizenship 2Citizenship 2
Citizenship 2
Beckham Toh Yuexi
 
Curriculum and instruction explored
Curriculum and instruction exploredCurriculum and instruction explored
Curriculum and instruction explored
traciemdixon
 
Prezentatsia1
Prezentatsia1Prezentatsia1
Prezentatsia1
patriot260494
 
Ewo company presentation 2016_en
Ewo company presentation 2016_enEwo company presentation 2016_en
Ewo company presentation 2016_en
Fernando Mena
 
Chapter 6 curriculum design
Chapter 6 curriculum design Chapter 6 curriculum design
Chapter 6 curriculum design
traciemdixon
 

Viewers also liked (9)

Timothy_Sisk
Timothy_SiskTimothy_Sisk
Timothy_Sisk
 
Trafusarde
TrafusardeTrafusarde
Trafusarde
 
Những thực phầm có lợi cho bệnh nhân khớp
Những thực phầm có lợi cho bệnh nhân khớpNhững thực phầm có lợi cho bệnh nhân khớp
Những thực phầm có lợi cho bệnh nhân khớp
 
resume (1)
resume (1)resume (1)
resume (1)
 
Citizenship 2
Citizenship 2Citizenship 2
Citizenship 2
 
Curriculum and instruction explored
Curriculum and instruction exploredCurriculum and instruction explored
Curriculum and instruction explored
 
Prezentatsia1
Prezentatsia1Prezentatsia1
Prezentatsia1
 
Ewo company presentation 2016_en
Ewo company presentation 2016_enEwo company presentation 2016_en
Ewo company presentation 2016_en
 
Chapter 6 curriculum design
Chapter 6 curriculum design Chapter 6 curriculum design
Chapter 6 curriculum design
 

Similar to Itroroduction to R language

R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
062MayankSinghal
 
R programming
R programmingR programming
R programming
Pramodkumar Jha
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
chestialtaff
 
Introduction2R
Introduction2RIntroduction2R
Introduction2R
Aureliano Bombarely
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
Alberto Labarga
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
Infinity Tech Solutions
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdf
zehiwot hone
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
Khaled Al-Shamaa
 
Programming in R
Programming in RProgramming in R
Programming in R
Smruti Sarangi
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
Yogendra Chaubey
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
krishna singh
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Functions in advanced programming
Functions in advanced programmingFunctions in advanced programming
Functions in advanced programming
VisnuDharsini
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
Abd El Kareem Ahmed
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
reddyprasad reddyvari
 
Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics
nazlitemu
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
BilawalBaloch1
 
R basics
R basicsR basics
R basics
Sagun Baijal
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
 

Similar to Itroroduction to R language (20)

R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
R programming
R programmingR programming
R programming
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Introduction2R
Introduction2RIntroduction2R
Introduction2R
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdf
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Programming in R
Programming in RProgramming in R
Programming in R
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Functions in advanced programming
Functions in advanced programmingFunctions in advanced programming
Functions in advanced programming
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
R basics
R basicsR basics
R basics
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 

Recently uploaded

sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 

Recently uploaded (20)

sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 

Itroroduction to R language

  • 2. The R environment ! R is integrated suite of software facilities for data manipulation, calculation and graphical display. its also open source - “cheers”
  • 3. How to get and use R? http://r-project.org/ is place where u can get the all the core packages. How to start using it? — Terminal : > R // Type this command — GUI : Find the installed R application and double click it
  • 4. Some basic commands ! source(“file.r”) Used for executing commands stored in file.r sink(“record.lis”) All the subsequent outputs will be stored in record file ls() Used to display the names of objects stored in within R rm(ob) Removes the object ob from memory
  • 5. Vectors ! R works on data structures. Vector is simplest of them. > vec <- c(1, 2, 3, 4, 5) // <- is assignment operator and c is function used for creating vectors > vec [1] 1 2 3 4 5 > vec +1 // can u guess what will be output? [1] 2 3 4 5 6
  • 6. Generating sequences ! > vec1 <- 1:10 // Used for generating vector having elements from 1 to 10. > vec2 <- seq(-5, 5, by= 0.2) // Used for generation vector from -5 to 5 with difference of 0.2 > vec3 <- rep( vec1, times=10) // Will generate 10 copies of vec1 > temp <- vec > 3 // Will check condition for all the elements in vec > vec4 <- c(“hello”, “there”) // Will create vector of strings ! !
  • 7. Matrices > X <- matrix(NA, nrow= 7 , ncol= 3) > X [,1] [,2] [,3] [1,] NA NA NA [2,] NA NA NA //This will create a matrix with values not available [3,] NA NA NA . Indexing starts from 1 [4,] NA NA NA [5,] NA NA NA [6,] NA NA NA [7,] NA NA NA ! > X[row, col] syntax is used for accessing values of the cell
  • 8. Lists ! List is used to make parcel of unrelated items > result <- list(mu = 0.3, sigma = 0.45, x =1:3) > result$mu 0.3 > result$x [1] 1 2 3 > result.new <- “hello there” // Will add the string in new variable
  • 9. Regression ! Linear regression is used to find the best fit curve from the the given values so that the residual error is minimum. Steps needed to find the best fit curve: #collect data #define model #apply regression #use the generated values to predict
  • 10. Linear model in R Modelling is technique to represent the data mathematically General form: response ~ op1 term1 op2 term 2 op3 term3... Models and syntax: -Independent Variables - Y , A , B -Coefficients - β
  • 11. ! Model Syntax Y=βo +β1A Y~A Y = β1A Y ~ -1 + A Y = βo+ β1A + β2A2 Y ~ A + I(A^2) Y = βo+ β1A + β2B Y~A+B Y=βo +β1AB Y ~ A:B
  • 12. Example Data : > conc [1]0 10 20 30 40 50 > signal [1] 4 22 44 60 82 95 ! Expected model: signal = βo + β1×conc# #
  • 13. ! ! > lm(signal ~ conc) Call: lm(formula = signal ~ conc) Coefficients: (Intercept) conc 3.60 1.94 > lm.r <- lm(signal ~ conc) ! Carrying out regression
  • 14.
  • 15. > layout(matrix(1:4, 2, 2) ! > plot(lm.r) ! ! ! ! !
  • 16.
  • 17. Uniform vs Normal Distribution Normal Uniform
  • 18. Uniform Distribution > runif(5000) // Will generate 5000 uniform dist points > plot(runif(5000)) // Will plot all the points and produce UD > plot(density(runif(5000))) // Density of all the numbers Some statics: > summary(runif(5000)) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0004056 0.2701000 0.5072000 0.5124000 0.7514000 0.9995000
  • 19. 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.0 density.default(x = runif(5000)) N = 5000 Bandwidth = 0.04717 Density 0 1000 2000 3000 4000 5000 0.00.20.40.60.81.0 Index runif(5000)
  • 20. Normal Distribution > rnorm(5000) // Will generate 5000 uniform dist points > plot(rnorm(5000)) // Will plot all the points and produce UD > plot(density(rnorm(5000))) // Density of all the numbers Some statics: > summary(runif(5000)) Min. 1st Qu. Median Mean 3rd Qu. Max. -4.549000 -0.674800 0.005506 -0.001849 0.666600 3.629000
  • 21. -4 -2 0 2 4 0.00.10.20.3 density.default(x = rnorm(5000)) N = 5000 Bandwidth = 0.1643 Density 0 1000 2000 3000 4000 5000 -4-2024 Index rnorm(5000) rnorm(5000)
  • 22. Auto correlation function > acf(rnorm(100)) 0 5 10 15 20 -0.20.00.20.40.60.81.0 Lag ACF Series rnorm(100)