Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fitting Non-Linear Regression ModelsV&R 8.2 Oy Mae Louie Bessie Nguyen Gina Piscitelli.

Similar presentations


Presentation on theme: "Fitting Non-Linear Regression ModelsV&R 8.2 Oy Mae Louie Bessie Nguyen Gina Piscitelli."— Presentation transcript:

1 Fitting Non-Linear Regression ModelsV&R 8.2 Oy Mae Louie Bessie Nguyen Gina Piscitelli

2 When do we use a non-linear regression model? When at least one of the parameters is not linear The general form of a non-linear regression model is y=η(x,β) + ε where ε ~N(0, σ 2 )

3 Plot of Weight Loss vs Days for an Obese Patient oldpar<-par(mar=c(5.1,4.1,4.1,4.1)) plot(Days,Weight,type="p",ylab="Weight(kg)") Wt.lbs<-pretty(range(Weight*2.2025)) axis(side=4,at=Wt.lbs/2.205,lab=Wt.lbs,srt=90) mtext("Weight(lb)",side=4,line=3)

4 Weight Loss Dataset Model: y = β o + β 1 *2 -t/θ + ε The parameters: β o : ultimate lean weight β 1 : total amount of weight to be lost θ: time taken to lose half the amount of weight remaining to be lost

5 Method Used to Analyze Data Iterative procedure The number of iterations depend on how quickly the parameters converge. The converged parameters are close approximates for βo,β1, and θ. The likelihood for the non-linear regression model is maximized when residual sum of squares is minimized.

6 Non-Linear Regression Methods 1."Direct Computation" Method: y = β o + β 1 *2 -t/θ 2. "Derivative" Method: η(β) ≈ ω (0) + Z (0) β 3. Self-Starting Method: y = β o + β 1 exp(-x/θ) + ε

7 1. Direct Computation Method The direct computation method initializes values for b0, b1, and theta by inspection of the weight loss data set. R Code wtloss.st <-c(b0 = 90, b1 = 95, th =120) wtloss.fm <- nls(Weight ~ b0 + b1*2^(-Days/th), data = wtloss, start = wtloss.st, trace = T) wtloss.fm lines(Days,fitted.values(wtloss.fm))

8 2. Derivative Method The equation η(β) ≈ ω (0) + Z (0) β defines (in vector terms) the tangent plane to the surface at the coordinate point β = β (0) where η(β) is the mean vector ω (0) is the offset vector Z (0) is the matrix which defines the tangent plane Each iteration gives a new approximation for β until convergence is reached. The derivative method uses numerical methods to compute a formula for the gradient unless first derivatives are supplied.

9 2. Derivative Method (continued) The symbolic differentiation function deriv can be used to automatically generate the desired function. R code expn1<-deriv (y ~ b0 + b1 * 2 ^ (-x/th),c('b0','b1','th'), function(b0,b1,th,x){}) wtloss.gr <-nls(Weight ~expn(b0, b1, th, Days), data = wtloss, start = wtloss.st, trace = T) lines(Days,fitted.values(wtloss.gr))

10 3. Self-Starting Method The self starting method fits a non-linear model without explicit initial values. Procedure a)Fit Quadratic Regression b)Find fitted values y0, y1, and y2 and three equally spaced points x 0, x 1 = x 0 + δ and x 2 = x 0 + 2δ c)Find initial value of θ using the following formula: θo = δ / log ((y 0 – y 1 )/(y 1 -y 2 )) d) Find initial values for β 0 and β 1 by obtaining linear regression of y on exp(-x/ θo)

11 3. Self-Starting Method (continued) R code negexp<-selfStart(model = ~b0 + b1*exp(-x/th), initial = negexp.SSival,parameters=c("b0","b1","th"), template=function(x,b0,b1,th){}) wtloss.ss<-nls(Weight~negexp(Days,B0,B1,theta), data=wtloss,trace=T) lines(Days,fitted.values(wtloss.ss))

12 Results Direct Computation Method SSR B0B1theta : : : : Derivative Method SSR B0B1theta : : : : Self Starting Method SSRB0 B1 theta : : : B0 and B1: For all three methods, the approximated values for B0 and B1 are about the same. Theta: For both the direct computation and derivative method, the approximated values for theta are about the same. However, for the self starting method, the theta is different. For the Weight Loss data, three iterations are necessary for the values of B0, B1 and theta to converge.

13 Results Model: Weight ~ β 0 + β 1 * 2 -Days/θ β 0 = β 1 = θ = residual sum-of-squares: Model: y = * 2 -Days/141.91

14 Fitted Curve Plot

15 Summary Use a non-linear regression model when at least one of the parameters is not linear. Non-linear regression is an iterative procedure in which the number of iterations depend on how quickly the parameters converge. Three methods introduced:  Direct Computation Method  Derivative Method  Self-Starting Method


Download ppt "Fitting Non-Linear Regression ModelsV&R 8.2 Oy Mae Louie Bessie Nguyen Gina Piscitelli."

Similar presentations


Ads by Google