• No results found

Chapter 8 Linear Regression What I will know and be able to do Identify the response (y) and explanatory (x) variables in context and utilize a regression to summarize a linear relationship between the variables when possible and interpret what the line r

N/A
N/A
Protected

Academic year: 2020

Share "Chapter 8 Linear Regression What I will know and be able to do Identify the response (y) and explanatory (x) variables in context and utilize a regression to summarize a linear relationship between the variables when possible and interpret what the line r"

Copied!
71
0
0

Loading.... (view fulltext now)

Full text

(1)

Chapter 8

Linear Regression

What I will know and be able to do

Identify the response (y) and explanatory (x) variables in

context and utilize a regression to summarize a linear

relationship between the variables when possible and

interpret what the line represents.

Assignment:

(2)

Fat Versus Protein: An Example

• The following is a scatterplot of total fat versus protein for 30 items on the Burger King menu:

(3)

The Linear Model

• The correlation in this example is 0.83. It 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.

(4)

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 with only a couple of parameters.

• The linear model can help us understand how the values are associated.

(5)

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 ).

Slide 8 - 5

ˆ

(6)

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:

(7)

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).

• In the figure, the estimated fat of the BK Broiler chicken sandwich is 36 g, while the true value of fat is 25 g, so the residual is –11 g of fat.

(8)

“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, the least squares line.

(9)

Correlation and the Line

• The figure shows the scatterplot of z-scores for fat and protein.

• If a burger has average protein content, it should have about average fat content

too.

• Moving one standard deviation away from the mean in x moves us r standard deviations away from the mean in y.

• 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.

(10)

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.

(11)

The Regression Line in Real Units

• Remember from Algebra that a straight line can be written as:

• In Statistics we use a slightly different notation:

• We write to emphasize that the points that satisfy this equation are just our predicted values, not the actual data values.

• 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.

Slide 8 - 11

ymxb

ˆ

yb0b1x ˆ

(12)

The Regression Line in Real Units(cont.)

• We write b1 and b0 for the slope and intercept of the line. • b1 is the slope, which tells us how rapidly changes with

respect to x.

b0 is the y-intercept, which tells where the line crosses (intercepts) the y-axis.

Slide 8 - 12 ˆ

y

ˆ

(13)

• 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.

Slide 8 - 13

b

1

r

s

y

s

x

(14)

• 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.

Slide 8 - 14

b

0

y

b

1

x

(15)

Regression line equation

where

x

b

b

y

ˆ

0

1

x y

s

s

r

(16)

Regression line equation

b

1

= slope of line.

• For every unit increase in x, changes by the amount of the slope.

• Very important for interpreting data.

b

0

=

y

-intercept of line.

• The value of when x = 0.

• Usually not important for interpreting data. • Values of x are usually not close to 0.

yˆ

(17)

Fat Versus Protein: An Example

• The regression line for the Burger King data fits the data well:

• The equation is

Slide 8 - 17

(18)
(19)
(20)

Example 1: Calculating the regression line.

Degree Days vs. Gas Usage

9953

.

0

,

37

.

3

,

74

.

17

,

31

.

5

,

31

.

22

y

s

s

r

x

x y

x y

(21)

• Degree Days vs. Gas Usage 9953 . 0 , 37 . 3 , 74 . 17 , 31 . 5 , 31 .

22    

y s s r

x x y

19 . 0 74 . 17 37 . 3 ) 9953 . 0 (

1   

x y s s r b

(22)

• Degree Days vs. Gas Usage 9953 . 0 , 37 . 3 , 74 . 17 , 31 . 5 , 31 .

22    

y s s r

x x y

19 . 0 74 . 17 37 . 3 ) 9953 . 0 (

1   

x y s s r b

x

b

y

b

0

1

(23)

• Degree Days vs. Gas Usage 9953 . 0 , 37 . 3 , 74 . 17 , 31 . 5 , 31 .

22    

y s s r

x x y

19 . 0 74 . 17 37 . 3 ) 9953 . 0 (

1   

x y s s r b

07

.

1

)

31

.

22

(

19

.

0

31

.

5

1

0

y

b

x

b

(24)

• Don’t forget to write the equation.

)

(deg

19

.

0

07

.

1

days

gas

(25)

Example 1 Interpretations

Slope

• For every one unit increase in degree days, there is a predicted 0.19 unit increase in predicted gas usage.

Intercept

(26)

Example 1 - Prediction

Use regression equation to predict

y

from

x

.

• Ex. Predicted gas consumption when degree days = 40?

• Ex. Predicted gas consumption when degree days = 20?

67

.

8

6

.

7

07

.

1

)

40

(

19

.

0

07

.

1

ˆ

y

87

.

4

8

.

3

07

.

1

)

20

(

19

.

0

07

.

1

ˆ

(27)

Example: pg. 156 #9

A random sample of records of sales of homes from Feb. 15 to Apr. 30, 1993, from the files maintained by the Albuquerque Board of Realtors gives the price (in thousands of dollars) and size (in square feet) of 117 homes. A regression analysis gives us the model:

a. What does the slope of this line say about housing prices and house size?

size

ce

i

pr

ˆ

47

.

82

0

.

061

(28)

Example: pg. 156 #9

A random sample of records of sales of homes from Feb. 15 to Apr. 30, 1993, from the files maintained by the Albuquerque Board of Realtors gives the price (in thousands of dollars) and size (in square feet) of 117 homes. A regression analysis gives us the model:

b. What price would you predict to pay for a 3000 square foot home?

size

ce

i

pr

ˆ

47

.

82

0

.

061

(29)

Example: pg. 156 #9

A random sample of records of sales of homes from Feb. 15 to Apr. 30, 1993, from the files maintained by the Albuquerque Board of

Realtors gives the price (in thousands of dollars) and size (in square feet) of 117 homes. A regression analysis gives us the model:

c. A real estate agent shows a potential buyer a 1200 sq-ft home with an asking price that is $6000 less than one would expect to pay for a house of that size. What is the asking price?

size

ce

i

pr

ˆ

47

.

82

0

.

061

(30)

Example: Success in College (pg. 157 #18)

Colleges use SAT scores in the admissions process because they believe these scores provide some insight into how a high school student will perform at the college

level. Suppose that entering freshmen at a certain college have mean combined SAT scores of 1833 with a standard deviation of 123. In the first semester these students attained a mean GPA of 2.66 with a standard deviation of 0.56. A scatterplot

showed the association to be reasonably linear, and the correlation between SAT score and GPA was 0.47.

a. Write the equation of the regression line.

(31)

Example: Success in College (pg. 157 #18)

Colleges use SAT scores in the admissions process because they believe these scores provide some insight into how a high school student will perform at the college

level. Suppose that entering freshmen at a certain college have mean combined SAT scores of 1833 with a standard deviation of 123. In the first semester these students attained a mean GPA of 2.66 with a standard deviation of 0.56. A scatterplot

showed the association to be reasonably linear, and the correlation between SAT score and GPA was 0.47.

b. Explain what the intercept of the regression line indicates.

(32)

Example: Success in College (pg. 157 #18)

Colleges use SAT scores in the admissions process because they believe these scores provide some insight into how a high school student will perform at the college

level. Suppose that entering freshmen at a certain college have mean combined SAT scores of 1833 with a standard deviation of 123. In the first semester these students attained a mean GPA of 2.66 with a standard deviation of 0.56. A scatterplot

showed the association to be reasonably linear, and the correlation between SAT score and GPA was 0.47.

c. Interpret the slope of the regression line.

(33)

Example: Success in College (pg. 157 #18)

Colleges use SAT scores in the admissions process because they believe these scores provide some insight into how a high school student will perform at the college

level. Suppose that entering freshmen at a certain college have mean combined SAT scores of 1833 with a standard deviation of 123. In the first semester these students attained a mean GPA of 2.66 with a standard deviation of 0.56. A scatterplot

showed the association to be reasonably linear, and the correlation between SAT score and GPA was 0.47.

d. Predict the GPA of a freshman who scored a combined 2100.

(34)

Example: Success in College (pg. 157 #18)

Colleges use SAT scores in the admissions process because they believe these scores provide some insight into how a high school student will perform at the college

level. Suppose that entering freshmen at a certain college have mean combined SAT scores of 1833 with a standard deviation of 123. In the first semester these students attained a mean GPA of 2.66 with a standard deviation of 0.56. A scatterplot

showed the association to be reasonably linear, and the correlation between SAT score and GPA was 0.47.

e. Based on these statistics, how effective do you think SAT scores would be in predicting academic success? Explain.

R2 is only .221. SAT is probably only somewhat useful. There are many

(35)

Plotting the regression line

• Find two points on line.

• Pick two x values

• Find predicted for each x value.

• For example:

x = 20, =4.87 and x = 40, = 8.67

• Plot two points on graph.

• Make line through two points. • Regression line .

yˆ

yˆ

(36)

Properties of regression line

Regression line always goes through point

r

is connected to the value of

b

1

.

r has same sign as b1.

)

,

(

x

y

x y

(37)

Properties of regression line

The values of the

y

variable vary.

Regression line tries to explain variation

of

y

through its relationship with

x

.

• Not perfectly – points not exactly on line.

• Points close to line: regression explains variation of y well.

(38)

Properties of regression line

How much variation can we explain with our

regression?

Answer:

R

2

• Percent of variation in y that is explained by the linear relationship with x.

(39)

Go back to Degree Days vs. Gas Usage

• R2 = r2

• Since r = 0.9953,

(40)

Example: Roller Coasters

People who responded to a July 2004 Discovery Channel poll names the 10 best roller coasters in the United States. A table in Chapter 7, Exercise 33 shows the length of the initial drop (in feet) and the

duration of the ride (in seconds). A regression to predict duration from drop has R2=12.4%.

a. What are the variables and units in this regression?

(41)

Example: Roller Coasters

People who responded to a July 2004 Discovery Channel poll names the 10 best roller coasters in the United States. A table in Chapter 7, Exercise 33 shows the length of the initial drop (in feet) and the

duration of the ride (in seconds). A regression to predict duration from drop has R2=12.4%.

b. Write a sentence (in context) summarizing what the R2 says

about this regression.

12.4% of the variation in the duration of the ride on the

(42)

Example: Roller Coasters

People who responded to a July 2004 Discovery Channel poll names the 10 best roller coasters in the United States. A table in Chapter 7, Exercise 33 shows the length of the initial drop (in feet) and the

duration of the ride (in seconds). A regression to predict duration from drop has R2=12.4%.

c. What is the correlation between drop and duration? Interpret in context.

r = 𝑅2 = 0.352

The correlation coefficient of .352 shows a weak, positive linear relationship between duration and drop of roller

(43)

Residuals

• 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,

Slide 8 - 43

(44)

Residuals (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.

(45)

Example: Calculating Residuals

Degree Days vs. Gas Usage

Find the residual for the point (30,6.4)

Explain what this residual means in context.

x

y

ˆ

1

.

07

0

.

19

(46)

Example: Calculating Residuals

Degree Days vs. Gas Usage

Find the residual for the point (30,6.4)

Find the residual for the point (13,4.0)

x

y

ˆ

1

.

07

0

.

19

(47)

Residual Plots

Scatterplot

• Explanatory variable (x) on horizontal axis. • Residuals (e) on vertical axis.

• Horizontal line at residual = 0.

Good Residual Plot

(48)

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

(49)

Residuals (cont.)

• The residuals for the BK menu regression look appropriately boring:

(50)
(51)

Interpreting Residual Plots

Curved Pattern

• relationship is not linear.

Increasing spread about line as

x

increases.

• Predictions of y for larger x will be less accurate.

Decreasing spread about line as

x

increases.

(52)

The ages (in months) and heights (in inches) of seven children are given.

x 16 24 42 60 75 102 120

y 24 30 35 40 48 56 60

Find the LSRL.

Interpret the slope, y intercept, correlation coefficient, and R2 in the context of the problem. Is the LSRL a good model?

(53)
(54)

The Residual Standard Deviation

• The standard deviation of the residuals, se, measures how much the points spread around the regression line.

• Check to make sure the residual plot has about the same amount of scatter throughout. Check the Equal Variance Assumption with the

Does the Plot Thicken? Condition.

• We can interpret se in the context of a data set. It is the typical error in the predictions made by the regression line. It represents the typical distance a actual “y” value is away from the predicted “y” value.

(55)
(56)

R

2

—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.

(57)

R

2

—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.

(58)

• 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.

Slide 8 - 58

(59)

All regression analyses include this statistic, although

by tradition, it is written

R

2

(pronounced “

R

-squared”). An

R

2

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

R

2

means.

• In the BK example, 69% of the variation in total fat is accounted for by variation in the protein content.

Slide 8 - 59

(60)

How Big Should

R

2

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.

(61)

Reporting

R

2

• 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.

(62)

Assumptions and Conditions

Quantitative Variables Condition:

• Regression can only be done on two quantitative variables (and not two categorical 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.

(63)

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.

Slide 8 - 63

(64)

It’s a good idea to check linearity again

after

computing the regression when we can examine the

residuals.

Does the Plot Thicken? Condition:

• Look at the residual plot -- for the standard deviation of

the residuals to summarize the scatter, the residuals should share the same spread. Check for changing spread in the residual scatterplot.

Slide 8 - 64

(65)

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.

If the data seem to clump or cluster in the scatterplot,

that could be a sign of trouble worth looking into

further.

Slide 8 - 65

(66)

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.

(67)

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.

(68)

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.

(69)

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.

(70)

What have we learned?

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.

(71)

What have we learned? (cont.)

• 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.

References

Related documents

Results of the survey are categorized into the following four areas: primary method used to conduct student evaluations, Internet collection of student evaluation data,

innovation in payment systems, in particular the infrastructure used to operate payment systems, in the interests of service-users 3.. to ensure that payment systems

UPnP Control Point (DLNA) Device Discovery HTTP Server (DLNA, Chormecast, AirPlay Photo/Video) RTSP Server (AirPlay Audio) Streaming Server.. Figure 11: Simplified

An analysis of the economic contribution of the software industry examined the effect of software activity on the Lebanese economy by measuring it in terms of output and value

The directive establishes a framework for achieving or maintaining a good environmental status (GES) of the marine environment by the EU Member States by 2020. A good

Beside the advantages of using the know-how and the resources of the cloud services using cloud services incorporates also several risks: The cloud user needs

Success Scenario: (open, IaaS, PaaS, SaaS): An unidentified-user accesses a cloud- provider’s account creation web page. The unidentified-user provides:

14 When black, Latina, and white women like Sandy and June organized wedding ceremonies, they “imagine[d] a world ordered by love, by a radical embrace of difference.”