Linear regression.

Slides:



Advertisements
Similar presentations
Computational Statistics. Basic ideas  Predict values that are hard to measure irl, by using co-variables (other properties from the same measurement.
Advertisements

Some terminology When the relation between variables are expressed in this manner, we call the relevant equation(s) mathematical models The intercept and.
A Short Introduction to Curve Fitting and Regression by Brad Morantz
Classification and Prediction: Regression Via Gradient Descent Optimization Bamshad Mobasher DePaul University.
Statistics for Managers Using Microsoft® Excel 5th Edition
Correlation and Regression Analysis
SIMPLE LINEAR REGRESSION
SIMPLE LINEAR REGRESSION
1 Chapter 17: Introduction to Regression. 2 Introduction to Linear Regression The Pearson correlation measures the degree to which a set of data points.
Solving Quadratic Equations Tammy Wallace Varina High.
Linear Equation: an equation whose graph forms a line. is linear. is not. In linear equations, all variables are taken to the first power. Linear means.
1 1 Slide Simple Linear Regression Chapter 14 BA 303 – Spring 2011.
Regression Analysis British Biometrician Sir Francis Galton was the one who used the term Regression in the later part of 19 century.
Linear Equations Section 2.4 Equation comes from the Latin aequus meaning “even” or “level”. An equation is a statement in which two algebraic expressions.
SIMPLE LINEAR REGRESSION
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression Chapter.
Statistics for Business and Economics 8 th Edition Chapter 11 Simple Regression Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall Ch.
Simple Linear Regression
1 FORECASTING Regression Analysis Aslı Sencer Graduate Program in Business Information Systems.
Analytical vs. Numerical Minimization Each experimental data point, l, has an error, ε l, associated with it ‣ Difference between the experimentally measured.
Regression For the purposes of this class: –Does Y depend on X? –Does a change in X cause a change in Y? –Can Y be predicted from X? Y= mX + b Predicted.
Curve-Fitting Regression
Go to Table of Content Single Variable Regression Farrokh Alemi, Ph.D. Kashif Haqqi M.D.
2-4 Writing Linear Equations Objective: To write an equation of a line in slope intercept form given the slope and one or two points, and to write an equation.
Regression Regression relationship = trend + scatter
Simple Linear Regression. The term linear regression implies that  Y|x is linearly related to x by the population regression equation  Y|x =  +  x.
Correlation and Regression Basic Concepts. An Example We can hypothesize that the value of a house increases as its size increases. Said differently,
Introduction to Matrices and Matrix Approach to Simple Linear Regression.
Business Statistics: A Decision-Making Approach, 6e © 2005 Prentice-Hall, Inc. Chap 13-1 Introduction to Regression Analysis Regression analysis is used.
GRAPHING EQUATIONS. 6.EE.9 Use variables to represent two quantities in a real- world problem that change in relationship to one another; write an equation.
SWBAT: Calculate and interpret the residual plot for a line of regression Do Now: Do heavier cars really use more gasoline? In the following data set,
Unit 3 Sections 9.2 – Day 1.  After we determine that a relationship between two variables exists (correlation), the next step is determine the line.
Copyright © 2009 Pearson Education, Inc. CHAPTER 1: Graphs, Functions, and Models 1.1 Introduction to Graphing 1.2 Functions and Graphs 1.3 Linear Functions,
Economics 173 Business Statistics Lecture 10 Fall, 2001 Professor J. Petry
Linear Prediction Correlation can be used to make predictions – Values on X can be used to predict values on Y – Stronger relationships between X and Y.
Chapter 11: Linear Regression and Correlation Regression analysis is a statistical tool that utilizes the relation between two or more quantitative variables.
Curve Fitting Introduction Least-Squares Regression Linear Regression Polynomial Regression Multiple Linear Regression Today’s class Numerical Methods.
1 Simple Linear Regression and Correlation Least Squares Method The Model Estimating the Coefficients EXAMPLE 1: USED CAR SALES.
Algebra 2 January What are the 3 steps to graphing a linear equation? (section 2.2; Jan 12) 2. What is true about the slopes of perpendicular.
Y=3x+1 y 5x + 2 =13 Solution: (, ) Solve: Do you have an equation already solved for y or x?
System of Equations Solve by Substitution. A System of Equations:  Consists of two linear equations  We want to find out information about the two lines:
What does a “solution” look like? So, what’s the solution here?
Chapter 14 Introduction to Regression Analysis. Objectives Regression Analysis Uses of Regression Analysis Method of Least Squares Difference between.
Correlation and Regression Basic Concepts. An Example We can hypothesize that the value of a house increases as its size increases. Said differently,
1.6 Solving Linear Systems in Three Variables 10/23/12.
Linear regression. Case study Galactose diffusion in silica mesopore.
Chapter 12 Simple Regression Statistika.  Analisis regresi adalah analisis hubungan linear antar 2 variabel random yang mempunyai hub linear,  Variabel.
Graphing a Linear Equation A solution of an equation in two variables x and y is an ordered pair ( x, y ) that makes the equation true. The graph of an.
Elimination Method - Systems. Elimination Method  With the elimination method, you create like terms that add to zero.
3.5 Solving systems of equations in three variables Main Ideas Solve systems of linear equations in three variables. Solve real-world problems using systems.
R. E. Wyllys Copyright 2003 by R. E. Wyllys Last revised 2003 Jan 15
Ch12.1 Simple Linear Regression
SIMPLE LINEAR REGRESSION MODEL
Matrices Definition: A matrix is a rectangular array of numbers or symbolic elements In many applications, the rows of a matrix will represent individuals.
Simple linear equation
Lesson 5.3 How do you write linear equations in point-slope form?
Solve a system of linear equation in two variables
Graphing Linear Equations
Linear regression Fitting a straight line to observations.
Nonlinear regression.
Regression.
College Algebra Chapter 5 Systems of Equations and Inequalities
M248: Analyzing data Block D UNIT D2 Regression.
11C Line of Best Fit By Eye, 11D Linear Regression
SIMPLE LINEAR REGRESSION
Graphing Linear Equations
5.8 Modeling with Quadratic Functions
Graphing Linear Equations
Regression and Correlation of Data
Presentation transcript:

Linear regression

How to analyse data?

How to analyse data? Plot!

Human brain is one the most powerfull computationall tools How to analyse data? Plot! Human brain is one the most powerfull computationall tools Works differently than a computer…

Simple example – finding maximum y(xmax) Computer 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Computer Set y(xmax) = y(x1). 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Computer Set y(xmax) = y(x1). Go to the next point x2: 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Computer Set y(xmax) = y(x1). Go to the next point x2: If y(x2) > y(xmax) then xmax = x2 2. Else do nothing. 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Computer Set y(xmax) = y(x1). Go to the next point x2: If y(x2) > y(xmax) then xmax = x2 2. Else do nothing. 3. Repeat this procedure until you reach the end. 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Human brain 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Here! Human brain 3 2 1 x1 x2 x3

Simple example – finding maximum y(xmax) Here! Human brain 3 With increasing number of points quicker answer 2 1 x1 x2 x3

How to analyse data? Plot x against y Observe trend - correlation

How to „measure” linearity? Geometry 𝐚 𝒃

How to measure angle between two vectors? Scalar product 𝐚 𝜶 𝒃

How to measure angle between two vectors? Scalar product 𝒂 =( 𝒂 𝟏 , 𝒂 𝟐 ), 𝒃 =( 𝒃 𝟏 , 𝒃 𝟐 ) 𝐚 𝜶 𝒃

How to measure angle between two vectors? Scalar product 𝒂 =( 𝒂 𝟏 , 𝒂 𝟐 ), 𝒃 =( 𝒃 𝟏 , 𝒃 𝟐 ) 𝐚 𝒂 𝒐 𝒃 = 𝒂 𝟏 𝒃 𝟏 + 𝒂 𝟐 𝒃 𝟐 = 𝒊=𝟏 𝟐 𝒂 𝒊 𝒃 𝒊 𝜶 𝒃

How to measure angle between two vectors? Scalar product 𝒂 =( 𝒂 𝟏 , 𝒂 𝟐 ), 𝒃 =( 𝒃 𝟏 , 𝒃 𝟐 ) 𝐚 𝒂 𝒐 𝒃 = 𝒂 𝟏 𝒃 𝟏 + 𝒂 𝟐 𝒃 𝟐 𝜶 𝒂 𝒐 𝒂 = 𝒂 𝟏 𝟐 + 𝒂 𝟐 𝟐 𝒃

How to measure angle between two vectors? Scalar product 𝒂 =( 𝒂 𝟏 , 𝒂 𝟐 ), 𝒃 =( 𝒃 𝟏 , 𝒃 𝟐 ) 𝐚 𝒂 𝒐 𝒃 = 𝒂 𝟏 𝒃 𝟏 + 𝒂 𝟐 𝒃 𝟐 𝜶 𝒂 𝒐 𝒂 = 𝒂 𝟏 𝟐 + 𝒂 𝟐 𝟐 𝒃 𝒄𝒐𝒔 𝜶 = 𝒂 𝒐 𝒃 𝒂 𝒃

Example 𝒛 𝒙 𝒚

Example How to do it? 𝒛 𝒙 𝒚

Example How to do it? We choose two vectors 𝒛 𝐚 𝒃 𝒙 𝒚

Example How to do it? We choose two vectors 𝒛 𝐚 𝒃 𝒙 𝒚 𝒂 =(𝟏,𝟎,𝟏), 𝒃 =(𝟎,𝟏,𝟏) 𝐚 𝒃 𝒙 𝒚

Example How to do it? We choose two vectors 𝒛 𝐚 𝒃 𝒙 𝒚 𝒂 =(𝟏,𝟎,𝟏), 𝒃 =(𝟎,𝟏,𝟏) 𝐚 𝒄𝒐𝒔 𝜶 = 𝒂 𝒐 𝒃 𝒂 𝒃 𝒃 𝒙 𝒚 𝜶=𝟔 𝟎 𝒐

Example How to do it? We choose two vectors 𝒛 𝐚 𝒃 𝒙 𝒚 𝒂 =(𝟏,𝟎,𝟏), 𝒃 =(𝟎,𝟏,𝟏) 𝐚 𝒄𝒐𝒔 𝜶 = 𝒂 𝒐 𝒃 𝒂 𝒃 𝒃 𝒙 𝒄𝒐𝒔 𝜶 = 𝟏,𝟎,𝟏 𝒐 𝟎,𝟏,𝟏 (𝟏,𝟎,𝟏) 𝟎,𝟏,𝟏 𝒚

Example How to do it? We choose two vectors 𝒛 𝐚 𝒃 𝒙 𝒚 𝒂 =(𝟏,𝟎,𝟏), 𝒃 =(𝟎,𝟏,𝟏) 𝐚 𝒄𝒐𝒔 𝜶 = 𝒂 𝒐 𝒃 𝒂 𝒃 𝒃 𝒙 𝒄𝒐𝒔 𝜶 = 𝟏,𝟎,𝟏 𝒐 𝟎,𝟏,𝟏 (𝟏,𝟎,𝟏) 𝟎,𝟏,𝟏 = 𝟏∗𝟎+𝟎∗𝟏+𝟏∗𝟏 𝟐 𝟐 = 𝟏 𝟐 𝒚

Example How to do it? We choose two vectors 𝒛 𝐚 𝒃 𝒙 𝒚 𝒂 =(𝟏,𝟎,𝟏), 𝒃 =(𝟎,𝟏,𝟏) 𝐚 𝒄𝒐𝒔 𝜶 = 𝒂 𝒐 𝒃 𝒂 𝒃 𝒃 𝒙 𝒄𝒐𝒔 𝜶 = 𝟏,𝟎,𝟏 𝒐 𝟎,𝟏,𝟏 (𝟏,𝟎,𝟏) 𝟎,𝟏,𝟏 = 𝟏∗𝟎+𝟎∗𝟏+𝟏∗𝟏 𝟐 𝟐 = 𝟏 𝟐 𝒚 𝜶=𝟔 𝟎 𝒐

What’s the relevance? Two sets of data Data are vectors! X 1 2 3 4 Y 2 4.1 5.4 8.3 y4 y3 y2 𝒙 =(𝟏, 𝟐, 𝟑, 𝟒) 𝒚 =(𝟐, 𝟒.𝟏, 𝟓.𝟒, 𝟖.𝟑) y1 Data are vectors! x1 x2 x3 x4

What’s the relevance? Two sets of data Linear relationship parallel 𝒚 X 1 2 3 4 Y 2 4.1 5.4 8.3 y4 𝒚 =𝒂∗ 𝒙 y3 Linear relationship y2 y1 𝒚 parallel x1 x2 x3 x4 𝒙

How to measure parallelism between two vectors? Linear relationship 𝒚 y4 𝒙 parallel = zero angle y3 y2 y1 𝜶≈𝟎→𝒄𝒐𝒔 𝜶 ≈𝟏 x1 x2 x3 x4

How to calculute the angle? Scalar product! Two sets of data X 1 2 3 4 Y 2 4.1 5.4 8.3 y4 y3 cos 𝜶 = 𝒙 𝒐 𝒚 𝒙| 𝒚 | = 𝒊=𝟏 𝒏 𝒙 𝒊 𝒚 𝒊 𝒊=𝟏 𝒏 𝒙 𝒊 𝟐 𝒊=𝟏 𝒏 𝒚 𝒊 𝟐 y2 y1 x1 x2 x3 x4

How to calculute the angle? Scalar product! Changing origin (0,0)  𝒙 , 𝒚 𝑹 𝟐 =cos 𝜶 = 𝒊=𝟏 𝒏 (𝒙 𝒊 − 𝒙 ) (𝒚 𝒊 − 𝒚 ) 𝒊=𝟏 𝒏 (𝒙 𝒊 − 𝒙 ) 𝟐 𝒊=𝟏 𝒏 𝒚 𝒊 − 𝒚 𝟐 𝑦 𝒙 = 𝟏 𝒏 𝒊=𝟏 𝒏 𝒙 𝒊 , 𝒚 = 𝟏 𝒏 𝒊=𝟏 𝒏 𝒚 𝒊 𝑥

Our case Two sets of data 𝑹 𝟐 = 𝟏𝟎.𝟏 𝟓 𝟐𝟎.𝟖𝟓 =𝟎.𝟗𝟖 X 1 2 3 4 Y 2 4.1 5.4 8.3 y4 y3 𝑥 = 1+2+3+4 4 =2.5 𝑦 = 2+4.1+5.4+8.3 4 =4.95 𝑥− 𝑥 -1.5 -0.5 0.5 1.5 y2 𝑦− 𝑦 -2.95-0.85 0.45 3.35 𝒊=𝟏 𝒏 (𝒙 𝒊 − 𝒙 ) (𝒚 𝒊 − 𝒚 )=(−𝟏.𝟓∗−𝟐.𝟗𝟓)+(−𝟎.𝟓∗−𝟎.𝟖𝟓)+(𝟎.𝟓∗𝟎.𝟒𝟓)+(𝟏.𝟓∗𝟑.𝟑𝟓)=𝟏𝟎.𝟏 y1 x1 x2 x3 x4 ( 𝒊=𝟏 𝒏 (𝒙 𝒊 − 𝒙 ) 𝟐 =𝟓 𝒊=𝟏 𝒏 𝒚 𝒊 − 𝒚 𝟐 =𝟐𝟎.𝟖𝟓 𝑹 𝟐 = 𝟏𝟎.𝟏 𝟓 𝟐𝟎.𝟖𝟓 =𝟎.𝟗𝟖

What is the best position of the line? The best = smallest error X 1 2 3 4 Y 2 4.1 5.4 8.3 Error = data value – estimated value

What is the best position of the line? The best = smallest error X 1 2 3 4 Y 2 4.1 5.4 8.3 𝑆𝑆𝐸= 𝑖=1 𝑛 𝐸 𝑖 2 = 𝑖=1 𝑛 𝑦 𝑖 −𝑓 𝑥 𝑖 2 𝑦 2 𝐸 1 = 𝑦 1 −𝑓( 𝑥 1 ) 𝐸 2 𝑓 𝑥 2 𝑓 𝑥 1 𝐸 2 = 𝑦 2 −𝑓 𝑥 2 𝐸 1 𝑓 𝑥 =𝑎𝑥+𝑏 𝑦 1 𝑆𝑆𝐸= 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 𝐸 𝑖 = 𝑦 𝑖 −𝑓 𝑥 𝑖

How to adjust a and b so SSE is the smallest? 𝑆𝑆𝐸(𝑎,𝑏)= 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 How to calculate minimum of the SSE(a,b) function? 𝜕𝑆𝑆𝐸 𝑎,𝑏 𝜕𝑎 =0 𝜕𝑆𝑆𝐸 𝑎,𝑏 𝜕𝑏 =0

How to adjust a and b so SSE is the smallest? 𝑆𝑆𝐸(𝑎,𝑏)= 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 𝜕𝑆𝑆𝐸 𝑎,𝑏 𝜕𝑎 = 𝜕 𝜕𝑎 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 = 𝑖=1 𝑛 𝜕 𝜕𝑎 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 = 𝑖=1 𝑛 − 𝑥 𝑖 ∗2 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 =−2 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 𝜕𝑆𝑆𝐸 𝑎,𝑏 𝜕𝑏 = 𝜕 𝜕𝑏 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 = 𝑖=1 𝑛 𝜕 𝜕𝑏 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 = 𝑖=1 𝑛 −2 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 =−2 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏

How to adjust a and b so SSE is the smallest? 𝑆𝑆𝐸(𝑎,𝑏)= 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 2 𝜕𝑆𝑆𝐸 𝑎,𝑏 𝜕𝑎 =0 →−2 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 =0 𝜕𝑆𝑆𝐸 𝑎,𝑏 𝜕𝑏 =0→−2 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 =0

We obtain a set of linear equations of two variables a and b 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 =0 𝑖=1 𝑛 (𝑥 𝑖 𝑦 𝑖 −𝑎 𝑥 𝑖 2 −𝑏 𝑥 𝑖 )=0 𝑎 𝑖=1 𝑛 𝑥 𝑖 2 +𝑏 𝑖=1 𝑛 𝑥 𝑖 − 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 =0 𝑖=1 𝑛 𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏 =0 𝑖=1 𝑛 (𝑦 𝑖 −𝑎 𝑥 𝑖 −𝑏)=0 𝑎 𝑖=1 𝑛 𝑥 𝑖 +𝑏 𝑖=1 𝑛 1− 𝑖=1 𝑛 𝑦 𝑖 =0

Finally… Set of linear equations 𝑎 𝑖=1 𝑛 𝑥 𝑖 2 +𝑏 𝑖=1 𝑛 𝑥 𝑖 − 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 =0 𝑎 𝑖=1 𝑛 𝑥 𝑖 2 +𝑏 𝑖=1 𝑛 𝑥 𝑖 = 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 𝑎 𝑖=1 𝑛 𝑥 𝑖 +𝑏 𝑖=1 𝑛 1− 𝑖=1 𝑛 𝑦 𝑖 =0 𝑎 𝑖=1 𝑛 𝑥 𝑖 +𝑏𝑛= 𝑖=1 𝑛 𝑦 𝑖 𝑖=1 𝑛 𝑥 𝑖 2 𝑖=1 𝑛 𝑥 𝑖 𝑖=1 𝑛 𝑥 𝑖 𝑛 𝑎 𝑏 = 𝑖=1 𝑛 𝑥 𝑖 𝑦 𝑖 𝑖=1 𝑛 𝑦 𝑖

How to solve it? Set of linear equations. 𝒊=𝟏 𝒏 𝒙 𝒊 𝟐 𝒊=𝟏 𝒏 𝒙 𝒊 𝒊=𝟏 𝒏 𝒙 𝒊 𝒏 𝒂 𝒃 = 𝒊=𝟏 𝒏 𝒙 𝒊 𝒚 𝒊 𝒊=𝟏 𝒏 𝒚 𝒊 𝑨𝒙=𝒃

Has solution if 𝒅𝒆𝒕 𝑨 ≠𝟎 𝒙 𝟐 − 𝒙 𝟐 ≠𝟎 𝒙 𝟐 𝒙 𝑪𝒐𝒗 𝑿,𝑿 ≠𝟎 𝒊=𝟏 𝒏 𝒙 𝒊 𝟐 𝒊=𝟏 𝒏 𝒙 𝒊 𝒊=𝟏 𝒏 𝒙 𝒊 𝒏 =𝒏 𝒊=𝟏 𝒏 𝒙 𝒊 𝟐 − 𝒊=𝟏 𝒏 𝒙 𝒊 𝒊=𝟏 𝒏 𝒙 𝒊 ≠𝟎 𝟏 𝒏 𝒊=𝟏 𝒏 𝒙 𝒊 𝟐 − 𝟏 𝒏 𝒊=𝟏 𝒏 𝒙 𝒊 𝟏 𝒏 𝒊=𝟏 𝒏 𝒙 𝒊 ≠𝟎 𝒙 𝟐 𝒙 𝒙 𝟐 − 𝒙 𝟐 ≠𝟎 𝑪𝒐𝒗 𝑿,𝑿 ≠𝟎

Linear regression procedure Plot data – make observation, decide which model fits best. If you decide to use linear regression – compute 𝑹 𝟐 . Solve linear regression problem.