* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Inference for least squares lines
Survey
Document related concepts
Transcript
Warm-Up The least squares slope b1 is an estimate of the true slope of the line that relates global average temperature to CO2. Since b1 = 0.0103 is very close to 0, could it be that the true slope is NOT significantly different from 0 (that is, atmospheric CO2 gives very little information about global average temperature)? 1 Inference for Simple Linear Regression Simple Linear Regression 1. review of least squares procedure 2. inference for least squares lines 2 1. Review of Least Squares Procedure Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) • We will examine the relationship between quantitative variables x and y via a mathematical equation. • The motivation for using the technique: – Forecast the value of a response variable (y) from the value of explanatory variables (x1, x2,…xk.). – Analyze the specific relationship between the explanatory variable and the dependent variable. 3 The Model The model has a deterministic and a probabilistic component House Cost Most lots sell for $25,000 House size 4 The Model However, house costs vary even among same size houses! Since cost behave unpredictably, House Cost we add a random component. Most lots sell for $25,000 House size 5 The Model • The first order linear model y b0 b1x e y = response variable x = explanatory variable b0 = y-intercept b1 = slope of the line e = error variable y b0 and b1 are unknown population parameters, therefore are estimated from the data. Rise b0 b1 = Rise/Run Run x 6 The Least Squares (Regression) Line A good line is one that minimizes the sum of squared differences between the points and the line. 7 The Estimated Coefficients Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) To calculate the estimates of the slope and intercept of the least squares line , use the formulas: b1 r sy sx b0 y b1 x r correlation coefficient The least squares prediction equation that estimates the mean value of y for a particular value of x is: ŷ b0 b1 x n sy 2 ( y y ) i i 1 population intercept b 0 n 1 n sx (x x ) i 1 i n 1 b0 estimates the unknown value of the 2 b1 estimates the unknown value of the population slope b1 8 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) The Least Squares Regression Line • Example: – A car dealer wants to find the relationship between the odometer reading and the selling price of used cars. – A random sample of 100 cars is selected, and the data recorded. – Find the regression line. Car Odometer Price 1 37400 14600 2 44800 14100 3 45800 14000 4 30900 15600 5 31700 15600 6 34000 14700 . . . Independent Dependent . . . variable x variable y . . . 9 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) The Least Squares Regression Line • Solution – Solving by hand: Calculate a number of statistics x 36, 011; sx 6596.125 r 0.80517 y 14,841; s y 547.74 where n = 100. b1 r sy sx 0.81517 547.74 .06769 6596.125 b0 y b1 x 14,841 (.06769)(36, 011) 17, 286.15 yˆ b0 b1 x 17, 286.15 .06769 x 10 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) The Least Squares Regression Line Regression Statistics Multiple R 0.805167979 R Square 0.648295475 Adjusted R Square 0.644706653 Standard Error 326.4886258 Observations 100 yˆ 17, 248.73 .06686 x ANOVA df Regression Residual Total Intercept Odometer SS 19255607.37 10446292.63 29701900 MS 19255607.37 106594.8228 F 180.643 Coefficients Standard Error 17248.72734 182.0925742 -0.06686089 0.004974639 t Stat 94.72504534 -13.44034928 P-value 3.57E-98 5.75E-24 1 98 99 Significance F 5.75078E-24 Lower 95% Upper 95% 16887.37056 17610.084 -0.076732895 -0.0569889 11 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) 17248.73 Interpreting the Least Squares Regression Line Odometer Line Fit Plot Price 16000 0 15000 14000 No data 13000 Odometer yˆ 17, 248.73 .06686 x The intercept is b0 = $17248.73. Do not interpret the intercept as the “Price of cars that have not been driven” This is the slope of the line. For each additional mile on the odometer, the price decreases by an average of $0.0669 12 Random Error Component e: Assumptions for Inference y b0 b1x e • The random error e is a critical part of the regression model. • To do statistical inference, four requirements involving the distribution of e must be satisfied. 1. The distribution of the e’s can be described by a normal model 2. The mean of e is zero: E(e) = 0. 3. The standard deviation SD(e) of e, denoted se, is the same for all values of x. 4. The set of errors associated with different values of y are all independent. 13 The Normality of e 1. The distribution of the e’s can be described by a normal model 2. The mean of e is zero: E(e) = 0. 3. The standard deviation of e is se for all values of x. E(y|x3) The standard deviation se remains constant, m3 b0 + b1x3 E(y|x2) b0 + b1x2 m2 but the mean value changes with x b0 + b1x1 From the first three assumptions we have: y is normally distributed with mean E(y) = b0 + b1x, and a constant standard deviation se E(y|x1) m1 x1 x2 x3 14 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) Assessing the Model y b0 b1x e 1. Hypothesis test for the slope H0: b1 = 0 HA: b1 0 (or < 0,or > 0) 2. Check the value of r2 3. Examine the residuals yi yˆi , i 1, , n The above methods used to assess the model use the value of the Sum of Squares of the Errors, denoted SSE. 15 Warm-Up (cont.) SUMMARY OUTPUT Regression Statistics Multiple R 0.857739864 R Square 0.735717675 Adjusted R Square 0.729425238 Standard Error 0.131613902 Observations 44 ANOVA Regression Residual Total Intercept CO2 Results of hypothesis test MS F Significance F H0 : b1 = 0df Reject SS H0 1 2.025330433 2.025330433 116.9209567 1.03354E-13 HA : b 1 0 42 0.727533203 0.017322219 Confidence interval for b1 43 2.752863636 Coefficients Standard Error t Stat P-value Lower 95% Upper 95% 10.6441999 0.341822184 31.1395819 1.19922E-30 9.954374809 11.334025 0.010324616 0.000954834 10.81299943 1.03354E-13 0.008397684 0.012251548 16 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) SSE: Sum of Squares of the Errors – This is the sum of the squared differences between the observed y’s and the predicted y’s given by the regression line. ( yi yˆi )2 where yˆi b0 b1 xi – It can serve as a measure of how well the line fits the data. SSE is defined by n SSE ( y i ŷ i ) 2 . i 1 – A shortcut formula SSE yi2 b0 yi b1 xi yi 17 y b0 b1x e Standard Error of Estimate – E(e) = 0. The mean error is equal to zero. – SD(e) is denoted by se. If se is small the errors tend to be close to zero (the mean error), and the model describes the data well. – Therefore we can use se as a measure of the suitability of using a linear model. – An estimator of se is given by se Standard Error of Estimate SSE se n2 18 Standard Error of Estimate, Example • Example: – Calculate the standard error of estimate for the previous example and describe what it tells you about the model fit. • Solution SSE 10, 446, 293 SSE 10, 446, 293 se 326.49 n2 98 It is hard to assess the model based on se even when compared with the mean value of y. 19 se 326.49 y 14,841 Testing the slope – When no linear relationship exists between two variables, the regression line should be horizontal. q q qq q q q q q q q q Linear relationship. Different inputs (x) yield different outputs (y). No linear relationship. Different inputs (x) yield the same output (y). The slope is not equal to zero The slope is equal to zero 20 y b0 b1x e Testing the Slope • We can make an inference about b1 from b1 by testing H0: b1 = 0 HA: b1 = 0 (or < 0,or > 0) – The test statistic is b1 b1 t s b1 where sb1 se n 1 sx The standard error of b1. – If the error variable e is normally distributed, the statistic 21 is Student t distribution with d.f. = n-2. y b0 b1x e Testing the Slope, Example • Example – Test to determine whether there is enough evidence to infer that there is a linear relationship between the car auction price and the odometer reading for all three-year-old Tauruses in the previous example. 22 Testing the Slope, Example Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 ) • Solving by hand • To compute “t” we need the values of b1 and sb1. b1 .06686 se 326.49 sb1 .004975 n 1 sx 99 6596.125 b1 b1 .06686 0 t 13.44 . 004975 sb1 P-value = 2P(t98 > |-13.44|) ~ 0 23 Testing the Slope (Example) • Using the computer Odometer Price 37400 44800 45800 30900 45900 19100 40100 40200 14600 14100 Regression Statistics 14000 Multiple R 0.805167979 15600 R Square 0.648295475 Adjusted R 15600 Square 0.644706653 Standard 14700 Error 326.4886258 Observation 14500 s 100 15700 15100 ANOVA 14800 df 32400 43500 32700 34500 15200 Regression 14700 Residual 15600 Total 15600 37700 41400 24500 35800 48600 24200 14600 14600 Intercept 15700 Odometer 15000 14700 15400 31700 34000 1 98 99 There is overwhelming evidence to infer that the odometer reading affects the auction selling price. SS MS F 19255607.37 10446292.63 29701900 19255607.4 106594.823 180.643 Coefficients Standard Error 17248.72734 182.0925742 -0.066860885 0.004974639 t Stat 94.7250453 -13.4403493 P-value 3.57E-98 5.75E-24 Significance F 5.75078E-24 Lower 95% Upper 95% 16887.37056 17610.08 -0.076732895 -0.05699 24 Coefficient of determination r2 Case I: Case II: ignore x: use y to predict y use x: use yˆ b0 b1 x n errors: (obs. pred.) 2 i 1 n ( yi y ) i 1 TSS n errors: 2 (obs. pred.) i 1 n 2 2 ˆ = ( yi yi ) i 1 SSE Reduction in prediction error when use x: TSS-SSE = SSR 25 Coefficient of determination r2 Reduction in prediction error when use x: TSS-SSE = SSR or TSS = SSR + SSE The regression model SSR Overall variability in y TSS The error SSE Proportional reduction in prediction error when use x: TSS SSE SSE 1 TSS TSS 2 ( xi x )( yi y ) 2 i 1 algebra = r ) 2 2 sx s y n 26 Coefficient of determination: graphically y2 Two data points (x1,y1) and (x2,y2) of a certain sample are shown. y y1 x1 Total variation in y = (y1 y) 2 (y 2 y) 2 Variation in y = SSR + SSE (TSS) x2 Variation explained by the + Unexplained variation (error) regression line (ŷ1 y) 2 (ŷ 2 y) 2 (y1 ŷ1 ) 2 (y 2 ŷ 2 ) 2 27 Coefficient of determination r2 • R2 (=r2 ) measures the proportion of the variation in y that is explained by the variation in x. SSE TSS SSE SSR R 1 TSS TSS TSS 2 • r2 takes on any value between zero and one (-1r 1). r2 = 1: Perfect match between the line and the data points. r2 = 0: There are no linear relationship between x and y. 28 Coefficient of determination r2, Example • Example – Find the coefficient of determination for the used car price –odometer example.what does this statistic tell you about the model? • Solution – Solving by hand; r 2 (.80517)2 .6483 29 Coefficient of determination r2 – Using the computer From the regression output we have 64.8% of the variation in the auction selling price is explained by the variation in odometer reading. The rest (35.2%) remains unexplained by this model. Regression Statistics Multiple R 0.805167979 R Square 0.648295475 Adjusted R Square 0.644706653 Standard Error 326.4886258 Observations 100 ANOVA df Regression Residual Total Intercept Odometer 1 98 99 SS 19255607.37 10446292.63 29701900 MS 19255607.37 106594.8228 F Significance F 180.643 5.75078E-24 Coefficients Standard Error t Stat P-value 17248.72734 182.0925742 94.72504534 3.57E-98 -0.06686089 0.004974639 -13.44034928 5.75E-24 30 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 ) Using the Regression Equation • Before using the regression model, we need to assess how well it fits the data. • If we are satisfied with how well the model fits the data, we can use it to predict the values of y. • To make a prediction we use – Point prediction, and – Interval prediction 31 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 ) Point Prediction • Example – Predict the selling price of a three-year-old Taurus with 40,000 miles on the odometer. A point prediction yˆ 17248.73 .06686 x 17248.73 .066686(40, 000) 14,574 – It is predicted that a 40,000 miles car would sell for $14,574. – How close is this prediction to the real price? 32 Interval Estimates • Two intervals can be used to discover how closely the predicted value will match the true value of y. – Prediction interval – predicts y for a given value of x (price prediction for a specific car with 40,000 miles on odometer) – Confidence interval – estimates the average y for a given x (estimate the average price of all cars with 40,000 miles on odometer). – The prediction interval yˆ t 2 s SE 2 (b1 )( x x ) 2 e se2 n 2 – The confidence interval yˆ t 2 2 s SE 2 (b1 )( x x ) 2 e n 33 Interval Estimates, Example • Example - continued – Provide an interval estimate for the bidding price on a Ford Taurus with 40,000 miles on the odometer. – Two types of predictions are required: • A prediction for a specific car • An estimate for the average price per car 34 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 ) Interval Estimates: Example • Solution – A prediction interval provides the price estimate for a single car: yˆ t 2 s SE 2 (b1 )( x x ) 2 e se2 n 2 t.025,98 326.492 14,574 1.9845 (.004975) (40, 000 36, 011) 326.492 14,574 652 100 2 2 35 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (x100 , y100 ) Interval Estimates: Example • Solution – continued – A confidence interval provides the estimate of the mean price per car for a Ford Taurus with 40,000 miles reading on the odometer. • The confidence interval (95%) = yˆ t 2 2 s SE 2 (b1 )( x x ) 2 e n 326.492 14,574 1.9845 (.004975) (40, 000 36, 011) 14,574 76 100 2 2 36 Warm-Up (cont.) Simple linear regression results: (Statcrunch) Dependent Variable: Global Avg Temp Independent Variable: CO2 Global Avg Temp = 10.6442 + 0.010324616 CO2 Sample size: 44 R (correlation coefficient) = 0.85773986 R-sq = 0.73571767 Estimate of error standard deviation: 0.1316139 Parameter Intercept Slope Source Estimate Std. Err. 10.6442 Parameter Intercept Slope Estimate Std. Err. Alternative DF T-Stat P-value 10.6442 0.3418221 8 ≠0 42 31.139582 <0.0001 0.0103246 16 0.0009548 3367 ≠0 42 10.812999 <0.0001 Alternative P-value ≠0 42 31.139582 <0.0001 0.010324616 0.00095483367 ≠0 42 10.812999 <0.0001 DF SS MS F-stat 1 2.0253304 2.0253304 Error 42 0.7275332 0.017322219 Total 43 2.7528636 405 T-Stat 0.34182218 Model X value DF Pred. Y 14.825669 s.e.(Pred. y) 0.049603046 116.92096 95% C.I. for mean P-value <0.0001 95% P.I. for new 37 (14.725566, 14.925772) (14.541824, 15.109514) Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) The effect of the given x on the length of the interval – As x moves away from x the interval becomes longer. That is, the shortest interval is found at x. ŷ b0 b1 x yˆ t se2 SE (b1 ) ( x x ) n 2 2 2 x 38 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) The effect of the given x on the length of the interval – As x moves away from x the interval becomes longer. That is, the shortest interval is found at x. ŷ b0 b1 x yˆ ( x x 1) yˆ ( x x 1) yˆ t se2 SE (b1 ) ( x x ) n 2 2 yˆ t 2 se2 SE (b1 )(1) n 2 2 2 x 1 x 1 x ( x 1) x 1 ( x 1) x 1 39 Bivariate data: (x1 , y1 ), (x2 , y2 ), (x3 , y3 ), … , (xn , yn ) The effect of the given x on the length of the interval – As x moves away from x the interval becomes longer. That is, the shortest interval is found at x. ŷ b0 b1 x yˆ t se2 SE (b1 ) ( x x ) n 2 2 ˆ t y x 2 x x2 ( x 2) x 2 ( x 2) x 2 ˆ t y 2 se2 SE (b1 )(1) n 2 2 se2 SE (b1 )(2) n 2 2 2 2 40 y b0 b1x e Regression Diagnostics - I • The three conditions required for the validity of the regression analysis are: – the error variable is normally distributed. – SD(e) is constant for all values of x. – The errors are independent of each other. • How can we diagnose violations of these conditions? 41 y b0 b1x e Residual Analysis • Examining the residuals (or standardized residuals), help detect violations of the required conditions. • Example – continued: – Nonnormality. • Use Excel to obtain the standardized residual histogram. • Examine the histogram and look for a bell shaped. diagram with a mean close to zero. 42 y b0 b1x e Residual Analysis ObservationPredicted Price Residuals Standard Residuals 1 14736.91 -100.91 -0.33 2 14277.65 -155.65 -0.52 3 14210.66 -194.66 -0.65 4 15143.59 446.41 1.48 5 15091.05 476.95 1.58 For each residual we calculate the standard deviation as follows: A Partial list of Standard residuals s ri s e 1 hi where Standardized residual ‘i’ = Residual ‘i’ 1 ( x i x)2 hi Standard deviation 2 n (n 1)s x 43 Residual Analysis Standardized residuals 40 30 20 10 0 -2 -1 0 1 2 More It seems the residual are normally distributed with mean zero 44 y b0 b1x e SD(e) the Same for all x? Heteroscedasticity • When the requirement that SD(e) is the same for all x is violated, we have a condition called heteroscedasticity. • Diagnose heteroscedasticity by plotting the residual against the predicted y. + ^y ++ Residual + + + + + + + + + + + + ++ + + + + + + + + + + + + + + + The spread increases with ^y y^ ++ + ++ ++ ++ + + ++ + + 45 y b0 b1x e Homoscedasticity • When the requirement that SD(e) is the same for all x is not violated we have a condition of homoscedasticity. • Example - continued Residuals 1000 500 0 13500 -500 14000 14500 15000 15500 16000 -1000 Predicted Price 46 y b0 b1x e Non-Independence of Error Variables – A time series is constituted if data were collected over time. – Examining the residuals over time, no pattern should be observed if the errors are independent. – When a pattern is detected, the errors are said to be autocorrelated. – Autocorrelation can be detected by graphing the residuals against time. 47 y b0 b1x e Non Independence of Error Variables Patterns in the appearance of the residuals over time indicates that autocorrelation exists. Residual Residual + ++ + 0 + + + + + + + + + + ++ + + + Time Note the runs of positive residuals, replaced by runs of negative residuals + + + 0 + + + + Time + + Note the oscillating behavior of the residuals around zero. 48 Outliers • An outlier is an observation that is unusually small or large. • Several possibilities need to be investigated when an outlier is observed: – There was an error in recording the value. – The point does not belong in the sample. – The observation is valid. • Identify outliers from the scatter diagram. • It is customary to suspect an observation is an outlier if its |standard residual| > 2 49 An outlier + + + + + + + + + An influential observation +++++++++++ … but, some outliers may be very influential + + + + + + + The outlier causes a shift in the regression line 50 y b0 b1x e Procedure for Regression Diagnostics • Develop a model that has a theoretical basis. • Gather data for the two variables in the model. • Draw the scatter diagram to determine whether a linear model appears to be appropriate. • Determine the regression equation. • Check the required conditions for the errors. • Check the existence of outliers and influential observations • Assess the model fit. • If the model fits the data, use the regression equation. 51