SlideShare a Scribd company logo
1 of 12
Correlation and
Regression in R
Hamid Reza Bolhasani
PhD, Data Scientist
Jan 2020
1
Table of contents
- Covariance
- Correlation
- Examples
- Regression
- Case Study in R
- Conclusion
2
Covariance
1
))((
),cov( 1




n
yyxx
yx
i
n
i
i
1
)( 2
12




n
xx
S
n
i
i
x
Variance
Gives information of a single variable
Covariance
Gives information on the degree to which two variables
vary together.
 When X and Y cov (x,y) = pos.
 When X and Y cov (x,y) = neg.
 When no constant relationship: cov (x,y) = 0
3
Covariance Example
High variance data Low variance data
Subject x y x error * y
error
x y X error * y
error
1 101 100 2500 54 53 9
2 81 80 900 53 52 4
3 61 60 100 52 51 1
4 51 50 0 51 50 0
5 41 40 100 50 49 1
6 21 20 900 49 48 4
7 1 0 2500 48 47 9
Mean 51 50 51 50
Sum of x error * y error : 7000 Sum of x error * y error : 28
Covariance: 1166.67 Covariance: 4.67
4
Correlation & Regression
Correlation
- Is there any relationship between 2 variables (x,y)?
- X is independent (Explanatory) and Y is dependent (Response)
- Correlation ≠ Causation
Regression
How well a certain independent variable predict dependent variable?
     2 2
2 2
N XY X Y
N X X N Y Y
xyr
 
  

   
xy
xy
x y
s
r
s s

5
Correlation in Scatter Diagrams
x
y
Strong negative correlation
x
y
Weak positive correlation
x
y
Strong positive correlation
x
y
Nonlinear Correlation
r = 0.91 r = 0.88
r = 0.42
r = 0.07
6
Regression Example
Smoking vs Lung Capacity
N Cigarettes (X ) Lung Capacity (Y )
1 0 45
2 5 42
3 10 33
4 15 31
5 20 29
7
Example Analysis
Smoking vs Lung Capacity
20
25
30
35
40
45
50
-5 0 5 10 15 20 25
LungCapacity
Smoking (yrs)
Lung Capacity (Y )
8
1
( 215) 53.75
4
xyS    
0.96xyr  
When smoking is above its group
means, lung capacity tends to be
below its group mean.
Greater smoking exposure implies
greater likelihood of lung damage.
Regression
9
- The process of predicting variable Y using variable X.
- Tells us how values in Y changes as a function of changes in value X.
- Calculates the “best-fit” line for a certain of data.
x
y
d1
d2
d3
Observed y-value
Predicted y-value
intercept
ε
ŷ = ax + b
ε = residual error
= y i , true value
slope
= ŷ, predicted value
Regression: Case Study in R
10
library(ggplot2)
ggplot(data=mtcars, aes(x=wt, y=mpg))+geom_point()
- Data = mtcars
- wt: weight
- Mpg: miles per gallon
- S(x,y) = -5.11
- r(x,y) = -0.86
Regression: Case Study in R
11
- Intercept = 37
- Slope = -5.3
ggplot(data=mtcars, aes(x=wt, y=mpg))+geom_point()+geom_smooth(method="lm",se=FALSE)
lm(data=mtcars, mpg ~ wt)
Thanks!Hamid Reza Bolhasani
bolhasani@gmail.com
Jan 2020
12

More Related Content

What's hot

Econometrics project mcom and mphill
Econometrics project  mcom and mphillEconometrics project  mcom and mphill
Econometrics project mcom and mphilljunaidsuri
 
METHOD OF LEAST SQURE
METHOD OF LEAST SQUREMETHOD OF LEAST SQURE
METHOD OF LEAST SQUREDanial Mirza
 
Grade 9 homework questions on 2.4 and 2.5
Grade 9 homework questions on 2.4 and 2.5Grade 9 homework questions on 2.4 and 2.5
Grade 9 homework questions on 2.4 and 2.5ambermaine100
 
Regularization and variable selection via elastic net
Regularization and variable selection via elastic netRegularization and variable selection via elastic net
Regularization and variable selection via elastic netKyusonLim
 
Linear Regression Ordinary Least Squares Distributed Calculation Example
Linear Regression Ordinary Least Squares Distributed Calculation ExampleLinear Regression Ordinary Least Squares Distributed Calculation Example
Linear Regression Ordinary Least Squares Distributed Calculation ExampleMarjan Sterjev
 
BlUP and BLUE- REML of linear mixed model
BlUP and BLUE- REML of linear mixed modelBlUP and BLUE- REML of linear mixed model
BlUP and BLUE- REML of linear mixed modelKyusonLim
 
Regression analysis by Muthama JM
Regression analysis by Muthama JMRegression analysis by Muthama JM
Regression analysis by Muthama JMJapheth Muthama
 
Simple linear regression
Simple linear regressionSimple linear regression
Simple linear regressionMaria Theresa
 
Error analysis statistics
Error analysis   statisticsError analysis   statistics
Error analysis statisticsTarun Gehlot
 
Visual Explanation of Ridge Regression and LASSO
Visual Explanation of Ridge Regression and LASSOVisual Explanation of Ridge Regression and LASSO
Visual Explanation of Ridge Regression and LASSOKazuki Yoshida
 

What's hot (20)

Econometrics project mcom and mphill
Econometrics project  mcom and mphillEconometrics project  mcom and mphill
Econometrics project mcom and mphill
 
METHOD OF LEAST SQURE
METHOD OF LEAST SQUREMETHOD OF LEAST SQURE
METHOD OF LEAST SQURE
 
Grade 9 homework questions on 2.4 and 2.5
Grade 9 homework questions on 2.4 and 2.5Grade 9 homework questions on 2.4 and 2.5
Grade 9 homework questions on 2.4 and 2.5
 
Chapter15
Chapter15Chapter15
Chapter15
 
04 regression
04 regression04 regression
04 regression
 
Chapter13
Chapter13Chapter13
Chapter13
 
Regularization and variable selection via elastic net
Regularization and variable selection via elastic netRegularization and variable selection via elastic net
Regularization and variable selection via elastic net
 
Linear Regression Ordinary Least Squares Distributed Calculation Example
Linear Regression Ordinary Least Squares Distributed Calculation ExampleLinear Regression Ordinary Least Squares Distributed Calculation Example
Linear Regression Ordinary Least Squares Distributed Calculation Example
 
Dag in mmhc
Dag in mmhcDag in mmhc
Dag in mmhc
 
BlUP and BLUE- REML of linear mixed model
BlUP and BLUE- REML of linear mixed modelBlUP and BLUE- REML of linear mixed model
BlUP and BLUE- REML of linear mixed model
 
5 regression
5 regression5 regression
5 regression
 
Regression analysis by Muthama JM
Regression analysis by Muthama JMRegression analysis by Muthama JM
Regression analysis by Muthama JM
 
Simple linear regression
Simple linear regressionSimple linear regression
Simple linear regression
 
Chapter14
Chapter14Chapter14
Chapter14
 
Error analysis statistics
Error analysis   statisticsError analysis   statistics
Error analysis statistics
 
Stat sample test ch 10
Stat sample test ch 10Stat sample test ch 10
Stat sample test ch 10
 
2018 MUMS Fall Course - Problem Set 1 (Attachment for Class Presentation) - J...
2018 MUMS Fall Course - Problem Set 1 (Attachment for Class Presentation) - J...2018 MUMS Fall Course - Problem Set 1 (Attachment for Class Presentation) - J...
2018 MUMS Fall Course - Problem Set 1 (Attachment for Class Presentation) - J...
 
Chapter4
Chapter4Chapter4
Chapter4
 
Business statistics homework help
Business statistics homework helpBusiness statistics homework help
Business statistics homework help
 
Visual Explanation of Ridge Regression and LASSO
Visual Explanation of Ridge Regression and LASSOVisual Explanation of Ridge Regression and LASSO
Visual Explanation of Ridge Regression and LASSO
 

Similar to Correlation and Regression in R: CR-R

correlation and regression
correlation and regressioncorrelation and regression
correlation and regressionUnsa Shakir
 
Regression and correlation in statistics
Regression and correlation in statisticsRegression and correlation in statistics
Regression and correlation in statisticsiphone4s4
 
Statistics
Statistics Statistics
Statistics KafiPati
 
Regression and corelation (Biostatistics)
Regression and corelation (Biostatistics)Regression and corelation (Biostatistics)
Regression and corelation (Biostatistics)Muhammadasif909
 
Correlation by Neeraj Bhandari ( Surkhet.Nepal )
Correlation by Neeraj Bhandari ( Surkhet.Nepal )Correlation by Neeraj Bhandari ( Surkhet.Nepal )
Correlation by Neeraj Bhandari ( Surkhet.Nepal )Neeraj Bhandari
 
Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...
Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...
Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...Payaamvohra1
 
Module 1 Powerpoint 2.pptx
Module 1 Powerpoint 2.pptxModule 1 Powerpoint 2.pptx
Module 1 Powerpoint 2.pptxZyrenMisaki
 
Unit 1 Correlation- BSRM.pdf
Unit 1 Correlation- BSRM.pdfUnit 1 Correlation- BSRM.pdf
Unit 1 Correlation- BSRM.pdfRavinandan A P
 
Regression and Co-Relation
Regression and Co-RelationRegression and Co-Relation
Regression and Co-Relationnuwan udugampala
 
Corr-and-Regress (1).ppt
Corr-and-Regress (1).pptCorr-and-Regress (1).ppt
Corr-and-Regress (1).pptMuhammadAftab89
 
Cr-and-Regress.ppt
Cr-and-Regress.pptCr-and-Regress.ppt
Cr-and-Regress.pptRidaIrfan10
 
Corr-and-Regress.ppt
Corr-and-Regress.pptCorr-and-Regress.ppt
Corr-and-Regress.pptkrunal soni
 
Corr-and-Regress.ppt
Corr-and-Regress.pptCorr-and-Regress.ppt
Corr-and-Regress.pptMoinPasha12
 
Correlation & Regression for Statistics Social Science
Correlation & Regression for Statistics Social ScienceCorrelation & Regression for Statistics Social Science
Correlation & Regression for Statistics Social Sciencessuser71ac73
 

Similar to Correlation and Regression in R: CR-R (20)

correlation and regression
correlation and regressioncorrelation and regression
correlation and regression
 
Regression and correlation in statistics
Regression and correlation in statisticsRegression and correlation in statistics
Regression and correlation in statistics
 
stats_ch12.pdf
stats_ch12.pdfstats_ch12.pdf
stats_ch12.pdf
 
Statistics
Statistics Statistics
Statistics
 
Regression and corelation (Biostatistics)
Regression and corelation (Biostatistics)Regression and corelation (Biostatistics)
Regression and corelation (Biostatistics)
 
Correlation by Neeraj Bhandari ( Surkhet.Nepal )
Correlation by Neeraj Bhandari ( Surkhet.Nepal )Correlation by Neeraj Bhandari ( Surkhet.Nepal )
Correlation by Neeraj Bhandari ( Surkhet.Nepal )
 
33851.ppt
33851.ppt33851.ppt
33851.ppt
 
Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...
Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...
Biostats coorelation vs rREGRESSION.DIFFERENCE BETWEEN CORRELATION AND REGRES...
 
Module 1 Powerpoint 2.pptx
Module 1 Powerpoint 2.pptxModule 1 Powerpoint 2.pptx
Module 1 Powerpoint 2.pptx
 
Ch01_03.ppt
Ch01_03.pptCh01_03.ppt
Ch01_03.ppt
 
Unit 1 Correlation- BSRM.pdf
Unit 1 Correlation- BSRM.pdfUnit 1 Correlation- BSRM.pdf
Unit 1 Correlation- BSRM.pdf
 
Regression and Co-Relation
Regression and Co-RelationRegression and Co-Relation
Regression and Co-Relation
 
Corr-and-Regress (1).ppt
Corr-and-Regress (1).pptCorr-and-Regress (1).ppt
Corr-and-Regress (1).ppt
 
Corr-and-Regress.ppt
Corr-and-Regress.pptCorr-and-Regress.ppt
Corr-and-Regress.ppt
 
Cr-and-Regress.ppt
Cr-and-Regress.pptCr-and-Regress.ppt
Cr-and-Regress.ppt
 
Corr-and-Regress.ppt
Corr-and-Regress.pptCorr-and-Regress.ppt
Corr-and-Regress.ppt
 
Corr-and-Regress.ppt
Corr-and-Regress.pptCorr-and-Regress.ppt
Corr-and-Regress.ppt
 
Corr-and-Regress.ppt
Corr-and-Regress.pptCorr-and-Regress.ppt
Corr-and-Regress.ppt
 
Correlation & Regression for Statistics Social Science
Correlation & Regression for Statistics Social ScienceCorrelation & Regression for Statistics Social Science
Correlation & Regression for Statistics Social Science
 
Correlation
CorrelationCorrelation
Correlation
 

More from Hamidreza Bolhasani

Introduction to Research Methodology
Introduction to Research MethodologyIntroduction to Research Methodology
Introduction to Research MethodologyHamidreza Bolhasani
 
Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...
Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...
Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...Hamidreza Bolhasani
 
Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)Hamidreza Bolhasani
 
An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...
An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...
An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...Hamidreza Bolhasani
 
CS-Core Mobile Network (General)
CS-Core Mobile Network (General)CS-Core Mobile Network (General)
CS-Core Mobile Network (General)Hamidreza Bolhasani
 
NFV +SDN (Network Function Virtualization)
NFV +SDN (Network Function Virtualization)NFV +SDN (Network Function Virtualization)
NFV +SDN (Network Function Virtualization)Hamidreza Bolhasani
 
5G New Services - Opportunities and Challenges
5G New Services - Opportunities and Challenges5G New Services - Opportunities and Challenges
5G New Services - Opportunities and ChallengesHamidreza Bolhasani
 
5G + AI Applications in Healthcare and Medical Sciences
5G + AI Applications in Healthcare and Medical Sciences5G + AI Applications in Healthcare and Medical Sciences
5G + AI Applications in Healthcare and Medical SciencesHamidreza Bolhasani
 
2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network
2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network
2G / 3G / 4G / IMS / 5G Overview with Focus on Core NetworkHamidreza Bolhasani
 
Neural Networks Hardware Accelerators (An Introduction)
Neural Networks Hardware Accelerators (An Introduction)Neural Networks Hardware Accelerators (An Introduction)
Neural Networks Hardware Accelerators (An Introduction)Hamidreza Bolhasani
 
An Introduction to Quantum Computers Architecture
An Introduction to Quantum Computers ArchitectureAn Introduction to Quantum Computers Architecture
An Introduction to Quantum Computers ArchitectureHamidreza Bolhasani
 
Transport Layer in Computer Networks (TCP / UDP / SCTP)
Transport Layer in Computer Networks (TCP / UDP / SCTP)Transport Layer in Computer Networks (TCP / UDP / SCTP)
Transport Layer in Computer Networks (TCP / UDP / SCTP)Hamidreza Bolhasani
 
Mobile Networks Overview (2G / 3G / 4G-LTE)
Mobile Networks Overview (2G / 3G / 4G-LTE)Mobile Networks Overview (2G / 3G / 4G-LTE)
Mobile Networks Overview (2G / 3G / 4G-LTE)Hamidreza Bolhasani
 
High-Tech Telecommunication (4G/LTE) overview with focus on new services
High-Tech Telecommunication (4G/LTE) overview with focus on new servicesHigh-Tech Telecommunication (4G/LTE) overview with focus on new services
High-Tech Telecommunication (4G/LTE) overview with focus on new servicesHamidreza Bolhasani
 

More from Hamidreza Bolhasani (16)

Introduction to Research Methodology
Introduction to Research MethodologyIntroduction to Research Methodology
Introduction to Research Methodology
 
Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...
Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...
Internet of Things (IoT) and Artificial Intelligence (AI) role in Medical and...
 
Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)
 
An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...
An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...
An Overview on the role of Artificial Intelligence (AI) and Deep Neural Netwo...
 
CS-Core Mobile Network (General)
CS-Core Mobile Network (General)CS-Core Mobile Network (General)
CS-Core Mobile Network (General)
 
5G Network Overview
 5G Network Overview 5G Network Overview
5G Network Overview
 
NFV +SDN (Network Function Virtualization)
NFV +SDN (Network Function Virtualization)NFV +SDN (Network Function Virtualization)
NFV +SDN (Network Function Virtualization)
 
5G New Services - Opportunities and Challenges
5G New Services - Opportunities and Challenges5G New Services - Opportunities and Challenges
5G New Services - Opportunities and Challenges
 
5G + AI Applications in Healthcare and Medical Sciences
5G + AI Applications in Healthcare and Medical Sciences5G + AI Applications in Healthcare and Medical Sciences
5G + AI Applications in Healthcare and Medical Sciences
 
2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network
2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network
2G / 3G / 4G / IMS / 5G Overview with Focus on Core Network
 
Neural Networks Hardware Accelerators (An Introduction)
Neural Networks Hardware Accelerators (An Introduction)Neural Networks Hardware Accelerators (An Introduction)
Neural Networks Hardware Accelerators (An Introduction)
 
An Introduction to Quantum Computers Architecture
An Introduction to Quantum Computers ArchitectureAn Introduction to Quantum Computers Architecture
An Introduction to Quantum Computers Architecture
 
Transport Layer in Computer Networks (TCP / UDP / SCTP)
Transport Layer in Computer Networks (TCP / UDP / SCTP)Transport Layer in Computer Networks (TCP / UDP / SCTP)
Transport Layer in Computer Networks (TCP / UDP / SCTP)
 
IMS + VoLTE Overview
IMS + VoLTE OverviewIMS + VoLTE Overview
IMS + VoLTE Overview
 
Mobile Networks Overview (2G / 3G / 4G-LTE)
Mobile Networks Overview (2G / 3G / 4G-LTE)Mobile Networks Overview (2G / 3G / 4G-LTE)
Mobile Networks Overview (2G / 3G / 4G-LTE)
 
High-Tech Telecommunication (4G/LTE) overview with focus on new services
High-Tech Telecommunication (4G/LTE) overview with focus on new servicesHigh-Tech Telecommunication (4G/LTE) overview with focus on new services
High-Tech Telecommunication (4G/LTE) overview with focus on new services
 

Recently uploaded

{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 

Recently uploaded (20)

{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 

Correlation and Regression in R: CR-R

  • 1. Correlation and Regression in R Hamid Reza Bolhasani PhD, Data Scientist Jan 2020 1
  • 2. Table of contents - Covariance - Correlation - Examples - Regression - Case Study in R - Conclusion 2
  • 3. Covariance 1 ))(( ),cov( 1     n yyxx yx i n i i 1 )( 2 12     n xx S n i i x Variance Gives information of a single variable Covariance Gives information on the degree to which two variables vary together.  When X and Y cov (x,y) = pos.  When X and Y cov (x,y) = neg.  When no constant relationship: cov (x,y) = 0 3
  • 4. Covariance Example High variance data Low variance data Subject x y x error * y error x y X error * y error 1 101 100 2500 54 53 9 2 81 80 900 53 52 4 3 61 60 100 52 51 1 4 51 50 0 51 50 0 5 41 40 100 50 49 1 6 21 20 900 49 48 4 7 1 0 2500 48 47 9 Mean 51 50 51 50 Sum of x error * y error : 7000 Sum of x error * y error : 28 Covariance: 1166.67 Covariance: 4.67 4
  • 5. Correlation & Regression Correlation - Is there any relationship between 2 variables (x,y)? - X is independent (Explanatory) and Y is dependent (Response) - Correlation ≠ Causation Regression How well a certain independent variable predict dependent variable?      2 2 2 2 N XY X Y N X X N Y Y xyr           xy xy x y s r s s  5
  • 6. Correlation in Scatter Diagrams x y Strong negative correlation x y Weak positive correlation x y Strong positive correlation x y Nonlinear Correlation r = 0.91 r = 0.88 r = 0.42 r = 0.07 6
  • 7. Regression Example Smoking vs Lung Capacity N Cigarettes (X ) Lung Capacity (Y ) 1 0 45 2 5 42 3 10 33 4 15 31 5 20 29 7
  • 8. Example Analysis Smoking vs Lung Capacity 20 25 30 35 40 45 50 -5 0 5 10 15 20 25 LungCapacity Smoking (yrs) Lung Capacity (Y ) 8 1 ( 215) 53.75 4 xyS     0.96xyr   When smoking is above its group means, lung capacity tends to be below its group mean. Greater smoking exposure implies greater likelihood of lung damage.
  • 9. Regression 9 - The process of predicting variable Y using variable X. - Tells us how values in Y changes as a function of changes in value X. - Calculates the “best-fit” line for a certain of data. x y d1 d2 d3 Observed y-value Predicted y-value intercept ε ŷ = ax + b ε = residual error = y i , true value slope = ŷ, predicted value
  • 10. Regression: Case Study in R 10 library(ggplot2) ggplot(data=mtcars, aes(x=wt, y=mpg))+geom_point() - Data = mtcars - wt: weight - Mpg: miles per gallon - S(x,y) = -5.11 - r(x,y) = -0.86
  • 11. Regression: Case Study in R 11 - Intercept = 37 - Slope = -5.3 ggplot(data=mtcars, aes(x=wt, y=mpg))+geom_point()+geom_smooth(method="lm",se=FALSE) lm(data=mtcars, mpg ~ wt)