week4 1 Least-Squares regression line • A regression line is a straight line that describes how a response variable y changes as an explanatory variable x changes. We often use it to predict the value of the response variable y for a given value of the explanatory variable x. • A straight line relating a response variable y to an explanatory variable x, has an equation of the form: y = a + b·x where b is the slope and a is the intercept. • Least-squares regression line of y on x is the line that makes the sum of squares of vertical distances of the data points from the line as small as possible. • The equation of the least-squares regression line of y on x is with slope and intercept . x b a y ⋅ + = ˆ x y s s r b = x b y a − =
45
Embed
Least-Squares regression linefisher.utstat.toronto.edu/~hadas/STAB22/Lecture notes/week4.pdf · week4 1 Least-Squares regression line •A regression line is a straight line that
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
week4 1
Least-Squares regression line• A regression line is a straight line that describes how a
response variable y changes as an explanatory variable xchanges. We often use it to predict the value of the response variable y for a given value of the explanatory variable x.
• A straight line relating a response variable y to an explanatory variable x, has an equation of the form: y = a + b·xwhere b is the slope and a is the intercept.
• Least-squares regression line of y on x is the line that makes the sum of squares of vertical distances of the data points fromthe line as small as possible.
• The equation of the least-squares regression line of y on x is
with slope and intercept .
xbay ⋅+=ˆ
x
y
ss
rb = xbya −=
week4 2
• The slope of the least square regression line, b, is the amount by which y changes when x increase by one unit.
• So if the regression line equation is y = a + b·x and we change x to be x+1 (increasing x by 1 unit) the resulting y is
y* = a + b·(x + 1) = a + b·x +b.If b > 0 then y will increase and if b < 0, y will decrease.
• The change in the response variable y corresponding to a change of k units in the explanatory variable x is equal to k·b.
week4 3
Example
A grocery store conducted a study to determine the relationship between the amount of money x, spent on advertising and the weekly volume y, of sales. Six different levels of advertising expenditure were tried in a random order for a six-week period. The accompanying data were observed (in units of $100).
• The output above gives the prediction equation: sales = 1.00 + 9.39 ad. costThis can be used (after some diagnostic checks) for predicting sales. For example the predicted sales, when the amount spent on advertising is 15, is .85.1411539.900.1 =⋅+=sales
week4 6
Extrapolation
• Extrapolation is the use of the regression line for prediction outside the rage of values of the explanatory variable x. Such predictions are often not accurate.
• For example, predicting the weekly sales, when the amount spent on advertising is 600$, would not be accurate.
week4 7
Interpreting the regression line
• The slope and intercept of the least-square line depend on the units of measurement-you can not conclude anything from their size.
• The least-squares regression line always passes through the point on the graph of y and x.),( yx
week4 8
Coefficient of determination - r2
• The square of the correlation (r2) is the fraction of the variation in the values of y that is explained by the least-squares regression of y on x.
• The use of r2 to describe the success of regression in explaining the response y is very common.
• In the above example,r2 = 0.979 = 97.9%, i.e. 97.9% of the variation in sales is explained by the regression of sales on ad. cost.
week4 9
Example from Term test, Summer, ’99• MINITAB analyses of data on math and verbal SAT scores are given below.
Correlations (Pearson)Verbal Math
Math 0.275 Cell Contents: Correlation0.000 P-Value
GPA 0.322 0.1940.000 0.006
The regression equation isGPA = 1.11 + 0.00256 Verbal
Analysis of VarianceSource DF SS MS F PRegression 1 6.9682 6.9682 22.98 0.00Residual Error 198 60.0518 0.3033Total 199 67.0200
a) Which of the SAT verbal or math is a better predictor of GPA?b) What percent of the variation in GPA is explainable by the
verbal scores?c) By the math scores?d) Indicate directly on the scatterplot below what it is that is
minimized when we regress GPA on verbal SAT score. Give its actual numerical value for this regression.
8 007 0060 050 040 0
4
3
2
1
0
V e rb a l
GPA
week4 11
e) In each case below, either make the prediction, or indicate anyreservations about making a prediction, or indicate whatshould be done in order to make a prediction.i) Predict the GPA of someone with a verbal SAT score of 700.ii) Predict the GPA of someone with a verbal SAT score of 250.iii) Predict the verbal score of someone with a GPA of 3.15.
week4 12
Residuals• A residual is the difference between an observed value of the
response variable and the value predicted by the regression line. That is,
residual = observed y – predicted y = .Residuals are also called ‘errors’ and denoted by e .
• A negative value of the residual for a particular value of the explanatory variable x, means that the predicted value is overestimating the true value, i.e.
• Similarly, when a residual is positive, the predicted value is underestimating the true value of the response, i.e.
yy ˆ−
yyyy ˆ0ˆ <⇒<−
yyyy ˆ0ˆ >⇒>−
week4 13
Example• For the example on sales data above,
sales = 1.00 + 9.39 ad. costWhen x = 1.0, y = 10.2 and then the residual = = 10.2 – 10.39 = - 0.19.
• MINITAB commands:Stat > Regression > Regression and click storage and choose Fits and Residuals. The output is given below,
• The mean of the least-square residuals is always zero.• A model that allows for the possibility that the observations do
not lie exactly on a straight line is the model y = a + bx +e
where e is a random error. • For inferences about the model, we make the following
assumptions on random errors.– Errors are normally distributed with mean 0 and constant
variance.– Errors are independent.
week4 16
Residual plots• Residual plots help us assess the model assumptions and
the fit of a regression line.• Recommended residual plots include:
i) Normal probability plot of residuals, and some other plots such as histogram, box-plot etc. Check for normality. If skewed a transformation of the response variable may help.
ii) Plot residuals versus predictor or fitted value.Look for curvature suggesting the need for higher order model or transformations, as shown in the following plot
week4 17
Also look for trends in dispersion, e.g. an increasing dispersion as the fitted values increase, in which case the assumption ofconstant variance of the residuals is not valid and atransformation of the response may help, e.g. log or square root.
iii) Plot residuals versus time order (if taken in some sequence) andversus any other excluded variable that you think might berelevant. Look for patterns suggesting that this variable has aninfluence on the relationship among the other variables.
week4 18
Outliers and influential observations
• An outlier is an observation that lies outside the overall pattern of the other observations.
• Points that are outliers in the y direction of a scatterplot have large residuals, but other outliers need not have large residuals.
• An observation is influential for a statistical calculation if removing it would markedly change the result of the calculation.
• Points that are outliers in the x direction of a scatterplot are often influential for the least square regression line.
week4 19
Example - Term test, Summer, ’99• MINITAB analyses of data on math and verbal SAT scores are given below.
a) In the scatterplot below, circle the observations possessing the 3 largest residuals.
b) Circle below all the values that are outliers in the x-direction, and hence potentially the most influential observations.
4 0 0 5 0 0 6 0 0 7 0 0 8 0 0
0
1
2
3
4
V e rb a l
GP
A
8 0 07 0 06 0 05 0 04 0 0
4
3
2
1
0
V e rb a l
GPA
week4 21
Association and causation• In many studies of the relationship between two variables the
goal is to establish that changes in the explanatory variable cause changes in response variable.
• An association between an explanatory variable x and a response variable y, even if it very strong, is not by itself good evidence that changes in x actually cause changes in y.
• Some explanations for an observed association.
The dashed double arrow lines show an association. The solid arrows show a cause and effectlink. The variable x is explanatory, y is response and z is a lurking variable.
week4 22
Lurking Variables
• A lurking variable is a variable that is not among the explanatory or response variables in a study and yet may influence interpretation of relationships among those variables.
• Lurking variables can make a correlation or regression misleading.
• In the sales example above a possible lurking variable is the type of advertising being used e.g. radio, T.V , street promotion etc.
week4 23
Confounding
• Two variables are confounded when their effects on a response variable cannot be distinguished from each other.
• The confounded variable may be either explanatory variables or lurking variables.
• Examples 2.42 and 2.43 on page 157 in IPS.
week4 24
Example (Term test May 98)• MINITAB analyses of data (Reading.mtw) on pre1 and post1
scores are given belowThe regression equation isPost1 = 1.85 + 0.636 Pre1Predictor Coef StDev T PConstant 1.852 1.185 1.56 0.123Pre1 0.6358 0.1158 5.49 0.000 S = 2.820 R-Sq = 32.0% R-Sq(adj) = 31.0%
Analysis of VarianceSource DF SS MS F PRegression 1 239.74 239.74 30.15 0.000Residual Error 64 508.88 7.95Total 65 748.62
Unusual ObservationsObs Pre1 Post1 Fit StDev Fit Residual StResid30 8.0 13.000 6.939 0.404 6.061 2.17R
week4 25
a) Does it make sense to use the equation found by MINITAB’s regression procedure for predicting post1 scores from pre1 scores? Also, circle the most unusual value in the data set. Is this an influential observation?
b) Comment on the distribution of residuals based on the following plots.
15105
15
10
5
0
Pre1Po
st1
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
SSS S
SD
DD
DD
D
D
DD
D
DD
DD
D
D
D D
D
D
D
D B
B
B
BB
B
B
B
B
BB
B
BB
B
B
BB
B
B
B
B
week4 26
c) What do you learn from the following plot?
50-5
10
5
0
Residual
Freq
uenc
y
Histogram of the Residuals(response is Post1)
50-5
2.5
2.0
1.5
1.0
0.5
0.0
-0 .5
-1 .0
-1 .5
-2 .0
-2 .5
Nor
mal
Sco
re
Residual
Normal Probability Plot of the Residuals(response is Post1)
15105
5
0
-5
Pre1
Res
idua
l
Residuals Versus Pre1(response is Post1)
week4 27
d) Describe one problem that can be spotted from a plot like the one above, and then draw what the corresponding plot would have to look like, below.
e) From the above plots, would you say that ‘group’ is an important lurking variable in our regression of post1 on pre1? Why (not)?
Here are some more MINITAB outputs.The regression equation is
f) For each of the following, make a prediction if you can, and if you cannot explain why. (Assume that the variable ‘group’ may be ignored)
i) Predict the post1 score of someone with pre1 score = 45.
ii) Predict the pre1 score of someone with post1 score = 10.
iii) Predict the post1 score of someone with pre1 score = 11.
g) If we regressed post3 on pre2, what proportion of the total variation in post3 scores will by explained by the linear relation?
h) If the std. dev. of post3 is 50% bigger than the std. dev. of pre2, estimate how much of an increase there is in post3 score corresponding to an increase of 1.0 in pre2, on average.
i) Is the std. dev. of post 3 scores closer to 0.1, 0.5, 1, 5, 20, 50?
3
2
0.181 0.181 1.5 0.27post
pre
sslope
s= × = × =
week4 30
Cautions about regression and correlation• Correlation measures only linear association, and fitting a
straight line makes sense only when the overall pattern of the relationship is linear. Always plot data before calculating.
• Extrapolation (using the regression line to predict value far outside the range of the data that we used to fit it) often produces unreliable predictions.
• Correlations and least square regressions are not resistant. Always plot the data and look for potentially influential points.
• Lurking variables can make a correlation or regression misleading. Plot residuals against time and against other variables that may influence the relationship between x and y.
• High correlation does not imply causation.• A correlation based on averages over many individuals is
usually higher than the correlation between the same variables based on the data for less individuals.
week4 31
Question from Term Test Oct, 2000a) On the plot below, draw in with bars exactly what is
minimized (after squaring and summing) should we fit a least-square line to predict W from Z.
b) Here is a scatterplot with a positive association between x and y. Explain how you can change this into a negative association without changing x or y values, but by introducing new information about the data.
week4 32
c) Suppose that in a regression study, the observations are taken one per week, over many weeks. What type of diagnostic should you examine? Draw an example of what you would not like to see in this diagnostic plot, if you want to use your simple regression of y on x. Explain briefly what the problem is.
week4 33
d) Consider the scatterplot and the possible fitted line below.
For the line drawn above draw a rough picture of the following residual plots.i) Residuals vs x.ii) Histogram of residuals.
week4 34
Question from Term Test Oct 2000In a study of car engine exhaust emissions, nitrogen oxide (NOX)and carbon monoxide (CO), in grams per mile were measured fora sample of 46 similar light-duty engines.a) On the graph below circle the two values that likely had the
biggest influence on the slope of the l.s. line fitted to all the data.
20100
3
2
1
CO
NOX
week4 35
b) If we were to remove the two most influential observations mentioned above, would the slope of the l. s. line increase or decrease?
Here are some MINITAB outputs:The regression equation isNOX = 1.83 - 0.0631 COPredictor Coef StDev T PConstant 1.83087 0.09616 19.04 0.000CO -0.06309 0.01011 -6.24 0.000S = 0.3568 R-Sq = 46.9% R-Sq(adj) = 45.7%
Analysis of VarianceSource DF SS MS F PRegression 1 4.9562 4.9562 38.92 0.000Residual Error 44 5.6027 0.1273Total 45 10.5589
Unusual ObservationsObs CO NOX Fit StDev Fit Residual St.Resid22 23.5 0.8600 0.3465 0.1660 0.5135 1.63 X24 22.9 0.5700 0.3849 0.1602 0.1851 0.58 X32 4.3 2.9400 1.5602 0.0644 1.3798 3.93 R
week4 36
c) What percent of the total variation in NOX is still left unexplained even after taking into account the CO values?
d) How much does the NOX emission change when CO decreases by 10 grams?
e) Tom predicts a CO of 13.15 if NOX = 1.0 (using the fitted regression equation in the above output). Do you agree? Explain.
f) Jim predicts a NOX of 0.06 if CO = 28. Do you agree? Explain.
e) The sum of squared deviations of the NOX measurements about their mean is 10.56. The sum of squared deviations of the NOX values from the l.s. line is less than 10.56. The latteris what percent of the former?
We continue with the pursuit of a good prediction equation for prediction of NOX measurements. Have a look at the MINITABoutputs and answer the following.
week4 37
A)First we try deleting the 3 most unusual observations.
i) Comparing the scatterplots using NOX and logNOX with no data deleted, what do you conclude?
ii) Compare the regressions using logNOX with the regression of NOX on CO but minus the three unusual observations. Which approach works best? (Discuss the residual plots and any other relevant info).
0.50.0-0.5
9
8
7
6
5
4
3
2
1
0
Residual
Freq
uenc
y
Histogram of the Residuals(response is logNOX)
20100
0.5
0.0
-0.5
CO
Res
idua
l
Residuals Versus CO(response is logNOX)
week4 42
QuestionRefer to Exercise-2.73 page 175 IPS. Some useful MINITAB outputs are given below.Coef Stdev t value p Constant -2.5801 2.7277 -0.9459 0.3536Rural 1.0935 0.0506 21.6120 0.0000
Df SS MS F p Regression 1 9371.099 9371.099 467.0797 0Error 24 481.516 20.063
State whether the following statements are true of false.I. 95.1% of the variation in city particulate level has been
explained by the model.II. An increase of 10g in the rural particulate level is
accompanied by an expected increase of 15g in the cityparticulate level.
III. The estimated city particulate level when the rural particulatelevel is 50g is approximately 52g.
IV. Correlation between city and rural particulate levels is 0.951.
week4 43
QuestionExamine the following regression minitab output from a study ofthe relation between freshman year grade point average, denoted"GPA" and verbal Scholastic Aptitude Test score, denoted"VERBAL": The regression equation isGPA = 0.539 + 0.00362 VERBALPredicto Coef Stdev t-ratio pConstant 0.5386 0.3982 1.35 0.179VERBAL 0.0036214 0.0006600 5.49 0.000s = 0.4993 R-sq = 23.5% R-sq(adj)22.7%Analysis of VarianceSOURCE DF SS MS F pRegression 1 7.5051 7.5051 30.10 0.000Error 98 24.4313 0.2493Total 99 31.9364