Least squares regression

Similar documents
Curve Fitting and Interpolation

Curve Fitting. Objectives

Regression and Nonlinear Axes

Exam 2. Average: 85.6 Median: 87.0 Maximum: Minimum: 55.0 Standard Deviation: Numerical Methods Fall 2011 Lecture 20

Curve Fitting. Least Squares Regression. Linear Regression

Interpolation and Polynomial Approximation I

Cubic Splines MATH 375. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Cubic Splines

Interpolation (Shape Functions)

CURVE FITTING LEAST SQUARE LINE. Consider the class of linear function of the form. = Ax+ B...(1)

Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. What for x = 1.2?

MATH ASSIGNMENT 07 SOLUTIONS. 8.1 Following is census data showing the population of the US between 1900 and 2000:

Salinity Calibration fit with Matlab

Interpolation APPLIED PROBLEMS. Reading Between the Lines FLY ROCKET FLY, FLY ROCKET FLY WHAT IS INTERPOLATION? Figure Interpolation of discrete data.

(0, 0), (1, ), (2, ), (3, ), (4, ), (5, ), (6, ).

Part I 5. Part II 2. Part III 8. Part IV 10. Part V 5 TOTAL 30

Math 307: Problems for section 3.1

5.3. Polynomials and Polynomial Functions

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

Q1. Discuss, compare and contrast various curve fitting and interpolation methods

Linear Equations. Find the domain and the range of the following set. {(4,5), (7,8), (-1,3), (3,3), (2,-3)}

Review of Section 1.1. Mathematical Models. Review of Section 1.1. Review of Section 1.1. Functions. Domain and range. Piecewise functions

The highest degree term is x $, therefore the function is degree 4 (quartic) c) What are the x-intercepts?

CHAPTER Order points and then develop a divided difference table:

Polynomial Functions

AMTH142 Lecture 16. Least Squares

Lecture 10 Polynomial interpolation

Preliminaries Lectures. Dr. Abdulla Eid. Department of Mathematics MATHS 101: Calculus I

Math 1311 Section 5.5 Polynomials and Rational Functions

General Linear Least-Squares and Nonlinear Regression

Least Squares Regression

Quantitative Techniques (Finance) 203. Polynomial Functions

Q 0 x if x 0 x x 1. S 1 x if x 1 x x 2. i 0,1,...,n 1, and L x L n 1 x if x n 1 x x n

ERASMUS UNIVERSITY ROTTERDAM Information concerning the Entrance examination Mathematics level 2 for International Business Administration (IBA)

POLYNOMIAL FUNCTIONS. Chapter 5

Chapter 1 Numerical approximation of data : interpolation, least squares method

Functions: Polynomial, Rational, Exponential

Newton s Method and Linear Approximations

Steps for Regression. Simple Linear Regression. Data. Example. Residuals vs. X. Scatterplot. Make a Scatter plot Does it make sense to plot a line?

Non-Linear Regression

Engineering 7: Introduction to computer programming for scientists and engineers

6x 2 8x + 5 ) = 12x 8. f (x) ) = d (12x 8) = 12

SPLINE INTERPOLATION

Statistics 3657 : Moment Approximations

Ordinary Differential Equations (ode)

BSM510 Numerical Analysis

Evaluate and Graph Polynomial Functions

6x 2 8x + 5 ) = 12x 8

MA3457/CS4033: Numerical Methods for Calculus and Differential Equations

Histogram of Residuals. Residual Normal Probability Plot. Reg. Analysis Check Model Utility. (con t) Check Model Utility. Inference.

Simple Linear Regression. Steps for Regression. Example. Make a Scatter plot. Check Residual Plot (Residuals vs. X)

Matrix Theory and Differential Equations Homework 2 Solutions, due 9/7/6

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

Newton s Method and Linear Approximations

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. C) x 8. C) y = x + 3 2

a factors The exponential 0 is a special case. If b is any nonzero real number, then

A monomial or sum of monomials

Logarithmic Functions

Computational Physics

Interpolation Theory

Copula Regression RAHUL A. PARSA DRAKE UNIVERSITY & STUART A. KLUGMAN SOCIETY OF ACTUARIES CASUALTY ACTUARIAL SOCIETY MAY 18,2011

Newton s Method and Linear Approximations 10/19/2011

1 Piecewise Cubic Interpolation

Math Numerical Analysis Mid-Term Test Solutions

Numerical interpolation, extrapolation and fi tting of data

Applied Numerical Analysis Homework #3

Wed. Sept 28th: 1.3 New Functions from Old Functions: o vertical and horizontal shifts o vertical and horizontal stretching and reflecting o

Taylor Series and Numerical Approximations

polynomial function polynomial function of degree n leading coefficient leading-term test quartic function turning point

A Library of Functions

Practice Calculus Test without Trig

MA.8.1 Students will apply properties of the real number system to simplify algebraic expressions and solve linear equations.

INTERPOLATION. and y i = cos x i, i = 0, 1, 2 This gives us the three points. Now find a quadratic polynomial. p(x) = a 0 + a 1 x + a 2 x 2.

Observations Homework Checkpoint quizzes Chapter assessments (Possibly Projects) Blocks of Algebra

AP Physics C Mechanics Calculus Basics

Cubic Splines; Bézier Curves

Lesson 6 Maximum Likelihood: Part III. (plus a quick bestiary of models)

Lecture 5 - Logarithms, Slope of a Function, Derivatives

CCSS TRADITIONAL PATHWAY ALGEBRA I CONTENT MAP

Polynomial Functions. x n 2 a n. x n a 1. f x = a o. x n 1 a 2. x 0, , a 1

Review for Mastery. Integer Exponents. Zero Exponents Negative Exponents Negative Exponents in the Denominator. Definition.

Algebra III Chapter 2 Note Packet. Section 2.1: Polynomial Functions

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 53L Fall Test III. Rebecca A. Simmons & Michael R. Gustafson II

Lecture Note 3: Interpolation and Polynomial Approximation. Xiaoqun Zhang Shanghai Jiao Tong University

Summer Packet for Students Taking Introduction to Calculus in the Fall

f(x) = 2x + 5 3x 1. f 1 (x) = x + 5 3x 2. f(x) = 102x x

Quartic Equation. By CH vd Westhuizen A unique Solution assuming Complex roots. Ax^4 + Bx^3 + Cx^2 + Dx + E = 0

Math 120 Winter Handout 3: Finding a Formula for a Polynomial Using Roots and Multiplicities

CURVE FITTING LEAST SQUARE LINE. Consider the class of linear function of the form

A Story of Functions Curriculum Overview

ALGEBRA 1 PACING GUIDE

ERASMUS UNIVERSITY ROTTERDAM

AP Calculus AB. Review for Test: Applications of Integration

Announcements. Topics: Homework: - sections , 6.1 (extreme values) * Read these sections and study solved examples in your textbook!

UP AND UP DOWN AND DOWN DOWN AND UP UP AND DOWN

Global polynomial interpolants suffer from the Runge Phenomenon if the data sites (nodes) are not chosen correctly.

Test #1 Polynomial Functions Mr. Oldridge MHF4U [Created Summer 2011]

The Laplace Transform. Background: Improper Integrals

Cubic Spline. s(x) = s j (x) = a j + b j (x x j ) + c j (x x j ) 2 + d j (x x j ) 3, j = 0,... n 1 (1)

Solutions to Problems and

Calculus I Homework: The Derivatives of Polynomials and Exponential Functions Page 1

Transcription:

Curve Fitting Least squares regression Interpolation

Two categories of curve fitting. 1. Linear least squares regression, determining the straight line that best fits data points. 2. Interpolation, determining a curved line that goes through a series of points.

Linear Least Squares Regression (to find the formula of a straight line that best fits data points) e i The vertical distance, e i, between data point i and a straight line is, e = y a a x i i 0 1 i The goal is to minimize n i= 1 e i

Instead of minimizing the sum of the distances, minimizing the sum of the squares of the distances (the residuals) has the sameeffecteffect and is easier mathematically. n n 2 r = i = i 0 1 i i= 1 i= 1 ( ) 2 S e y a a x How can we find the values of a 0 and a 1 to minimize S r?

In the case of a function f = f(x), we can find the minimum by setting the derivative of f with respect to x equal to zero, df dx = 0 But S r is a function of two variables, a 0 and a 1, S r (a 0,a 1 ); therefore, S a r Sr = 0& = 0 a 0 1

Evaluation of derivatives, S n = 2 y a a x = 0 r ( ) i 0 1 i a 0 i= 1 and n Sr = 2 ( y ) i a0 a1xi xi = 0 a 1 i= 1 y i a 0 a1xi 0 = and yx ax ax 2 i i 0 i 1 i = 0

Rearrange, + = na a x y 0 1 i i y a x + a x = y x 2 0 i 1 i i i 2 The values, n, x, y, x, y x i i i i i can be determined dfrom the data.

Solve for a 0 and a 1. 0 1 a n x y x y = ( ) i i i i 1 2 2 n xi xi a0 = y a1x where, x y = xi n y i = n

Example (using MATLAB for calculations) >> x = [0 2 4 6 9 11 12 15 17 19]; >> y = [5 6 7 6 9 8 7 10 12 12]; >> sumxy = sum(x.*y) sumxy = 911 >> sumx = sum(x); >> sumy = sum(y); >> sumx2 = sum(x.^2); >> n = size(x,2) n = 10 >> a1 = (n*sumxy sumx*sumy) / (n*sumx2 sumx^2) a1 = 0.3525 >> xmean = sumx/n; >> ymean = sumy/n; >> a0 = ymean a1*xmean a0 = 4.8515 >> xx = linspace(0,20); >> yy = a1*xx + a0; >> plot(xx,yy,x,y,'o )

Non linear least squares residuals. Some non linear formulas for y = y(x) can be linearized to linear formulas. β 1 x y = α e ln y = β x+ ln α 1 1 1 β2 y x y β x = α ln = β ln + lnα 2 2 2 y x 1 β + x β 1 1 3 3 = α 3 = = + β3+ x y α3x α3 x α3

Example To Find: Fit an exponential model to, x 04 0.4 08 0.8 12 1.2 16 1.6 2 23 2.3 y 800 975 1500 1950 2900 3600 Solution: Linearize the exponential equation, β1x y e ln y x = α = β + lnα 1 1 1

Calculations using MATLAB β1x y e ln y x = α = β + lnα 1 1 1 >> x = [.4 [4.8 1.2 12162 1.6 2 23]; 2.3]; >> y = [800 975 1500 1950 2900 3600]; >> lny = log(y); >> p = polyfit(x,lny,1); >> beta1 = p(1) beta1 = 0.8187 >> alpha1 = exp(p(2)) alpha1 = 546.5909 >> xx = linspace(.2,2.4); >> yy = alpha1*exp(beta1*xx); >> plot(xx,yy,x,y,'h') >> y = 546.6e 0.819x

Using Excel for linear regressions, 4000 3500 3000 2500 y = 546.59e 0.8187x R² = 0.9933 y 2000 y 1500 Expon. (y) 1000 500 0 0 0.5 1 1.5 2 2.5

Interpolation Interpolation with polynomials If n data points are given, a polynomial of degree n 1 can be determined that passes through all the points. >> x = [0 1 2 3]; >> y = [0 2 1 4]; >> p = polyfit(x,y,3) p = 2.1667 9.0000 8.8333 0.0000 >> xx = linspace(0,3); >> yy = polyval(p,xx); >> plot(x,y,'o',xx,yy) 3 2 y = 2.1667 x 9.0000 x + 8.8333 8333x

If the n data points are know to represent a polynomial, then using polyfit with degree n 1 is suitable for interpolation. If, however, the data points do not come from a polynomial function then higher order polynomials will not, in general, provide a good fit.

1 Example using Runge s function f ( x ) = 2 1+ 25x Data points from Runge s function x 1.0000 0.7500 0.5000 0.2500 0 0.2500 0.5000 0.7500 1.0000 y 0.0385 0.0664 0.1379 0.3902 1.0000 0.3902 0.1379 0.0664 0.0385 Use the 9 points to create an 8 th degree polynomial and plot both Runge s function and the polynomial. >> x = linspace( 1,1,9); >> y = 1./(1+25*x.^2); >> p = polyfit(x,y,8); (,y,); >> xx = linspace( 1,1); >> yy = 1./(1+25*xx.^2); >> yyp = polyval(p,xx); >> plot(x,y, y'o',xx,yy, 'g',xx,yyp, 'r') >>

Interpolation using splines Splines are connected piecewise polynomials (linear, quadratic, cubic, quartic, etc.) that go from one data point to the next. In order to determine the coefficients of the In order to determine the coefficients of the polynomials, point location plus continuity of 1 st, 2 nd, etc. derivatives are used.

Consider the splines that connect the points. Spline 1 Point 1 2 Spline 2 Spline 3 Point 2 3 At point 1 2, the location, the slope, and the inflection of both spline 1 and spline 2 must match; likewise, at point 2 3, the same for splines 2 and 3. This information allows the coefficients of the cubic splines to be determined.

Usefulness of splines Splines are more versatile than polynomials for interpolating the regions between data points. Example (Runge s function) >> x = linspace( 1,1,9); >> y = 1./(1+25*x.^2); >> xx = linspace( 1,1); >> yy = 1./(1+25*xx.^2); >> yspline = spline(x,y,xx); >> plot(x,y,'o',xx,yy,'r',xx,yspline,'g') N h h i l i i id bl b Note that the interpolation is considerably better than that with the 8 th order polynomial.

Eample Example using splines for interpolation Consider data for an exponential curve. x 0 0.2500 0.5000 0.7500 1.0000 y 1.0000 1.0157 1.1331 1.5248 2.7183 Determine the y value at x = 0.9 using splines. >> x = linspace(0,1,5); >> y = exp(x.^3); >> yp9 = spline(x,y,0.9) yp9 = 2.1052 >> yactual =exp((0.9)^3) yactual = 2.0730 >>