SlideShare a Scribd company logo
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Chapter 8
Linear Regression
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 3
Fat versus Protein: An Example
 The following is a scatterplot of total fat versus
protein for 30 items on the Burger King menu:
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 4
The Linear Model
 Correlation says “There seems to be a linear
association between these two variables,” but it
doesn’t tell what that association is.
 We can say more about the linear relationship
between two quantitative variables with a model.
 A model simplifies reality to help us understand
underlying patterns and relationships.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 5
The Linear Model (cont.)
 The linear model is just an equation of a straight
line through the data.
 The points in the scatterplot don’t all line up,
but a straight line can summarize the general
pattern.
 The linear model can help us understand how
the values are associated.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 6
Residuals
 The model won’t be perfect, regardless of the line
we draw.
 Some points will be above the line and some will
be below.
 The estimate made from a model is the predicted
value (denoted as ).ˆy
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 7
Residuals (cont.)
 The difference between the observed value and
its associated predicted value is called the
residual.
 To find the residuals, we always subtract the
predicted value from the observed one:
ˆresidual observed predicted y y= − = −
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 8
Residuals (cont.)
 A negative residual means
the predicted value’s too
big (an overestimate).
 A positive residual means
the predicted value’s too
small (an underestimate).
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 9
“Best Fit” Means Least Squares
 Some residuals are positive, others are negative,
and, on average, they cancel each other out.
 So, we can’t assess how well the line fits by
adding up all the residuals.
 Similar to what we did with deviations, we square
the residuals and add the squares.
 The smaller the sum, the better the fit.
 The line of best fit is the line for which the sum of
the squared residuals is smallest.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 10
The Least Squares Line
 We write our model as
 This model says that our predictions from our
model follow a straight line.
 If the model is a good one, the data values will
scatter closely around it.
0 1
ˆy b b x= +
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 11
The Least Squares Line (cont.)
 In our model, we have a slope (b1):
 The slope is built from the correlation and the
standard deviations:
 Our slope is always in units of y per unit of x.
1
y
x
s
b r
s
=
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 12
The Least Squares Line (cont.)
 In our model, we also have an intercept (b0).
 The intercept is built from the means and the
slope:
 Our intercept is always in units of y.
0 1b y b x= −
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 13
Fat versus Protein: An Example
 The regression line for the
Burger King data fits the
data well:
 The equation is
 The predicted fat
content for a BK Broiler
chicken sandwich is
6.8 + 0.97(30) = 35.9
grams of fat.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 14
The Least Squares Line (cont.)
 Since regression and correlation are closely
related, we need to check the same conditions for
regressions as we did for correlations:
 Quantitative Variables Condition
 Straight Enough Condition
 Outlier Condition
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 15
Correlation and the Line
 Moving one standard deviation away from the
mean in x moves us r standard deviations away
from the mean in y.
 This relationship is
shown in a scatterplot
of z-scores for
fat and protein:
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 16
Correlation and the Line (cont.)
 Put generally, moving any number of standard
deviations away from the mean in x moves us r
times that number of standard deviations away
from the mean in y.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 17
How Big Can Predicted Values Get?
 r cannot be bigger than 1 (in absolute value),
so each predicted y tends to be closer to its mean
(in standard deviations) than its corresponding
x was.
 This property of the linear model is called
regression to the mean; the line is called the
regression line.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 18
Residuals Revisited
 The linear model assumes that the relationship
between the two variables is a perfect straight
line. The residuals are the part of the data that
hasn’t been modeled.
Data = Model + Residual
or (equivalently)
Residual = Data – Model
Or, in symbols,
ˆe y y= −
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 19
Residuals Revisited (cont.)
 Residuals help us to see whether the model
makes sense.
 When a regression model is appropriate, nothing
interesting should be left behind.
 After we fit a regression model, we usually plot
the residuals in the hope of finding…nothing.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 20
Residuals Revisited (cont.)
 The residuals for the BK menu regression look
appropriately boring:
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 21
R2
—The Variation Accounted For
 The variation in the residuals is the key to
assessing how well the model fits.
 In the BK menu items
example, total fat has
a standard deviation
of 16.4 grams. The
standard deviation
of the residuals
is 9.2 grams.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 22
R2
—The Variation Accounted For (cont.)
 If the correlation were 1.0 and the model
predicted the fat values perfectly, the residuals
would all be zero and have no variation.
 As it is, the correlation is 0.83—not perfection.
 However, we did see that the model residuals
had less variation than total fat alone.
 We can determine how much of the variation is
accounted for by the model and how much is left
in the residuals.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 23
R2
—The Variation Accounted For (cont.)
 The squared correlation, r2
, gives the fraction of
the data’s variance accounted for by the model.
 Thus, 1– r2
is the fraction of the original variance
left in the residuals.
 For the BK model, r2
= 0.832
= 0.69, so 31% of the
variability in total fat has been left in the
residuals.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 24
R2
—The Variation Accounted For (cont.)
 All regression analyses include this statistic,
although by tradition, it is written R2
(pronounced
“R-squared”). An R2
of 0 means that none of the
variance in the data is in the model; all of it is still
in the residuals.
 When interpreting a regression model you need
to Tell what R2
means.
 In the BK example, 69% of the variation in total
fat is accounted for by the model.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 25
How Big Should R2
Be?
 R2
is always between 0% and 100%. What makes
a “good” R2
value depends on the kind of data
you are analyzing and on what you want to do
with it.
 The standard deviation of the residuals can give
us more information about the usefulness of the
regression by telling us how much scatter there is
around the line.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 26
 Along with the slope and intercept for a
regression, you should always report R2
so that
readers can judge for themselves how successful
the regression is at fitting the data.
 Statistics is about variation, and R2
measures the
success of the regression model in terms of the
fraction of the variation of y accounted for by the
regression.
How Big Should R2
Be (cont)?
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 27
Regression Assumptions and Conditions
 Quantitative Variables Condition:
 Regression can only be done on two
quantitative variables, so make sure to check
this condition.
 Straight Enough Condition:
 The linear model assumes that the relationship
between the variables is linear.
 A scatterplot will let you check that the
assumption is reasonable.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 28
Regressions Assumptions and Conditions (cont.)
 It’s a good idea to check linearity again after
computing the regression when we can examine
the residuals.
 You should also check for outliers, which could
change the regression.
 If the data seem to clump or cluster in the
scatterplot, that could be a sign of trouble worth
looking into further.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 29
 If the scatterplot is not straight enough, stop here.
 You can’t use a linear model for any two
variables, even if they are related.
 They must have a linear association or the
model won’t mean a thing.
 Some nonlinear relationships can be saved by re-
expressing the data to make the scatterplot more
linear.
Regressions Assumptions and Conditions (cont.)
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 30
 Outlier Condition:
 Watch out for outliers.
 Outlying points can dramatically change a
regression model.
 Outliers can even change the sign of the slope,
misleading us about the underlying relationship
between the variables.
Regressions Assumptions and Conditions (cont.)
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 31
Reality Check:
Is the Regression Reasonable?
 Statistics don’t come out of nowhere. They are based on
data.
 The results of a statistical analysis should reinforce
your common sense, not fly in its face.
 If the results are surprising, then either you’ve learned
something new about the world or your analysis is
wrong.
 When you perform a regression, think about the
coefficients and ask yourself whether they make sense.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 32
What Can Go Wrong?
 Don’t fit a straight line to a nonlinear relationship.
 Beware extraordinary points (y-values that stand off from
the linear pattern or extreme x-values).
 Don’t extrapolate beyond the data—the linear model may
no longer hold outside of the range of the data.
 Don’t infer that x causes y just because there is a good
linear model for their relationship—association is not
causation.
 Don’t choose a model based on R2
alone.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 33
What Have We Learned?
 When the relationship between two quantitative
variables is fairly straight, a linear model can help
summarize that relationship.
 The regression line doesn’t pass through all
the points, but it is the best compromise in the
sense that it has the smallest sum of squared
residuals.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 34
What Have We Learned? (cont.)
 The correlation tells us several things about the
regression:
 The slope of the line is based on the correlation,
adjusted for the units of x and y.
 For each SD in x that we are away from the x mean,
we expect to be r SDs in y away from the y mean.
 Since r is always between -1 and +1, each predicted y
is fewer SDs away from its mean than the
corresponding x was (regression to the mean).
 R2
gives us the fraction of the response accounted for
by the regression model.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 35
What Have We Learned? (cont.)
 The residuals also reveal how well the model
works.
 If a plot of the residuals against predicted
values shows a pattern, we should re-examine
the data to see why.
 The standard deviation of the residuals
quantifies the amount of scatter around the
line.
Copyright © 2012 Pearson Canada Inc., Toronto, Ontario
Slide 8- 36
 The linear model makes no sense unless the Linear
Relationship Assumption is satisfied.
 Also, we need to check the Straight Enough
Condition and Outlier Condition with a scatterplot.
 For the standard deviation of the residuals, we must
make the Equal Variance Assumption. We check it
by looking at both the original scatterplot and the
residual plot for Does the Plot Thicken? Condition.
What Have We Learned? (cont.)

More Related Content

What's hot

The Mechanics of Probabilistic Record Matching
The Mechanics of Probabilistic Record MatchingThe Mechanics of Probabilistic Record Matching
The Mechanics of Probabilistic Record Matching
Jeffrey Tyzzer
 
Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...
Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...
Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...
CSCJournals
 
Moving Beyond Linearity (Article 7 - Practical Exercises)
Moving Beyond Linearity (Article 7 - Practical Exercises)Moving Beyond Linearity (Article 7 - Practical Exercises)
Moving Beyond Linearity (Article 7 - Practical Exercises)
Theodore Grammatikopoulos
 
ECONOMETRICS PROJECT PG2 2015
ECONOMETRICS PROJECT PG2 2015ECONOMETRICS PROJECT PG2 2015
ECONOMETRICS PROJECT PG2 2015Sayantan Baidya
 
logistic regression.pdf
logistic regression.pdflogistic regression.pdf
logistic regression.pdf
BauyrzhanKalmakhan
 
Lecture2 Applied Econometrics and Economic Modeling
Lecture2 Applied Econometrics and Economic ModelingLecture2 Applied Econometrics and Economic Modeling
Lecture2 Applied Econometrics and Economic Modeling
stone55
 

What's hot (6)

The Mechanics of Probabilistic Record Matching
The Mechanics of Probabilistic Record MatchingThe Mechanics of Probabilistic Record Matching
The Mechanics of Probabilistic Record Matching
 
Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...
Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...
Penalized Regressions with Different Tuning Parameter Choosing Criteria and t...
 
Moving Beyond Linearity (Article 7 - Practical Exercises)
Moving Beyond Linearity (Article 7 - Practical Exercises)Moving Beyond Linearity (Article 7 - Practical Exercises)
Moving Beyond Linearity (Article 7 - Practical Exercises)
 
ECONOMETRICS PROJECT PG2 2015
ECONOMETRICS PROJECT PG2 2015ECONOMETRICS PROJECT PG2 2015
ECONOMETRICS PROJECT PG2 2015
 
logistic regression.pdf
logistic regression.pdflogistic regression.pdf
logistic regression.pdf
 
Lecture2 Applied Econometrics and Economic Modeling
Lecture2 Applied Econometrics and Economic ModelingLecture2 Applied Econometrics and Economic Modeling
Lecture2 Applied Econometrics and Economic Modeling
 

Similar to Linear regression

HRUG - Linear regression with R
HRUG - Linear regression with RHRUG - Linear regression with R
HRUG - Linear regression with R
egoodwintx
 
notes on correlational research
notes on correlational researchnotes on correlational research
notes on correlational researchSiti Ishark
 
Case2_Best_Model_Final
Case2_Best_Model_FinalCase2_Best_Model_Final
Case2_Best_Model_FinalEric Esajian
 
Can you Deep Learn the Stock Market?
Can you Deep Learn the Stock Market?Can you Deep Learn the Stock Market?
Can you Deep Learn the Stock Market?
Gaetan Lion
 
Applications of regression analysis - Measurement of validity of relationship
Applications of regression analysis - Measurement of validity of relationshipApplications of regression analysis - Measurement of validity of relationship
Applications of regression analysis - Measurement of validity of relationship
Rithish Kumar
 
Linear Regression- An 80-year study of the Dow Jones Industrial Average
Linear Regression- An 80-year study of the Dow Jones Industrial AverageLinear Regression- An 80-year study of the Dow Jones Industrial Average
Linear Regression- An 80-year study of the Dow Jones Industrial Average
courtalecia
 
Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...
Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...
Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...
Solventure
 
Logistic regression and analysis using statistical information
Logistic regression and analysis using statistical informationLogistic regression and analysis using statistical information
Logistic regression and analysis using statistical information
AsadJaved304231
 
Econometrics
EconometricsEconometrics
Econometrics
Stephanie King
 
Neural Network Model
Neural Network ModelNeural Network Model
Neural Network ModelEric Esajian
 
The future is uncertain. Some events do have a very small probabil.docx
The future is uncertain. Some events do have a very small probabil.docxThe future is uncertain. Some events do have a very small probabil.docx
The future is uncertain. Some events do have a very small probabil.docx
oreo10
 
1030 track1 heiler
1030 track1 heiler1030 track1 heiler
1030 track1 heiler
Rising Media, Inc.
 
Guide for building GLMS
Guide for building GLMSGuide for building GLMS
Guide for building GLMSAli T. Lotia
 
What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?
What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?
What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?
Smarten Augmented Analytics
 
1440 track3 galusha
1440 track3 galusha1440 track3 galusha
1440 track3 galusha
Rising Media, Inc.
 
Multiple Linear Regression.pptx
Multiple Linear Regression.pptxMultiple Linear Regression.pptx
Multiple Linear Regression.pptx
BHUSHANKPATEL
 
Further6 displaying bivariate data
Further6  displaying bivariate dataFurther6  displaying bivariate data
Further6 displaying bivariate datakmcmullen
 
Building a Regression Model using SPSS
Building a Regression Model using SPSSBuilding a Regression Model using SPSS
Building a Regression Model using SPSSZac Bodner
 
Environment&EconomicGrowth
Environment&EconomicGrowthEnvironment&EconomicGrowth
Environment&EconomicGrowthAnaisa Cerda
 
Regression and Classification Analysis
Regression and Classification AnalysisRegression and Classification Analysis
Regression and Classification Analysis
YashIyengar
 

Similar to Linear regression (20)

HRUG - Linear regression with R
HRUG - Linear regression with RHRUG - Linear regression with R
HRUG - Linear regression with R
 
notes on correlational research
notes on correlational researchnotes on correlational research
notes on correlational research
 
Case2_Best_Model_Final
Case2_Best_Model_FinalCase2_Best_Model_Final
Case2_Best_Model_Final
 
Can you Deep Learn the Stock Market?
Can you Deep Learn the Stock Market?Can you Deep Learn the Stock Market?
Can you Deep Learn the Stock Market?
 
Applications of regression analysis - Measurement of validity of relationship
Applications of regression analysis - Measurement of validity of relationshipApplications of regression analysis - Measurement of validity of relationship
Applications of regression analysis - Measurement of validity of relationship
 
Linear Regression- An 80-year study of the Dow Jones Industrial Average
Linear Regression- An 80-year study of the Dow Jones Industrial AverageLinear Regression- An 80-year study of the Dow Jones Industrial Average
Linear Regression- An 80-year study of the Dow Jones Industrial Average
 
Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...
Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...
Chapter 2 - Benchmarking and the Best Practice Frontier in the Supply Chain T...
 
Logistic regression and analysis using statistical information
Logistic regression and analysis using statistical informationLogistic regression and analysis using statistical information
Logistic regression and analysis using statistical information
 
Econometrics
EconometricsEconometrics
Econometrics
 
Neural Network Model
Neural Network ModelNeural Network Model
Neural Network Model
 
The future is uncertain. Some events do have a very small probabil.docx
The future is uncertain. Some events do have a very small probabil.docxThe future is uncertain. Some events do have a very small probabil.docx
The future is uncertain. Some events do have a very small probabil.docx
 
1030 track1 heiler
1030 track1 heiler1030 track1 heiler
1030 track1 heiler
 
Guide for building GLMS
Guide for building GLMSGuide for building GLMS
Guide for building GLMS
 
What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?
What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?
What is Isotonic Regression and How Can a Business Utilize it to Analyze Data?
 
1440 track3 galusha
1440 track3 galusha1440 track3 galusha
1440 track3 galusha
 
Multiple Linear Regression.pptx
Multiple Linear Regression.pptxMultiple Linear Regression.pptx
Multiple Linear Regression.pptx
 
Further6 displaying bivariate data
Further6  displaying bivariate dataFurther6  displaying bivariate data
Further6 displaying bivariate data
 
Building a Regression Model using SPSS
Building a Regression Model using SPSSBuilding a Regression Model using SPSS
Building a Regression Model using SPSS
 
Environment&EconomicGrowth
Environment&EconomicGrowthEnvironment&EconomicGrowth
Environment&EconomicGrowth
 
Regression and Classification Analysis
Regression and Classification AnalysisRegression and Classification Analysis
Regression and Classification Analysis
 

More from suncil0071

Conditional probability
Conditional probabilityConditional probability
Conditional probability
suncil0071
 
Basics of probability
Basics of probabilityBasics of probability
Basics of probability
suncil0071
 
Cluster and multistage sampling
Cluster and multistage samplingCluster and multistage sampling
Cluster and multistage samplingsuncil0071
 
Stratified sampling
Stratified samplingStratified sampling
Stratified samplingsuncil0071
 
Simple random sampling
Simple random samplingSimple random sampling
Simple random samplingsuncil0071
 
Simple random sampling
Simple random samplingSimple random sampling
Simple random samplingsuncil0071
 
Ideas to understand
Ideas to understandIdeas to understand
Ideas to understandsuncil0071
 
Understanding randomness
Understanding randomnessUnderstanding randomness
Understanding randomnesssuncil0071
 
Measures of central tendency mean
Measures of central tendency  meanMeasures of central tendency  mean
Measures of central tendency mean
suncil0071
 
Histograms & stem plots
Histograms  & stem plotsHistograms  & stem plots
Histograms & stem plots
suncil0071
 

More from suncil0071 (12)

Conditional probability
Conditional probabilityConditional probability
Conditional probability
 
Basics of probability
Basics of probabilityBasics of probability
Basics of probability
 
Who’s who
Who’s whoWho’s who
Who’s who
 
Cluster and multistage sampling
Cluster and multistage samplingCluster and multistage sampling
Cluster and multistage sampling
 
Stratified sampling
Stratified samplingStratified sampling
Stratified sampling
 
Simple random sampling
Simple random samplingSimple random sampling
Simple random sampling
 
Simple random sampling
Simple random samplingSimple random sampling
Simple random sampling
 
Ideas to understand
Ideas to understandIdeas to understand
Ideas to understand
 
Understanding randomness
Understanding randomnessUnderstanding randomness
Understanding randomness
 
Correlation
CorrelationCorrelation
Correlation
 
Measures of central tendency mean
Measures of central tendency  meanMeasures of central tendency  mean
Measures of central tendency mean
 
Histograms & stem plots
Histograms  & stem plotsHistograms  & stem plots
Histograms & stem plots
 

Recently uploaded

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 

Recently uploaded (20)

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 

Linear regression

  • 1.
  • 2. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Chapter 8 Linear Regression
  • 3. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 3 Fat versus Protein: An Example  The following is a scatterplot of total fat versus protein for 30 items on the Burger King menu:
  • 4. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 4 The Linear Model  Correlation says “There seems to be a linear association between these two variables,” but it doesn’t tell what that association is.  We can say more about the linear relationship between two quantitative variables with a model.  A model simplifies reality to help us understand underlying patterns and relationships.
  • 5. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 5 The Linear Model (cont.)  The linear model is just an equation of a straight line through the data.  The points in the scatterplot don’t all line up, but a straight line can summarize the general pattern.  The linear model can help us understand how the values are associated.
  • 6. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 6 Residuals  The model won’t be perfect, regardless of the line we draw.  Some points will be above the line and some will be below.  The estimate made from a model is the predicted value (denoted as ).ˆy
  • 7. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 7 Residuals (cont.)  The difference between the observed value and its associated predicted value is called the residual.  To find the residuals, we always subtract the predicted value from the observed one: ˆresidual observed predicted y y= − = −
  • 8. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 8 Residuals (cont.)  A negative residual means the predicted value’s too big (an overestimate).  A positive residual means the predicted value’s too small (an underestimate).
  • 9. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 9 “Best Fit” Means Least Squares  Some residuals are positive, others are negative, and, on average, they cancel each other out.  So, we can’t assess how well the line fits by adding up all the residuals.  Similar to what we did with deviations, we square the residuals and add the squares.  The smaller the sum, the better the fit.  The line of best fit is the line for which the sum of the squared residuals is smallest.
  • 10. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 10 The Least Squares Line  We write our model as  This model says that our predictions from our model follow a straight line.  If the model is a good one, the data values will scatter closely around it. 0 1 ˆy b b x= +
  • 11. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 11 The Least Squares Line (cont.)  In our model, we have a slope (b1):  The slope is built from the correlation and the standard deviations:  Our slope is always in units of y per unit of x. 1 y x s b r s =
  • 12. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 12 The Least Squares Line (cont.)  In our model, we also have an intercept (b0).  The intercept is built from the means and the slope:  Our intercept is always in units of y. 0 1b y b x= −
  • 13. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 13 Fat versus Protein: An Example  The regression line for the Burger King data fits the data well:  The equation is  The predicted fat content for a BK Broiler chicken sandwich is 6.8 + 0.97(30) = 35.9 grams of fat.
  • 14. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 14 The Least Squares Line (cont.)  Since regression and correlation are closely related, we need to check the same conditions for regressions as we did for correlations:  Quantitative Variables Condition  Straight Enough Condition  Outlier Condition
  • 15. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 15 Correlation and the Line  Moving one standard deviation away from the mean in x moves us r standard deviations away from the mean in y.  This relationship is shown in a scatterplot of z-scores for fat and protein:
  • 16. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 16 Correlation and the Line (cont.)  Put generally, moving any number of standard deviations away from the mean in x moves us r times that number of standard deviations away from the mean in y.
  • 17. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 17 How Big Can Predicted Values Get?  r cannot be bigger than 1 (in absolute value), so each predicted y tends to be closer to its mean (in standard deviations) than its corresponding x was.  This property of the linear model is called regression to the mean; the line is called the regression line.
  • 18. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 18 Residuals Revisited  The linear model assumes that the relationship between the two variables is a perfect straight line. The residuals are the part of the data that hasn’t been modeled. Data = Model + Residual or (equivalently) Residual = Data – Model Or, in symbols, ˆe y y= −
  • 19. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 19 Residuals Revisited (cont.)  Residuals help us to see whether the model makes sense.  When a regression model is appropriate, nothing interesting should be left behind.  After we fit a regression model, we usually plot the residuals in the hope of finding…nothing.
  • 20. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 20 Residuals Revisited (cont.)  The residuals for the BK menu regression look appropriately boring:
  • 21. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 21 R2 —The Variation Accounted For  The variation in the residuals is the key to assessing how well the model fits.  In the BK menu items example, total fat has a standard deviation of 16.4 grams. The standard deviation of the residuals is 9.2 grams.
  • 22. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 22 R2 —The Variation Accounted For (cont.)  If the correlation were 1.0 and the model predicted the fat values perfectly, the residuals would all be zero and have no variation.  As it is, the correlation is 0.83—not perfection.  However, we did see that the model residuals had less variation than total fat alone.  We can determine how much of the variation is accounted for by the model and how much is left in the residuals.
  • 23. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 23 R2 —The Variation Accounted For (cont.)  The squared correlation, r2 , gives the fraction of the data’s variance accounted for by the model.  Thus, 1– r2 is the fraction of the original variance left in the residuals.  For the BK model, r2 = 0.832 = 0.69, so 31% of the variability in total fat has been left in the residuals.
  • 24. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 24 R2 —The Variation Accounted For (cont.)  All regression analyses include this statistic, although by tradition, it is written R2 (pronounced “R-squared”). An R2 of 0 means that none of the variance in the data is in the model; all of it is still in the residuals.  When interpreting a regression model you need to Tell what R2 means.  In the BK example, 69% of the variation in total fat is accounted for by the model.
  • 25. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 25 How Big Should R2 Be?  R2 is always between 0% and 100%. What makes a “good” R2 value depends on the kind of data you are analyzing and on what you want to do with it.  The standard deviation of the residuals can give us more information about the usefulness of the regression by telling us how much scatter there is around the line.
  • 26. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 26  Along with the slope and intercept for a regression, you should always report R2 so that readers can judge for themselves how successful the regression is at fitting the data.  Statistics is about variation, and R2 measures the success of the regression model in terms of the fraction of the variation of y accounted for by the regression. How Big Should R2 Be (cont)?
  • 27. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 27 Regression Assumptions and Conditions  Quantitative Variables Condition:  Regression can only be done on two quantitative variables, so make sure to check this condition.  Straight Enough Condition:  The linear model assumes that the relationship between the variables is linear.  A scatterplot will let you check that the assumption is reasonable.
  • 28. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 28 Regressions Assumptions and Conditions (cont.)  It’s a good idea to check linearity again after computing the regression when we can examine the residuals.  You should also check for outliers, which could change the regression.  If the data seem to clump or cluster in the scatterplot, that could be a sign of trouble worth looking into further.
  • 29. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 29  If the scatterplot is not straight enough, stop here.  You can’t use a linear model for any two variables, even if they are related.  They must have a linear association or the model won’t mean a thing.  Some nonlinear relationships can be saved by re- expressing the data to make the scatterplot more linear. Regressions Assumptions and Conditions (cont.)
  • 30. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 30  Outlier Condition:  Watch out for outliers.  Outlying points can dramatically change a regression model.  Outliers can even change the sign of the slope, misleading us about the underlying relationship between the variables. Regressions Assumptions and Conditions (cont.)
  • 31. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 31 Reality Check: Is the Regression Reasonable?  Statistics don’t come out of nowhere. They are based on data.  The results of a statistical analysis should reinforce your common sense, not fly in its face.  If the results are surprising, then either you’ve learned something new about the world or your analysis is wrong.  When you perform a regression, think about the coefficients and ask yourself whether they make sense.
  • 32. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 32 What Can Go Wrong?  Don’t fit a straight line to a nonlinear relationship.  Beware extraordinary points (y-values that stand off from the linear pattern or extreme x-values).  Don’t extrapolate beyond the data—the linear model may no longer hold outside of the range of the data.  Don’t infer that x causes y just because there is a good linear model for their relationship—association is not causation.  Don’t choose a model based on R2 alone.
  • 33. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 33 What Have We Learned?  When the relationship between two quantitative variables is fairly straight, a linear model can help summarize that relationship.  The regression line doesn’t pass through all the points, but it is the best compromise in the sense that it has the smallest sum of squared residuals.
  • 34. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 34 What Have We Learned? (cont.)  The correlation tells us several things about the regression:  The slope of the line is based on the correlation, adjusted for the units of x and y.  For each SD in x that we are away from the x mean, we expect to be r SDs in y away from the y mean.  Since r is always between -1 and +1, each predicted y is fewer SDs away from its mean than the corresponding x was (regression to the mean).  R2 gives us the fraction of the response accounted for by the regression model.
  • 35. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 35 What Have We Learned? (cont.)  The residuals also reveal how well the model works.  If a plot of the residuals against predicted values shows a pattern, we should re-examine the data to see why.  The standard deviation of the residuals quantifies the amount of scatter around the line.
  • 36. Copyright © 2012 Pearson Canada Inc., Toronto, Ontario Slide 8- 36  The linear model makes no sense unless the Linear Relationship Assumption is satisfied.  Also, we need to check the Straight Enough Condition and Outlier Condition with a scatterplot.  For the standard deviation of the residuals, we must make the Equal Variance Assumption. We check it by looking at both the original scatterplot and the residual plot for Does the Plot Thicken? Condition. What Have We Learned? (cont.)