Non-Linear Regression Samuel L. Baker

Similar documents
The Mean Version One way to write the One True Regression Line is: Equation 1 - The One True Line

Essential Maths 1. Macquarie University MAFC_Essential_Maths Page 1 of These notes were prepared by Anne Cooper and Catriona March.

FinQuiz Notes

Every equation implies at least two other equation. For example: The equation 2 3= implies 6 2 = 3 and 6 3= =6 6 3=2

1. Define the following terms (1 point each): alternative hypothesis

Module 9: Further Numbers and Equations. Numbers and Indices. The aim of this lesson is to enable you to: work with rational and irrational numbers

Conceptual Explanations: Logarithms

Solving Systems of Linear Equations Symbolically

Section 2.1: Reduce Rational Expressions

ab is shifted horizontally by h units. ab is shifted vertically by k units.

Chaos and Dynamical Systems

b) 2( ) a) Write an equation that models this situation. Let S = yearly salary and n = number of yrs since 1990.

4.6 (Part A) Exponential and Logarithmic Equations

7.8 Improper Integrals

QUADRATIC EQUATIONS EXPECTED BACKGROUND KNOWLEDGE

Finding Complex Solutions of Quadratic Equations

Simple linear regression: linear relationship between two qunatitative variables. Linear Regression. The regression line

Expansion formula using properties of dot product (analogous to FOIL in algebra): u v 2 u v u v u u 2u v v v u 2 2u v v 2

Polynomial Degree and Finite Differences

7.1 Exponential Functions

A population of 50 flies is expected to double every week, leading to a function of the x

3.5 Solving Quadratic Equations by the

1Number ONLINE PAGE PROOFS. systems: real and complex. 1.1 Kick off with CAS

f 0 ab a b: base f

At first numbers were used only for counting, and 1, 2, 3,... were all that was needed. These are called positive integers.

Solutions to Problems and

Regression with Nonlinear Transformations

Sample Solutions from the Student Solution Manual

Regression and Nonlinear Axes

INEQUALITIES. Inequalities PASSPORT

GOOD LUCK! 2. a b c d e 12. a b c d e. 3. a b c d e 13. a b c d e. 4. a b c d e 14. a b c d e. 5. a b c d e 15. a b c d e. 6. a b c d e 16.

MTH 65 WS 3 ( ) Radical Expressions

Creating Good Equations for the Classroom: Rational, Logarithmic and Square Root aversion ""Î# 9Î#!"'

we make slices perpendicular to the x-axis. If the slices are thin enough, they resemble x cylinders or discs. The formula for the x

School of Business. Blank Page

Mathematics Background

find the constant of variation. Direct variations are proportions.

Intermediate Algebra Chapter 12 Review

AQA GCSE Maths Foundation Skills Book Statistics 1

Short Solutions to Review Material for Test #2 MATH 3200

Physics 210: Worksheet 26 Name:

Volatility. Gerald P. Dwyer. February Clemson University

7.4* General logarithmic and exponential functions

Math Review ECON 300: Spring 2014 Benjamin A. Jones MATH/CALCULUS REVIEW

Algebra I Notes Concept 00b: Review Properties of Integer Exponents

Biostatistics and Design of Experiments Prof. Mukesh Doble Department of Biotechnology Indian Institute of Technology, Madras

Weak bidders prefer first-price (sealed-bid) auctions. (This holds both ex-ante, and once the bidders have learned their types)

Mathematical Ideas Modelling data, power variation, straightening data with logarithms, residual plots

Growth and Decay Models

Chapter 6. Logistic Regression. 6.1 A linear model for the log odds

Dynamical Systems Solutions to Exercises

Section 8.5. z(t) = be ix(t). (8.5.1) Figure A pendulum. ż = ibẋe ix (8.5.2) (8.5.3) = ( bẋ 2 cos(x) bẍ sin(x)) + i( bẋ 2 sin(x) + bẍ cos(x)).

STEP Support Programme. Hints and Partial Solutions for Assignment 2

CHAPTER FIVE. Solutions for Section 5.1. Skill Refresher. Exercises

Graphs and polynomials

Project Two. James K. Peterson. March 26, Department of Biological Sciences and Department of Mathematical Sciences Clemson University

Math 103 Exam 4 MLC Sample Exam. Name: Section: Date:

12Variation UNCORRECTED PAGE PROOFS

Algebra I Notes Unit Nine: Exponential Expressions

Robot Position from Wheel Odometry

Multiple Regression Theory 2006 Samuel L. Baker

Inequalities. Inequalities. Curriculum Ready.

Physics 505 Homework No. 3 Solutions S3-1

PRE-CALCULUS: by Finney,Demana,Watts and Kennedy Chapter 3: Exponential, Logistic, and Logarithmic Functions 3.1: Exponential and Logistic Functions

Math 216 Second Midterm 28 March, 2013

CHAPTER 5 FUNCTIONAL FORMS OF REGRESSION MODELS

4. Find x, log 4 32 = x. 5. ln e ln ln e. 8. log log log 3 243

Simple Examples. Let s look at a few simple examples of OI analysis.

Boosting. b m (x). m=1

The following document was developed by Learning Materials Production, OTEN, DET.

Online Supplementary Appendix B

Uncertainty and Graphical Analysis

Class 7. Prediction, Transformation and Multiple Regression.

The Exponential function f with base b is f (x) = b x where b > 0, b 1, x a real number

Interpreting coefficients for transformed variables

Fast inverse for big numbers: Picarte s iteration

UNIT 5 QUADRATIC FUNCTIONS Lesson 2: Creating and Solving Quadratic Equations in One Variable Instruction

Introduction to Determining Power Law Relationships

Chapter 1 Review of Equations and Inequalities

EOQ and EPQ-Partial Backordering-Approximations

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

1 Caveats of Parallel Algorithms

Graphs and polynomials

Logarithmic Functions and Models Power Functions Logistic Function. Mathematics. Rosella Castellano. Rome, University of Tor Vergata

Chapter 13 - Inverse Functions

1 Systems of Differential Equations

Section 4.2 Logarithmic Functions & Applications

Single Peakedness and Giffen Demand

ECON2228 Notes 2. Christopher F Baum. Boston College Economics. cfb (BC Econ) ECON2228 Notes / 47

Chapter 7. Scatterplots, Association, and Correlation

Exponentials and Logarithms Review Part 2: Exponentials

Project Two. Outline. James K. Peterson. March 27, Cooling Models. Estimating the Cooling Rate k. Typical Cooling Project Matlab Session

Lecture 12. Functional form

Algebra 1 Khan Academy Video Correlations By SpringBoard Activity and Learning Target

. Divide common fractions: 12 a. = a b. = a b b. = ac b c. 10. State that x 3 means x x x, . Cancel common factors in a fraction : 2a2 b 3.

MCS 115 Exam 2 Solutions Apr 26, 2018

CDS M Phil Econometrics

Each element of this set is assigned a probability. There are three basic rules for probabilities:

Higher. Polynomials and Quadratics. Polynomials and Quadratics 1

Simple Regression Model (Assumptions)

Transcription:

NON-LINEAR REGRESSION 1 Non-Linear Regression 2006-2008 Samuel L. Baker The linear least squares method that you have een using fits a straight line or a flat plane to a unch of data points. Sometimes the true relationship that you want to model is curved, rather than flat. For example, if something is growing exponentially, which means growing at a steady rate, the relationship etween X and Y is curve, like that shown to the right. To fit something like this, you need non-linear regression. Often, you can adapt linear least squares to do this. The method is to create new variales from your data. The new variales are nonlinear functions of the variales in your data. If you construct your new variales properly, the curved function of your original variales can e expressed as a linear function of your new variales. We will e discussing two popular non-linear equation forms that are amenale to this technique: Equation Interpretation Linear Form Y = Ae u Y = AX u Y is growing (or shrinking) at a constant relative rate of. The elasticity of Y with respect to X is a constant,. ln(y) = ln(a) + + ln(u) ln(y) = ln(a) + ln(x) + ln(u) Consider the first equation, Y = Ae u. This is an exponential growth equation. is the growth rate. u is a random error term. If you take the logarithm of oth sides of that equation, you get ln(y) = ln(a) + + ln(u). This equation has logarithms in it, ut they relate in a linear way. It is in the form y=a++error, except that y, a, and the error are logarithms. (A review of logarithms and e is coming up on the next page. Bear with me until then.) This means that if you create a new variale, the ase-e logarithm of Y, written as ln(y), you can use the regular least squares method to fit ln(y) = ln(a) + + ln(u). That is a way of fitting the curve Y = Ae to your data. (We will go over this again after the review of logarithms.) Similarly, consider the second equation, Y = AX u. This is a constant-elasticity equation (more on why I call it that later), typically used for demand curves. Take the logarithm of oth sides of that equation and you get ln(y) = ln(a) + ln(x) + ln(u). For this equation, if you create the variale ln(y) and also a variale for the ase-e logarithm of X, written

NON-LINEAR REGRESSION 2 as ln(x), you can use the regular least squares method to fit the curve Y = AX to your data. Before we go further into how to use these new equations, we had etter review logarithms and e. Logarithms defined: If a = c then = logac. = logac is read, is the log to the ase a of c. I rememer the logarithm definition y rememering that: The log of 1 is 0, regardless of the ase. Anything to the 0 power is 1. If I can rememer those two facts, then I can aritrarily pick 10 as my ase and write: 0 10 = 1 and log101 = 0. From that I get a = c and log c =, y sustituting a for 10, for 0, and c for 1. a You can't take the log of 0 or of a negative numer. The c in logac must e a positive numer. e ( 2.718282) is the ase of the natural logarithms (log e is written ln ). Natural logarithms are used for continuous growth rates. Something growing at a 100% annual rate, compounded continuously, will grow to e times its original size in one year. (The diagram on the preceding page shows a 100% growth rate.) r Something growing at an r annual rate, compounded continuously, will grow to e times its original size in one year. In Excel, the function =EXP(A1) raises e the power of whatever numer is in cell A1. =LN(A1) takes the natural log of whatever is in cell A1. e Some exponential algera rules a+ a e = e e a a e = (e ) ln(a) e = a ln(a) e = a 0 e = 1 Some corresponding logarithm algera rules ln( a ) = ln( a )+ln( ) ln( a ) = ln( a ) a ln( e ) = a ln( 1 ) = 0 Non-linear models that can e made linear using logarithms: Now we can get ack to the curved models introduced at the eginning of this section and give fuller explanations.

NON-LINEAR REGRESSION 3 Constant growth or decay equation Y = Ae Suppose you re modeling a process that you think has continuous growth at a constant growth rate. This is like the diagram on page 1. You want to estimate the growth rate from your data. u Y = Ae u is your equation. X is often a measure of time. X goes up y 1 for each second, hour, day, year, or whatever time unit you are using. Sometimes, X is a measure of dosage. A is the starting amount, the amount expected when X is 0. is the relative growth rate, with continuous compounding. u is the random error. Notice that we multiply y the error, rather than adding or sutracting the error as in standard linear regression. u has a mean of 1 and is always igger than 0. u is never 0 or negative. Use this equation if: The analogy with steady growth or decay makes sense. Y cannot e 0 or negative. X can e positive, 0, or negative. The interpretation of in Y = Ae u: is the parameter in which you are most interested, usually. Your estimate of is your estimate of the relative change in Y associated with a unit change in X. (X+1) + Mathematically, if X goes up y 1, Y is multiplied y e. That is ecause Ae equals Ae, which equals Ae e, which is Y is multiplied y e. That may not look like relative change, ut it is, if you are using continuous compounding. People who use these models usually make a simpler statement aout. They say that if X goes up y 1, Y goes up y 100 percent. They mean that if X goes up y 1, Y is multiplied y (1+). For example, if your estimate for is 0.02, then it is said that if X goes up y 1, Y goes up y 2%, ecause Y is multiplied y 1.02. (1 +.02 = 1.02.) The 1+ idea is fine so long as is near 0. For small values of, e is close to 1+. Multiplying y 1+ is close to the same as multiplying y e. For example, if is 0.05 and X increases y 1, Y is multiplied y.5 e, which is aout 1.051, so Y really increases y 5.1%. That is pretty close to 5%. Most things in the financial world and the pulic health world grow pretty slowly, so the 1+ or -percent idea is OK. The downloadale file aout time series has more details on this. How to make the growth/decay equation linear: To convert Y = Ae u to a linear equation, take the natural log of oth sides: ln(y) = ln(ae u) Apply the rules aove and you get: ln(y) = ln(a) + + ln(u)

NON-LINEAR REGRESSION 4 To implement this, create a new variale y = ln(y). (The Y in the original equation is ig Y. The new variale is little y. ) Also, define v as equaling ln(u) and a as equaling ln(a). Susitute y for ln(y), a for ln(a), and v for ln(u) in ln(y) = ln(a) + + ln(u) and you get: y = a + + v This is a linear equation! It may seem like cheating to turn a curve equation into a straight line equation this way, ut that is how it s done. Doing the analysis this way is not exactly the same as fitting a curve to points using least squares. This method this method minimizes the sum of the squares of ln(y) - (ln(a) + ), not the sum of the squares of Y - Ae. In our equation, the error term is something we multiply y rather than add. Our equation is Y=Ae u, rather than Y = Ae +u. We make our equation Y=Ae u, rather than Y = Ae +u, so that when we take the log of oth sides we get an error, which we call v, the logarithm of u in the original equation, that ehaves like errors are supposed to ehave for linear regression. For example, for linear regression we have to assume that the error s expected value is 0. To make this work, we assume that the expected value of u is 1. That makes the expected value of ln(u) equal zero, ecause ln(1) = 0. In Y=Ae u, u is never 0 or negative, ut v can take on positive or negative values, ecause if u is less than 1, v=ln(u) is less than 0. When you transform Y=Ae u to y = a + + v and do a least squares regression, here is how you interpret the coefficients: is your estimate of the growth rate. a is your estimate of ln(a). To get an estimate of A, calcualte e to the a-hat power. Getting a prediction for Y from your prediction for y After you calculate a prediction for little y, you have to convert it to ig Y. Your prediction for Y = e Your prediction for y. In Excel, use the =EXP() function.

NON-LINEAR REGRESSION 5 An example The first two columns are your data in a dose-response experiment. The third column is calculated from the second y taking the natural logarithm. Your regression results are: Dose Bacteria LnBacteria 1 35500 10.4773 2 21100 9.95703 3 19700 9.88837 4 16600 9.71716 5 14200 9.561 6 10600 9.26861 7 10400 9.24956 8 6000 8.69951 9 5600 8.63052 10 3800 8.24276 11 3600 8.18869 12 3200 8.07091 13 2100 7.64969 14 1900 7.54961 15 1500 7.31322 LnBacteria is the dependent variale, with a mean of 8.8309284 Variale Coefficient Std Error T-statistic P-Value Intercept 10.57833 0.0597781 176.95997 0 Dose -0.2184253 0.0065747-33.222015 0 You have found that each dose reduces the numer of acteria y aout 22%. Prediction, showing how it is calculated: Variale Coefficient * Your Value = Product Intercept 10.57833 1.0 10.57833 Dose -0.2184253 16.0-3.4948041 Total is the prediction: 7.0835264 90% conf. interval is 6.861792 to 7.3052607 7.0835264 Your prediction for the numer of acteria if the dose is 16 is e = 1192. In Excel, calculate 6.861792 7.3052607 =EXP(7.0835264). The 90% confidence interval for that prediction is from e to e, which is aout 955 to 1488.

NON-LINEAR REGRESSION 6 Constant elasticity equation Y=AX u Another non-linear equation that is commonly used is the constant elasticity model. Applications include supply, demand, cost, and production functions. Y = AX u is your equation X is some continuous variale that s always igger than 0. A determines the scale. is the elasticity of Y with respect to X (more on elasticity elow). u, the error, has a mean of 1 and is always igger than 0. Use this equation if: Graph of Y=X 2 u u is log-normally distriuted with a mean of 1. X and Y are always positive. X and Y can not e 0 or negative. You suspect, or wish to test for, diminishing ( <1) or increasing ( >1) returns to scale If it is reasonale that the percentage change in Y caused y a 1% change in X is the same at any level of X (or any level of Z, if you are doing a multiple regression). That is why this is called a constant elasticity equation. A constant elasticity model can never give a negative prediction. If a negative prediction would make sense, you do not want this model. If a negative prediction would not make sense, this model may e what you want. The interpretation of, the elasticity: is the percentage change in Y that you get when X changes y 1%. Economists call the elasticity of Y with respect to X. If is positive, you see a pattern like in the diagram aove. If is negative in this equation, the pattern is like a hyperola. The points get closer and closer to the X axis as you go the right. The points get closer and closer to the Y axis and they get higher and higher as X goes to the left and gets near 0. If you do a multiple regression version of this, with the equation Y = c A X Z u, then is the percentage change in Y that you get when X changes y 1% and Z does not change. Economists say and c are elasticities of Y with respect to X and Z. -1 <1 example: Y = 5x u How to make this linear: If you take the log of oth sides of Y = A X u, you get:

NON-LINEAR REGRESSION 7 ln(y) = ln(a) + ln(x) + ln(u) To make this linear, create two new variales, y = ln(y) and x = ln(x). (If you have more than one X variale, take the logs of all of them.) Let a e ln(a) and v e ln(u), and our equation ecomes nice and linear: y = a + x + v As with the growth model, to use least squares, we must assume that v ehaves like errors are supposed to ehave for linear regression. One of those assumptions is that v s expected value is 0. That is why we assume that the mean of u is 1. That fits ecause ln(1) = 0. u is never 0 or negative, ut v can take on positive or negative values, ecause if u is less than 1, v=ln(u) is less than 0. The multiple regression version of the constant elasticity model works like this: c Y = A X Z u is the equation. Take the log of oth sides to get: ln(y) = ln(a) + ln(x) + c ln(z) + ln(u) which you estimate as y = a + x + c z + v where y = Ln(Y), a = ln(a), x = ln(x), etc. This equation lets you look for diminishing or increases returns to scale. If +c < 1, you have diminishing returns. Douling X and Z makes Y go up less than twofold. If +c >1, you have increasing returns. Douling X and Z makes Y more than doule. Sometimes a linear model shows heteroskedasticity -- apparently unequal variances of the errors -- that takes the form of the residuals fanning out or in as you look down the residual plot. This constant elasticity form can correct that. Getting a prediction for Y from your prediction for y As with the growth-decay model, when you calculate a prediction for y, you have to convert it to Y. You y do this y raising e to the y power, ecause Y = e. In Excel, use the =EXP() function.

NON-LINEAR REGRESSION 8 An example Here are some data: Price Visits LnPrice LnVisits 10 512 2.30259 6.23832 10 396 2.30259 5.98141 10 456 2.30259 6.12249 10 525 2.30259 6.2634 20 347 2.99573 5.84932 20 377 2.99573 5.93225 20 423 2.99573 6.04737 20 330 2.99573 5.79909 30 366 3.4012 5.90263 30 335 3.4012 5.81413 30 301 3.4012 5.70711 30 309 3.4012 5.73334 40 345 3.68888 5.84354 40 320 3.68888 5.76832 40 325 3.68888 5.78383 40 285 3.68888 5.65249 The first two columns are the actual data. The third and fourth columns are calculated as the natural logs of the first two columns. 3.6888 approximately = LN(40), for example. LnVisits is the dependent variale, with a mean of 5.9024412 Variale Coefficient Std Error T-statistic P-Value Intercept 6.8044237 0.1496568 45.466851 0 LnPrice -0.2912347 0.047653-6.1115685 0.0000269 The estimated coefficient of LnPrice says that when the price is 1% higher, there are 0.29% fewer visits. To predict visits if the price is $25, first calculate =EXP(25). It is aout 3.218875825. Use that in the prediction form. Prediction, showing how it is calculated: Variale Coefficient * Your Value = Product Intercept 6.8044237 1.0 6.8044237 LnPrice -0.2912347 3.2188758-0.9374482 Total is the prediction: 5.8669755 90% conf. interval is 5.6865181 to 6.0474328 The prediction for the logarithm of visits is 5.8669755. The prediction for visits is =EXP(5.8669755), which is aout 353. The 90% confidence interval for that prediction is from =EXP(5.6865181) to =EXP(6.0474328), which is aout 295 to 423. Notice that 353 is not in the middle of this confidence

NON-LINEAR REGRESSION 9 interval. More comments on our two non-linear models Time series often use the ln(y) = ln(a) + + ln(u) form. The multiple regression version has more than one X variale. Your independent (X) variales measure time, either Sequentially: 0,1,2,3,... or 1996, 1997, 1998,... or Cyclically: seasonal dummy variales (to e explained next week) Notice that you do not take the logs of these X variales, just the Y variale. The coefficient is the growth/decline rate, meaning that a change in X of 1 corresponds with a 100 percent change in Y, if is small. Cross section studies, that look for causation rather than time trends, often use the constant elasticity form, ln(y) = ln(a) + ln(x) + ln(u) For this model, your independent variales have a proportional effect on your Y variale. You do take the logs of your X variales. Coefficients are elasticities, meaning that a change in X y 1% (of X) changes Y y percent. General comments on working with transformed equations You must assume that the error in the transformed equation has the desired properties (normal distriution with mean 0). Once you get your estimates from the transformed equation, going ack to the original equation can e tricky. Some original-equation parameter estimates are iased, ut consistent, if the parameter was transformed (e.g. A in the models aove). Confidence intervals around predicted values are no longer symmetrical. You must get the confidence interval from the transformed equation and then transform the ends ack. Before you start with using a non-linear regression equation: Have a good reason for not using a linear model, such as a theory of how the process that you're oserving works, or a pattern you see on a graph or in the residuals from a linear regression Determine which non-linear equation is est for your data. Can you make a sensile analogy with steady growth or decay? How aout with demand or production? To do the regression: Use algera (or just read the aove) to transform your original non-linear equation into one that is linear. For example, Y = AX u transforms to ln(y) = ln(a) + ln(x) + ln(u).

NON-LINEAR REGRESSION 10 Create the variales you need from your data. Use least squares, including the transformed variales in your data set. Your predictions, and at least some of your estimated coefficients, will have to e transformed to anti-logs to get ack to the parameters in the original non-linear equation. In oth of these equations, the predicted value of ln(y) must e transformed with the exp function to get a predicted value for Y.