Download presentation

Presentation is loading. Please wait.

1
**Chapter 8 Linear Regression**

AP Statistics Chapter 8 Linear Regression

2
**Objectives: Linear model Predicted value Residuals Least squares**

Regression to the mean Regression line Line of best fit Slope intercept se R2

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
The Linear Model The correlation in this example is 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.

5
The Linear Model 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.

6
The Linear Model Unlike correlation, the linear model requires that there be an explanatory variable and a response variable. Linear Model A line that describes how a response variable y changes as an explanatory variable x changes. Used to predict the value of y for a given value of x. Linear model of the form:

7
The Linear Model 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 ).

8
**The Linear Model The predicted value:**

Putting a hat on y is standard statistics notation to indicate that something has been predicted by a model. Whenever you see a hat over a variable name or symbol, you can assume it is the predicted version of that variable or symbol.

9
Example: Linear Model Observed Values Linear Model Predicted Values

10
The Linear Model The linear model will not pass exactly through all the points, but should be as close as possible. A good linear model makes the vertical distances between the observed points and the predicted points (the error) as small as possible. This “error” doesn’t mean it’s a mistake. Statisticians often refer to variability not explained by the model as error.

11
The Linear Model Predicted value ŷ (y-hat) Observed value y Error = observed – predicted (y – ŷ)

12
Residuals This “error”, 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:

13
**Residuals Symbol for residual is: e Why e for residual?**

Because r is already taken. No, the e stands for “error.” So,

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

15
**“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.

16
**Least – Squares Regression Line (LSRL)**

The LSRL is the line that minimizes the sum of the squared residuals between the observed and predicted y values (y – ŷ).

17
**Correlation and the Line**

What we know about correlation from chapter 7 can lead us to the equation of the linear model. Start with a scatterplot of standardized values. Standardized scatterplot – zy (standardized fat) vs zx (standardized protein). Original scatterplot - fat versus protein for 30 items on the Burger King menu.

18
**Correlation and the Line**

What line would you choose to model the relationship of standardized values? Start at the center of the line. If an item has average protein , should it have average fat ? Yes, so the line should pass through the point This is the first property of the line we are looking for, it must always pass through the point In the plot of z-scores, the point is the origin and then the line passes through the origin (0, 0).

19
**Correlation and the Line**

The equation for a line that passes through the origin is y = mx. So the equation on our standardized plot will be We use to indicate that the point on the line is the predicted value , not the actual value zy.

20
**Correlation and the Line**

Many lines with different slopes pass through the origin. Which one best fits our data? That is, which slope determines the line that minimizes the sum of the squared residuals? It turns out that the best choice for slope is the correlation coefficient r. So, the equation of the linear model is

21
**Correlation and the Line**

What does this tell us? 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.

22
**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.

23
The Term Regression Sir Francis Galton related the heights of sons to the heights of their fathers with a regression line. The slope of the line was less than one. That is, sons of tall fathers were tall, but not as much above the mean height as their fathers had been above their mean. Sons of short fathers were short, but generally not as far from their mean as their fathers. Galton interpreted the slope correctly as indicating a “regression” toward the mean height. And regression stuck as a description of the method he used to find the line.

24
**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.

25
**The Regression Line in Real Units**

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.

26
**The Regression Line in Real Units**

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.

27
**The Regression Line in Real Units**

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.

28
**Example: Fat Versus Protein**

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 (with 30 g of protein) is (30) = 35.9 grams of fat.

29
**Calculate Regression Line by Hand**

First calculate the following for the data; The means The standard deviations The correlation r Then the LSRL is Slope y- - intercept

30
**Calculate Regression Line on TI-83/84**

Enter the data into lists: explanatory variable L1 and response L2 STAT/CALC/LinReg(a+bx)/L1,L2,VARS/Y-VARS/FUNCTION/Y1 Your display on the screen shows LinReg(a+bx)L1,L2,Y1. This creates the LSRL and stores it as function Y1. The LSRL will now overlay your scatterplot.

31
**Graphing the LSRL by Hand**

The equation of the LSRL makes prediction easy. Just substitute an x-value into the equation and calculate the corresponding y-value. Use the equation to calculate two points on the line. One at each end of the line (ie. low x-value and high x-value). Plot the two points and draw a line.

32
**Example: Calculate the LSRL by hand and on the calculator (r = -.64).**

33
**LSRL by Hand Calculate the slope Calculate the y-intercept**

From 2-VAR Stats Calculate the y-intercept

34
**LSRL by Hand - Continued**

Then the LRSL is; Or in the context of the problem

35
**By Calculator STAT/CALC/LinReg(a+bx)/L1,L2,VARS/Y-VARS/FUNCTION/Y1 or**

y=a+bx a= b= r2= r= or

36
Your Turn: Calculate the linear model by hand using r=.894. Solution:

37
**Your Turn: Calculate and graph the linear model using the Ti-83/84.**

Year Powerboat Reg. (1000s) Manatees Killed 1977 447 13 1978 460 21 1979 481 24 1980 498 16 1981 513 1982 512 20 1983 526 15 1984 559 34 1985 585 33 1986 614 1987 645 39 1988 675 43 1989 711 50 1990 719 47 Calculate and graph the linear model using the Ti-83/84. Solution:

38
Facts About LSRL The distinction between explanatory and response variables is essential in regression. LSR uses the distances of the data points from the line in only the y direction. If the 2 variables are reversed, you get a different LSRL. The LSRL always passes through the point

39
More Facts on LSRL There is a close connection between correlation and the slope of the LSRL. A change of one standard deviation in x corresponds to a change of r standard deviations in y.

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

41
Residuals Revisited 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.

42
Residuals Revisited The residuals for the BK menu regression look appropriately boring: The sum of the residuals is always equal to zero.

43
Finding Residuals Use the LSRL to find predicted values for each observed value and calculate the corresponding residual. Example: Data – (0,1) (1,6) (2,8) (3,13) (4,13) LSRL ŷ = x

44
Calculated Residuals

45
Residual Plot Is a scatterplot of the residuals against the explanatory variable (x). The residuals are plotted on the vertical axis. The explanatory variable (x) is plotted on the horizontal axis. The residual plot helps us assess the fit of a regression line.

46
Residual Plot Whenever you calculate a LSRL on the TI-83/84, the calculator automatically calculates the residuals for that particular LSRL and stores them in a list named RESIDS. To create a residual plot on the calculator, make sure you calculate the LSRL first.

47
Another Example - Data

48
Scatterplot

49
Residual Plot

50
**Your Turn: Plot the Residual Plot. Year Powerboat Reg. (1000s)**

Manatees Killed 1977 447 13 1978 460 21 1979 481 24 1980 498 16 1981 513 1982 512 20 1983 526 15 1984 559 34 1985 585 33 1986 614 1987 645 39 1988 675 43 1989 711 50 1990 719 47 Plot the Residual Plot.

51
**What to Look for on the Residual Plot**

Random points, no pattern – data fits the linear model. Curved pattern – the relationship is not linear. Increasing (or decreasing) spread about the zero line as x increases – Prediction of y will be less (more) accurate for larger values of x.

52
**Random Points, No Pattern**

53
Curved Pattern

54
Increasing Spread

55
Residual Plot Individual points with large residuals – these points are outliers in the vertical (y) direction. Outlier in the y direction

56
Residual Plot Individual points that are extreme in the x direction – these points are outliers in the horiztonal (x) direction, such points may not have large residuals, but they can be very important. Outlier in the x direction

57
Residual Plot No regression analysis is complete without a display of the residuals to check that the model is reasonable. Because the residuals are the “left over” after the model describes the relationship, they often reveal subtleties that were not clear from a plot of the original data.

58
**Importance of Checking the Residual Plot**

The scatterplot of the data seems to indicate that a linear model will be a good fit.

59
Next, the LSRL The LSRL ŷ = x yieds an r = and r2 =

60
Now the Residual Plot The residual plot, however, displays a distinctly curved pattern, indicating that a nonlinear model will be a better fit for the data. The pattern you see in the residual hints at a model you may need to fit your data.

61
**Moral Always look at a residual plot of your data!**

Any function is linear if plotted over a small enough interval. A residual plot will help you to see patterns in the data that may not be apparent in the original graph.

62
**The Residual Standard Deviation**

If the residual plot shows no interesting pattern, we can look at how large the residuals are. After all, we are trying to make them as small as possible. Since the mean of the residuals is always zero, it makes sense to look at how they vary or their standard deviation.

63
**The Residual Standard Deviation**

The standard deviation of the residuals, se, measures how much the points spread around the regression line. For se to make sense, the residuals should all share the same variation or spread. 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 check the Equal Variance Assumption in the original scatterplot or in the residual plot.

64
**Equal Variance Assumption**

Use either the original scatterplot or the residual plot. Scatterplot: Variation about the regression line is about the same. Residual plot: Variation about the zero residual line is about the same. Therefore, both plots show the residuals meet the equal Variance Assumption.

65
**The Residual Standard Deviation**

We estimate the SD of the residuals using: We don’t need to subtract the mean because the mean of the residuals We divide by n-2 rather than n-1. We used n-1 for s when we estimated the mean (used for µ). Now we are estimating both slope and the y-intercept, so we use n-2. We subtract one more for each parameter we estimate.

66
**The Residual Standard Deviation**

Then it’s a good to make a histogram of the residuals. It should look unimodal and roughly symmetric. Then we can apply the Rule to see how well the regression model describes the data.

67
**R2—The Variation Accounted For**

The variation in the residuals is the key to assessing how well the model fits. Compare the variation of the response variable with the variation of the residuals. 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.

68
**R2—The Variation Accounted For**

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

69
**R2—The Variation Accounted For**

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.69, so 31% of the variability in total fat has been left in the residuals.

70
**R2—The Variation Accounted For**

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, according to the model 69% of the variation in total fat is accounted for by variation in the protein content.

71
**R2—The Variation Accounted For**

The R2 is the Coefficient of Determination, indicates how well the model (the LSRL) fits the data. R2 values are between 0 and 1. The closer R2 is to 1, the better the regression line explains the response. R2 gives the fraction of the variability of y that is explained by the least squares linear regression on x. Example: R2=.73 means 73% of the total variation in y is explained by the linear model.

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

73
Reporting R2 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.

74
**More on Outliers Outlying points can strongly influence regression.**

A point can be an outlier because its x-value is extraordinary, because its y-value is extraordinary, or because it deviates from the overall pattern of the data. A point has leverage and is call an influential point if its removal causes the slope of the regression line to change dramatically.

75
More on Outliers Although the indicated point lies outside the overall pattern of the data set, its removal has little effect on the regression line. It would not be considered an influential point.

76
More on Outliers The point in the lower right-hand corner of the graph is an outlier in the x-direction. Its removal causes the slope of the regression line to change dramatically. This point has leverage and is an influential point.

77
**Influential Point - Summary**

As seen in the prior examples, points that are outliers in the x-direction on a scatterplot are often influential on the calculation of the LSRL or linear model.

78
**Regression: 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.

79
**Regression: Assumptions and Conditions**

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.

80
**Regression: Assumptions and Conditions**

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.

81
**Regression: Assumptions and Conditions**

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.

82
**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.

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

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

85
What have we learned? 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.

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

87
What have we learned? 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.

88
**Put it Altogether Example**

Review

89
**Example: Creating and Using a Least Squares Regression Line**

A student wanted to see how good she was at predicting distances measured in meters. She randomly selected 7 distances to estimate. After recording her estimated distances, she used a range finder to find the actual distances. Next is a scatterplot of the Actual Distances vs. Estimated Distances and the corresponding residual plot.

90
Make a Picture

91
**Check Conditions for Regression**

Quantitative Variables Condition: Actual Distance and Estimated Distance are quantitative. Straight Enough Condition: The data follow a straight line pattern. Outlier Condition: There are no outliers in the data. Does the Plot Thicken? Condition: The residual plot shows no obvious patterns. The scatterplot follows a linear pattern with no apparent outliers. The residual plot shows no discernable pattern, so a linear model is appropriate.

92
Numerical Analysis Use your calculator to find the equation of the LSRL, if given the data; however, you need to be able to read various computer outputs to be successful on the AP Statistics exam. There will be things on the printout that you might not be familiar with, such as the F-ratio. Focus on finding the information you need to write the equation of the LSRL (ie. Slope & y-intercept).

93
**Typical Questions on the Regression**

State the equation of the LSRL. Define any variables used.

94
**Answer The equation of the LSRL is**

= (estimated distance) or ŷ = x, where x=estimated distance & ŷ=actual distance

95
Question Interpret the slope and the y-intercept of the LSRL.

96
Answer In the context of the problem: For every additional meter of estimated distance, the predicted actual distance increases by approximately 0.92 meters. (remember, all interpretations must be given in context).

97
Continued The y-intercept of is the predicted value of y when x is equal to zero. = = (0) = In the context of the problem: A y-intercept of represents the predicted distance in meters when the distance between the person and the object being measured is zero – the person is holding the object. This value does not make sense in the context of this problem since a person holding an object would not make a prediction other than zero.

98
Question State and interpret the correlation coefficient.

99
Answer The correlation coefficient is r, and since we are given that R2 = 91.2% or 0.912, then (r is positive because the slope is positive). The correlation coefficient indicates that there is a strong, positive, linear relationship between the estimated distance and the predicted actual measured distance.

100
Question State and interpret the coefficient of determination.

101
**Answer The coefficient of determination, R2 = .912.**

Tells us that approximately 91% of the variability in the actual distance can be explained by a linear relationship between the actual distance and the estimated distance.

102
Question Predict the actual distance from an object when the estimated distance is 4 meters.

103
Answer = (4) = 3.8 The Linear model predicts that an estimated distance of 4 meters will correspond to a predicted actual distance of 3.8 meters.

104
Question For an estimated distance of 4 meters, the actual distance from the object was 4.2 meters. What is the residual for this data value?

105
**Answer Residual = observed – predicted or**

Residual = 4.2 – 3.8 = 0.4 meters

106
Assignment Ch-8 pg 192 – 199: 2, 3, 7 -12, 17, 18, 22, 25, 31, 32, 41, 49

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google