Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Linear Regression Review 1

Similar presentations


Presentation on theme: "Simple Linear Regression Review 1"— Presentation transcript:

1 Simple Linear Regression Review 1
Simple Linear Regression Review 1. review of scatterplots and correlation 2. review of least squares procedure 3. inference for least squares lines

2 Simple Linear Regression Review 1
Simple Linear Regression Review 1. review of scatterplots and correlation 2. review of least squares procedure 3. inference for least squares lines

3 Basic Terminology Univariate data: 1 variable is measured on each sample unit or population unit e.g. height of each student in a sample Bivariate data: 2 variables are measured on each sample unit or population unit e.g. height and GPA of each student in a sample; (caution: data from 2 separate samples is not bivariate data) Bivariate data: (x1, y1), (x2, y2), …, (xn, yn)

4 Basic Terminology (cont.)
Multivariate data: several variables are measured on each unit in a sample or population. (later in course) For each student in a sample of NCSU students, measure height, GPA, and distance between NCSU and hometown. Focus on bivariate data for now.

5 Introduction Bivariate data: (x1, y1), (x2, y2), …, (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 dependent variable (y) from the value of independent variables (x1, x2,…xk.). Analyze the specific relationships between the independent variables and the dependent variable.

6 Scatterplot: Fuel Consumption vs Car Weight. x=car weight, y=fuel cons.
(xi, yi): (3.4, 5.5) (3.8, 5.9) (4.1, 6.5) (2.2, 3.3) (2.6, 3.6) (2.9, 4.6) (2, 2.9) (2.7, 3.6) (1.9, 3.1) (3.4, 4.9)

7 The correlation coefficient "r"
The correlation coefficient is a measure of the direction and strength of the linear relationship between 2 quantitative variables. It is calculated using the mean and the standard deviation of both the x and y variables. Bivariate data: (x1, y1), (x2, y2), …, (xn, yn) Correlation can only be used to describe quantitative variables. Categorical variables don’t have means and standard deviations.

8 Properties (cont.) r ranges from -1 to+1
"r" quantifies the strength and direction of a linear relationship between 2 quantitative variables. Strength: how closely the points follow a straight line. Direction: is positive when individuals with higher X values tend to have higher values of Y.

9 Properties (cont.) High correlation does not imply cause and effect
CARROTS: Hidden terror in the produce department at your neighborhood grocery Everyone who ate carrots in 1920, if they are still alive, has severely wrinkled skin!!! Everyone who ate carrots in 1865 is now dead!!! 45 of yr olds arrested in Raleigh for juvenile delinquency had eaten carrots in the 2 weeks prior to their arrest !!!

10 Properties (cont.) Cause and Effect
There is a strong positive correlation between the monetary damage caused by structural fires and the number of firemen present at the fire. (More firemen-more damage) Improper training? Will no firemen present result in the least amount of damage?

11 Properties (cont.) Cause and Effect
(1,2) (24,75) (1,0) (18,59) (9,9) (3,7) (5,35) (20,46) (1,0) (3,2) (22,57) x = fouls committed by player; y = points scored by same player The correlation is due to a third “lurking” variable – playing time r measures the strength of the linear relationship between x and y; it does not indicate cause and effect correlation r = .935

12 Simple Linear Regression Review 1
Simple Linear Regression Review 1. review of scatterplots and correlation 2. review of least squares procedure 3. inference for least squares lines

13 The Model The model has a deterministic and a probabilistic components
House Cost Building a house costs about $75 per square foot. House cost = (Size) Most lots sell for $25,000 House size

14 The Model However, house costs vary even among same size houses!
Since cost behave unpredictably, we add a random component. House Cost Most lots sell for $25,000 House cost = (Size) + e House size Bivariate data: (x1, y1), (x2, y2), …, (xn, yn)

15 The Model The first order linear model y = dependent variable
x = independent variable b0 = y-intercept b1 = slope of the line e = error variable b0 and b1 are unknown population parameters, therefore are estimated from the data. y Rise b1 = Rise/Run Run b0 x

16 Estimating the Slope 1 and Intercept 0
The estimates are determined by selecting a sample from the population of interest. calculating sample statistics. producing a straight line that cuts into the data. Bivariate data: (x1, y1), (x2, y2), …, (xn, yn) y w Question: What should be considered a good line? w w w w w w w w w w w w w w x

17 The Least Squares (Regression) Line
Bivariate data: (x1, y1), (x2, y2), …, (xn, yn) A good line is one that minimizes the sum of squared differences between the data points and the line.

18 The Least Squares (Regression) Line
Bivariate data: (1, 2), (2, 4), (3, 1.5), (4, 3.2) Sum of squared differences = (2 - 1)2 + (4 - 2)2 + ( )2 + ( )2 = 6.89 Sum of squared differences = (2 -2.5)2 + ( )2 + ( )2 + ( )2 = 3.99 Let us compare two lines 4 (2,4) The second line is horizontal w w (4,3.2) 3 2.5 2 w (1,2) (3,1.5) w The smaller the sum of squared differences the better the fit of the line to the data. 1 2 3 4

19 The vertical differences are referred to as residuals and denoted ei.

20 The Least Squares (Regression) Line
A good line is one that minimizes the sum of squared residuals. This line has slope b1 and intercept b0 that minimizes for the given observations (x1, y1), (x2, y2), …, (xn, yn)

21 The Estimated Coefficients
To calculate the estimates of the slope and intercept of the least squares line , use the formulas: The least squares prediction equation that estimates the mean value of y for a particular value of x is:

22 The Simple Linear 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. Independent variable x Dependent variable y

23 The Simple Linear Regression Line
Solution Solving by hand: Calculate a number of statistics where n = 100.

24 The Simple Linear Regression Line
Solution – continued Using the computer 1. Scatterplot 2. Trend function 3. Tools > Data Analysis > Regression

25 The Simple Linear Regression Line
Regression Statistics Multiple R R Square Adjusted R Square Standard Error Observations 100 ANOVA df SS MS F Significance F Regression 1 E-24 Residual 98 Total 99 Coefficients t Stat P-value Lower 95% Upper 95% Intercept 3.57E-98 Odometer 5.75E-24

26 Interpreting the Linear Regression -Equation
No data The intercept is b0 = $ This is the slope of the line. For each additional mile on the odometer, the price decreases by an average of $0.0669 Do not interpret the intercept as the “Price of cars that have not been driven”

27 Simple Linear Regression Review 1
Simple Linear Regression Review 1. review of scatterplots and correlation 2. review of least squares procedure 3. inference for least squares lines

28 The Model The first order linear model y = dependent variable
x = independent variable b0 = y-intercept b1 = slope of the line e = error variable b0 and b1 are unknown population parameters, therefore are estimated from the data. y Rise b1 = Rise/Run Run b0 x

29 Error Variable: Required Conditions
The error e is a critical part of the regression model. Four requirements involving the distribution of e must be satisfied. The probability distribution of e is normal. The mean of e is zero: E(e) = 0. The standard deviation of e is se for all values of x. The set of errors associated with different values of y are all independent.

30 but the mean value changes with x
The Normality of e E(y|x3) The standard deviation remains constant, m3 b0 + b1x3 E(y|x2) b0 + b1x2 m2 E(y|x1) but the mean value changes with x m1 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 x1 x2 x3

31 Assessing the Model The least squares method will produce a regression line whether or not there is a linear relationship between x and y. Consequently, it is important to assess how well the linear model fits the data. Several methods are used to assess the model. All are based on the sum of squares for errors, SSE.

32 Sum of Squares for Errors
This is the sum of differences between the points and the regression line. It can serve as a measure of how well the line fits the data. SSE is defined by A shortcut formula

33 Estimate of se, the Standard Deviation of the Error Term 
The mean error is equal to zero (recall: the mean of e is zero: E(e) = 0). If se is small the errors tend to be close to zero (close to the mean error). Then, the model fits 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 se is called the standard error since it is an estimate of the standard deviation se

34 Estimate of se, an example
Calculate the standard error se for the previous example and describe what it tells you about the model fit. Solution It is hard to assess the model based on se even when compared with the mean value of y.

35 The slope is not equal to zero
Testing the slope When no linear relationship exists between two variables, the regression line should be horizontal. q q q q q q q q q q q q Linear relationship. Linear relationship. Linear relationship. Linear relationship. No linear relationship. Different inputs (x) yield the same output (y). Different inputs (x) yield different outputs (y). The slope is not equal to zero The slope is equal to zero

36 Testing the Slope We can draw inference about b1 from b1 by testing
H0: b1 = 0 H1: b1 = 0 (or < 0,or > 0) The test statistic is If the error variable is normally distributed, the statistic is Student t distribution with d.f. = n-2. where The standard error of b1.

37 Testing the Slope, 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 . Use a = 5%.

38 Testing the Slope, Example
Solving by hand To compute “t” we need the values of b1 and sb1. The rejection region is t > t.025 or t < -t.025 with df = n-2 = 98, t.025 =

39 Testing the Slope (Example)
Using the computer Odometer Price 37400 14600 44800 14100 Regression Statistics 45800 14000 Multiple R 30900 15600 R Square 31700 Adjusted R Square 34000 14700 Standard Error 45900 14500 Observations 100 19100 15700 40100 15100 ANOVA 40200 14800 df SS MS F Significance F 32400 15200 Regression 1 E-24 43500 Residual 98 32700 Total 99 34500 37700 Coefficients t Stat P-value Lower 95% Upper 95% 41400 Intercept 3.57E-98 24500 5.75E-24 35800 15000 48600 24200 15400 There is overwhelming evidence to infer that the odometer reading affects the auction selling price.

40 Coefficient of determination
Reduction in prediction error when use x: TSS-SSE = SSR

41 Coefficient of determination
Reduction in prediction error when use x: TSS-SSE = SSR or TSS = SSR + SSE The regression model SSR Overall variability in y TSS Explained in part by Remains, in part, unexplained The error SSE

42 Coefficient of determination: graphically
Two data points (x1,y1) and (x2,y2) of a certain sample are shown. y Variation in y = SSR + SSE (TSS) y1 x1 x2 Total variation in y = Variation explained by the regression line + Unexplained variation (error)

43 Coefficient of determination
R2 (=r2 ) measures the proportion of the variation in y that is explained by the variation in x. r2 takes on any value between zero and one (-1r 1). r2 = 1: Perfect match between the line and the data points. r2 = 0: There is no linear relationship between x and y.

44 Coefficient of determination, 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;

45 Coefficient of determination
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 R Square Adjusted R Square Standard Error Observations 100 ANOVA df SS MS F Significance F Regression 1 E-24 Residual 98 Total 99 Coefficients t Stat P-value Intercept 3.57E-98 Odometer 5.75E-24

46 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

47 Point Prediction Example
Predict the selling price of a three-year-old Taurus with 40,000 miles on the odometer. A point prediction It is predicted that a 40,000 miles car would sell for $14,574. How close is this prediction to the real price?

48 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, Confidence interval – estimates the average y for a given x. The prediction interval The confidence interval

49 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

50 Interval Estimates, Example
Solution A prediction interval provides the price estimate for a single car: t.025,98

51 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%) =

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

53 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 = x.

54 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 = x.

55 Regression Diagnostics - I
The three conditions required for the validity of the regression analysis are: the error variable is normally distributed. the error variance is constant for all values of x. The errors are independent of each other. How can we diagnose violations of these conditions?

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

57 Standardized residual ‘i’ =
Residual Analysis A Partial list of Standard residuals For each residual we calculate the standard deviation as follows: Standardized residual ‘i’ = Residual ‘i’ Standard deviation

58 It seems the residual are normally distributed with mean zero
Residual Analysis It seems the residual are normally distributed with mean zero

59 The spread increases with y
Heteroscedasticity When the requirement of a constant variance is violated we have a condition of heteroscedasticity. Diagnose heteroscedasticity by plotting the residual against the predicted y. + ^ y Residual + + + + + + + + + + + + + + ^ + + + y + + + + + + + + + The spread increases with y ^

60 Homoscedasticity When the requirement of a constant variance is not violated we have a condition of homoscedasticity. Example - continued

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

62 Non Independence of Error Variables
Patterns in the appearance of the residuals over time indicates that autocorrelation exists. Residual Residual + + + + + + + + + + + + + + + Time Time + + + + + + + + + + + + + Note the runs of positive residuals, replaced by runs of negative residuals Note the oscillating behavior of the residuals around zero.

63 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

64 An influential observation
An outlier An influential observation + + + + + + + + + + + + + … but, some outliers may be very influential + + + + + + + + + + + + + + The outlier causes a shift in the regression line

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


Download ppt "Simple Linear Regression Review 1"

Similar presentations


Ads by Google