Linear Regression.

Slides:



Advertisements
Similar presentations
Simple Linear Regression 1. review of least squares procedure 2
Advertisements

Lecture 17: Tues., March 16 Inference for simple linear regression (Ch ) R2 statistic (Ch ) Association is not causation (Ch ) Next.
Forecasting Using the Simple Linear Regression Model and Correlation
Regression Analysis Once a linear relationship is defined, the independent variable can be used to forecast the dependent variable. Y ^ = bo + bX bo is.
1 Simple Linear Regression and Correlation The Model Estimating the Coefficients EXAMPLE 1: USED CAR SALES Assessing the model –T-tests –R-square.
Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc Chapter 17 Simple Linear Regression and Correlation.
Statistics for the Social Sciences
Chapter 10 Simple Regression.
BA 555 Practical Business Analysis
Simple Linear Regression
1 BA 275 Quantitative Business Methods Residual Analysis Multiple Linear Regression Adjusted R-squared Prediction Dummy Variables Agenda.
Chapter Topics Types of Regression Models
Lecture 20 Simple linear regression (18.6, 18.9)
Regression Diagnostics - I
1 Simple Linear Regression Chapter Introduction In this chapter we examine the relationship among interval variables via a mathematical equation.
1 Simple Linear Regression and Correlation Chapter 17.
1 4. Multiple Regression I ECON 251 Research Methods.
© 2000 Prentice-Hall, Inc. Chap Forecasting Using the Simple Linear Regression Model and Correlation.
Lecture 17 Interaction Plots Simple Linear Regression (Chapter ) Homework 4 due Friday. JMP instructions for question are actually for.
1 Simple Linear Regression Chapter Introduction In Chapters 17 to 19 we examine the relationship between interval variables via a mathematical.
Business Statistics - QBM117 Statistical inference for regression.
Lecture 19 Simple linear regression (Review, 18.5, 18.8)
Correlation and Regression Analysis
Introduction to Regression Analysis, Chapter 13,
Simple Linear Regression Analysis
Simple Linear Regression. Introduction In Chapters 17 to 19, we examine the relationship between interval variables via a mathematical equation. The motivation.
Chapter 6 (cont.) Regression Estimation. Simple Linear Regression: review of least squares procedure 2.
1 Simple Linear Regression 1. review of least squares procedure 2. inference for least squares lines.
Keller: Stats for Mgmt & Econ, 7th Ed
Introduction to Linear Regression and Correlation Analysis
Inference for regression - Simple linear regression
Statistics for Managers Using Microsoft Excel, 4e © 2004 Prentice-Hall, Inc. Chap 12-1 Chapter 12 Simple Linear Regression Statistics for Managers Using.
1 Least squares procedure Inference for least squares lines Simple Linear Regression.
OPIM 303-Lecture #8 Jose M. Cruz Assistant Professor.
Keller: Stats for Mgmt & Econ, 7th Ed
Correlation & Regression
Business Statistics: A Decision-Making Approach, 6e © 2005 Prentice-Hall, Inc. Chap 13-1 Introduction to Regression Analysis Regression analysis is used.
Chapter 11 Correlation and Simple Linear Regression Statistics for Business (Econ) 1.
Economics 173 Business Statistics Lectures Summer, 2001 Professor J. Petry.
Correlation & Regression Analysis
Economics 173 Business Statistics Lecture 10 Fall, 2001 Professor J. Petry
Chapter 8: Simple Linear Regression Yang Zhenlin.
LEAST-SQUARES REGRESSION 3.2 Least Squares Regression Line and Residuals.
Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Simple Linear Regression Analysis Chapter 13.
1 Simple Linear Regression and Correlation Least Squares Method The Model Estimating the Coefficients EXAMPLE 1: USED CAR SALES.
Linear Regression Linear Regression. Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc. Purpose Understand Linear Regression. Use R functions.
Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc Chapter 17 Simple Linear Regression and Correlation.
1 Simple Linear Regression Review 1. review of scatterplots and correlation 2. review of least squares procedure 3. inference for least squares lines.
Lecturer: Ing. Martina Hanová, PhD.. Regression analysis Regression analysis is a tool for analyzing relationships between financial variables:  Identify.
Introduction. We want to see if there is any relationship between the results on exams and the amount of hours used for studies. Person ABCDEFGHIJ Hours/
Introduction Many problems in Engineering, Management, Health Sciences and other Sciences involve exploring the relationships between two or more variables.
1 Simple Linear Regression Chapter Introduction In Chapters 17 to 19 we examine the relationship between interval variables via a mathematical.
Stats Methods at IC Lecture 3: Regression.
Chapter 13 Simple Linear Regression
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 = is very.
Inference for Least Squares Lines
Correlation & Regression
Chapter 11: Simple Linear Regression
Simple Linear Regression Review 1
Keller: Stats for Mgmt & Econ, 7th Ed
Keller: Stats for Mgmt & Econ, 7th Ed Linear Regression Analysis
General Announcement ( )
BA 275 Quantitative Business Methods
CHAPTER 29: Multiple Regression*
Simple Linear Regression
Product moment correlation
Algebra Review The equation of a straight line y = mx + b
Introduction to Regression
Correlation and Simple Linear Regression
Correlation and Simple Linear Regression
Presentation transcript:

Linear Regression

What is a linear regression How do we make a linear regression Assessing the model Demo in Python

What is linear regression? Regression is an approach/method/algorithm used in finding the relationship between explanatory variables (or independent variables) and our variable of interest (or dependent variable).

What is linear regression? Said another way, we are interested in finding out how much our variable of interest (Y), will increase (or decrease) with a change in each of our explanatory/indep. variables (X1, X2, …)

Examples I work at Adobe. Work with lots of online retailers. A very common question is “How much is a visit worth (in terms of revenue)?” How is Revenue (Y) related to number of visits (X)? Natural extension of this is how is revenue related to different types of visits (google search, direct type, email campaign, etc.)?

Examples How can I estimate the value of a car? Simple approach = value of car by the odometer Advanced approach = for each make and model, how do the odometer reading change the value.

Examples What are some factors that influence house prices and how much do they influence them? Price (Y) related to: Number of bedrooms (X1) Number of bathrooms (X2) Square footage (X3) Lot size (X4) Etc.

How do we create a linear regression?

Creating a Linear Regression

Drawing a line Slope intercept b0 = y-intercept b1 = slope of the line Rise b1 = Rise/Run Run b0 x

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

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

The Model However, house cost 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 = 25000 + 75(Size) + e House size

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

Estimating the Coefficients The estimates are determined by drawing a sample from the population of interest, calculating sample statistics. producing a straight line that cuts into the data. 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

The Least Squares (Regression) Line A good line is one that minimizes the sum of squared differences between the points and the line.

The Least Squares (Regression) Line Sum of squared differences = (2 - 1)2 + (4 - 2)2 + (1.5 - 3)2 + (3.2 - 4)2 = 6.89 Sum of squared differences = (2 -2.5)2 + (4 - 2.5)2 + (1.5 - 2.5)2 + (3.2 - 2.5)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

Creating a Linear Regression

The Estimated Coefficients To calculate the estimates of the slope and intercept of the least squares line , use the formulas: To extended to multiple independent variables and betas, use matrix multiplication:

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

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

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

Assessing the model

Assessing the Model The least squares method will produces 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.

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 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 (or close) to zero

Coefficient of determination To measure the strength of the linear relationship we use the coefficient of determination. R2 takes on any value between zero and one. R2 = 1: Perfect match between the line and the data points. R2 = 0: There are no linear relationship between x and y.

Regression Diagnostics 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?

Residual Analysis Examining the residuals help detect violations of the required conditions. Checking to see if residuals (actual value – predicted value) are normally distributed with mean 0.

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

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 ^

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.

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.

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,575. How close is this prediction to the real price?

Procedure for Regression Diagnostics Develop a model that has a theoretical basis. Determine the regression equation. Check the required conditions for the errors. Assess the model fit. If the model fits the data, use the regression equation. NOTE: ALWAYS REMEMBER CORRELATION VS CAUSATION. As data miners, you almost never prove causation. Only correlation. http://www.tylervigen.com/spurious-correlations