nonlinear regression - eth z

36
Nonlinear Regression 28.11.2012

Upload: others

Post on 18-Oct-2021

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Nonlinear Regression - ETH Z

Nonlinear Regression

28.11.2012

Page 2: Nonlinear Regression - ETH Z

Goals of Today’s Lecture

I Understand the difference between linear and nonlinearregression models.

I See that not all functions are linearizable.

I Get an understanding of the fitting algorithm in a statisticalsense (i.e. fitting many linear regressions).

I Know that tests etc. are based on approximations and be ableto interpret computer output, profile t-plots and profile traces.

1 / 35

Page 3: Nonlinear Regression - ETH Z

Nonlinear Regression Model

The nonlinear regression model is

Yi = h(x(1)i , x

(2)i , . . . , x

(m)i ; θ1, θ2, . . . , θp) + Ei

= h(x i ; θ) + Ei .

where

I Ei are the error terms, Ei ∼ N (0, σ2) independent

I x (1), . . . , x (m) are the predictors

I θ1, . . . , θp are the parameters

I h is the regression function, “any” function.h is a function of the predictors and the parameters.

2 / 35

Page 4: Nonlinear Regression - ETH Z

Comparison with linear regression model

I In contrast to the linear regression model we now have ageneral function h.

In the linear regression model we had

h(x i ; θ) = xTi θ

(there we denoted the parameters by β).

I Note that in linear regression we required that theparameters appear in linear form.

I In nonlinear regression, we don’t have that restrictionanymore.

3 / 35

Page 5: Nonlinear Regression - ETH Z

Example: Puromycin

I The speed of an enzymatic reaction depends on theconcentration of a substrate.

I The initial speed is the response variable (Y ). Theconcentration of the substrate is used as predictor (x).Observations are from different runs.

I Model with Michaelis-Menten function

h(x ; θ) =θ1x

θ2 + x.

I Here we have one predictor x (the concentration) and twoparameters: θ1 and θ2.

I Moreover, we observe two groups: One where we treat theenzyme with Puromycin and one without treatment (controlgroup).

4 / 35

Page 6: Nonlinear Regression - ETH Z

Illustration: Puromycin (two groups)

0.0 0.2 0.4 0.6 0.8 1.0

50

100

150

200

Concentration

Vel

ocity

Concentration

Vel

ocity

Left: Data (• treated enzyme; 4 untreated enzyme)

Right: Typical shape of the regression function.

5 / 35

Page 7: Nonlinear Regression - ETH Z

Example: Biochemical Oxygen Demand (BOD)

Model the biochemical oxygen demand (Y ) as a function of theincubation time (x)

h(x ; θ) = θ1

(1− e−θ2x

).

1 2 3 4 5 6 7

8

10

12

14

16

18

20

Days

Oxy

gen

Dem

and

Days

Oxy

gen

Dem

and

6 / 35

Page 8: Nonlinear Regression - ETH Z

Linearizable FunctionsSometimes (but not always), the function h is linearizable.

Example

I Let’s forget about the error term E for a moment. Assume wehave

y = h(x ; θ) = θ1 exp{θ2/x}⇐⇒

log(y) = log(θ1) + θ2 · (1/x)

I We can rewrite this as

y = θ1 + θ2 · x ,

where y = log(y), θ1 = log(θ1), θ2 = θ2 and x = 1/x .

I If we use this linear model, we assume additive errors Ei

Yi = θ1 + θ2xi + Ei .

7 / 35

Page 9: Nonlinear Regression - ETH Z

I This means that we have multiplicative errors on the originalscale

Yi = θ1 exp{θ2/xi} · exp{Ei}.

I This is not the same as using a nonlinear model on theoriginal scale (it would have additive errors!).

I Hence, transformations of Y modify the model withrespect to the error term.

I In the Puromycin example: Do not linearize because errorterm would fit worse (see next slide).

I Hence, for those cases where h is linearizable, it depends onthe data if it’s advisable to do so or to perform a nonlinearregression.

8 / 35

Page 10: Nonlinear Regression - ETH Z

Puromycin: Treated enzyme

0.0 0.2 0.4 0.6 0.8 1.0

5010

015

020

0

Concentration

Vel

ocity

9 / 35

Page 11: Nonlinear Regression - ETH Z

Parameter Estimation

Let’s know assume that we really want to fit a nonlinear model.

Again, we use least squares. Minimize

S(θ) :=n∑

i=1

(Yi − ηi (θ))2 ,

whereηi (θ) := h(x i ; θ)

is the fitted value for the ith observation (x i is fixed, we only varythe parameter vector θ).

10 / 35

Page 12: Nonlinear Regression - ETH Z

Geometrical Interpretation

First we recall the situation for linear regression.

I By applying least squares we are looking for the parametervector θ such that

‖Y − Xθ‖22 =n∑

i=1

(Yi − xTi θ

)2is minimized.

I Or in other words: We are looking for the point on the planespanned by the columns of X that is closest to Y ∈ Rn.

I This is nothing else than projecting Y on that specific plane.

11 / 35

Page 13: Nonlinear Regression - ETH Z

Linear Regression: Illustration of Projection

0 2 4 6 8 10

0 2

4 6

810

0 2

4 6

810

η1 | y1

η 2 |

y 2

η3 | y3

Y

[1,1,1]

x

0 2 4 6 8 10

0 2

4 6

810

0 2

4 6

810

η1 | y1

η 2 |

y 2

η3 | y3

Y

[1,1,1]

x

y

12 / 35

Page 14: Nonlinear Regression - ETH Z

Situation for nonlinear regression

I Conceptually, the same holds true for nonlinear regression.

I The difference is: All possible points now don’t lie on a plane,but on a curved surface, the so called response or modelsurface defined by

η(θ) ∈ Rn

when varying the parameter vector θ.

I This is a p-dimensional surface because we parameterize itwith p parameters.

13 / 35

Page 15: Nonlinear Regression - ETH Z

Nonlinear Regression: Projection on Curved Surface

5 6 7 8 9 10 11

1012

1416

1820

1819

2021

22

η1 | y1

η 2 |

y 2

η3 | y3

Y

θ1 = 20

θ1 = 21

θ1 = 22

0.3

0.4

0.5θ2 =

y

14 / 35

Page 16: Nonlinear Regression - ETH Z

Computation

I Unfortunately, we can not derive a closed form solution forthe parameter estimate θ.

I Iterative procedures are therefore needed.

I We use a Gauss-Newton approach.

I Starting from an initial value θ(0), the idea is toapproximate the model surface by a plane, to perform aprojection on that plane and to iterate many times.

I Remember η : Rp → Rn. Define n × p matrix

A(j)i (θ) =

∂ηi (θ)

∂θj.

This is the Jacobi-matrix containing all partial derivatives.

15 / 35

Page 17: Nonlinear Regression - ETH Z

Gauss-Newton Algorithm

More formally, the Gauss-Newton algorithm is as follows

I Start with initial value θ(0)

I For l = 1, 2, . . .

Calculate tangent plane of η(θ) in θ(l−1):

η(θ) ≈ η(θ(l−1)) + A(θ(l−1)) · (θ − θ(l−1))

Project Y on tangent plane θ(l)

Projection is a linear regression problem, see blackboard.

Next l

I Iterate until convergence

16 / 35

Page 18: Nonlinear Regression - ETH Z

Initial Values

How can we get initial values?

I Available knowledge

I Linearized version (see Puromycin)

I Interpretation of parameters (asymptotes, half-life, . . . ),“fitting by eye”.

I Combination of these ideas (e.g., conditional linearizablefunctions)

17 / 35

Page 19: Nonlinear Regression - ETH Z

Example: Puromycin (only treated enzyme)

0 10 20 30 40 50

0.005

0.010

0.015

0.020

1/Concentration

1/ve

loci

ty

0.0 0.2 0.4 0.6 0.8 1.0

50

100

150

200

ConcentrationV

eloc

ity

Dashed line: Solution of linearized problem.

Solid line: Solution of the nonlinear least squares problem.

18 / 35

Page 20: Nonlinear Regression - ETH Z

Approximate Tests and Confidence Intervals

I Algorithm “only” gives us θ.

I How accurate is this estimate in a statistical sense?

I In linear regression we knew the (exact) distribution of theestimated parameters (remember animation!).

I In nonlinear regression the situation is more complex in thesense that we only have approximate results.

I It can be shown that

θjapprox .∼ N (θj ,Vjj)

for some matrix V (Vjj is the jth diagonal element).

19 / 35

Page 21: Nonlinear Regression - ETH Z

I Tests and confidence intervals are then constructed as in thelinear regression situation, i.e.

θj − θj√Vjj

approx .∼ tn−p.

I The reason why we basically have the same result as in thelinear regression case is because the algorithm is based on(many) linear regression problems.

I Once converged, the solution is not only the solution to thenonlinear regression problem but also for the linear one of thelast iteration (otherwise we wouldn’t have converged).

In factV = σ2(AT A)−1.

20 / 35

Page 22: Nonlinear Regression - ETH Z

Example Puromycin (two groups)

Remember, we originally had two groups (treatment and control)

0.0 0.2 0.4 0.6 0.8 1.0

50

100

150

200

Concentration

Vel

ocity

ConcentrationV

eloc

ity

Question: Do the two groups need different regression parameters?

21 / 35

Page 23: Nonlinear Regression - ETH Z

I To answer this question we set up a model of the form

Yi =(θ1 + θ3zi )xiθ2 + θ4zi + xi

+ Ei ,

where z is the indicator variable for the treatment (zi = 1 iftreated, zi = 0 otherwise).

I E.g., if θ3 is nonzero we have a different asymptote for thetreatment group (θ1 + θ3 vs. only θ1 in the control group).

I Similarly for θ2, θ4.

Let’s fit this model to data.

22 / 35

Page 24: Nonlinear Regression - ETH Z

Computer Output

Formula: velocity ~ (T1 + T3 * (treated == T)) * conc/(T2 +

T4 * (treated == T) + conc)

Parameters:

Estimate Std.Error t value Pr(>|t|)

T1 160.280 6.896 23.242 2.04e-15

T2 0.048 0.008 5.761 1.50e-05

T3 52.404 9.551 5.487 2.71e-05

T4 0.016 0.011 1.436 0.167

I We only get a significant test result for θ3 ( differentasymptotes) and not θ4.

I A 95%-confidence interval for θ3 (=difference betweenasymptotes) is

52.404± qt190.9759.551 = [32.4, 72.4],

where qt190.975 ≈ 2.09.

23 / 35

Page 25: Nonlinear Regression - ETH Z

More Precise Tests and Confidence Intervals

I Tests etc. that we have seen so far are only “usable” if linearapproximation of the problem around the solution θ is good.

I We can use another approach that is better (but also morecomplicated).

I In linear regression we had a quick look at the F -test fortesting simultaneous null-hypotheses. This is also possiblehere.

I Say we have the null hypothesis H0 : θ = θ∗ (whole vector).

Fact: Under H0 it holds

T =

(n − p

p

)S(θ∗)− S(θ)

S(θ)

approx .∼ Fp,n−p.

24 / 35

Page 26: Nonlinear Regression - ETH Z

I We still have only an “approximate” result. But thisapproximation is (much) better (more accurate) than theone that is based on the linear approximation.

I This can now be used to construct confidence regions bysearching for all vectors θ∗ that are not rejected using thistest (as earlier).

I If we only have two parameters it’s easy to illustrate theseconfidence regions.

I Using linear regression it’s also possible to derive confidenceregions (for several parameters). We haven’t seen this indetail.

I This approach can also be used here (because we use a linearapproximation in the algorithm, see also later).

25 / 35

Page 27: Nonlinear Regression - ETH Z

Confidence Regions: Examples

Puromycin Biochem. Oxygen D.

190 200 210 220 230 240

0.04

0.05

0.06

0.07

0.08

0.09

0.10

θ1

θ2

0 10 20 30 40 50 60

0

2

4

6

8

10

θ1

θ2

I Dashed: Confidence Region (80% and 95%) based on linear approx.

I Solid: Approach with F -test from above (more accurate).

I “+” is parameter estimate.

26 / 35

Page 28: Nonlinear Regression - ETH Z

What if we only want to test a single component θk?

I Assume we want to test H0 : θk = θ∗k .

I Now fix θk = θ∗k and minimize S(θ) with respect to θj , j 6= k.

I Denote the minimum by Sk(θ∗k).

I Fact: Under H0 it holds that

Tk(θ∗k) = (n − p)Sk(θ∗k)− S(θ)

S(θ)

approx .∼ F1,n−p,

or similarly

Tk(θ∗k) = sign(θk − θ∗k)

√Sk(θ∗k)− S(θ)

σ

approx .∼ tn−p.

27 / 35

Page 29: Nonlinear Regression - ETH Z

I Our first approximation was based on the linear approximationand we got a test of the form

δk(θ∗k) =θk − θ∗ks.e.(θk)

approx .∼ tn−p,

where s.e.(θk) =√Vjj .

This is what we saw in the computer output.

I The new approach with Tk(θ∗k) answers the same question(i.e., we do a test for a single component).

I The approximation of the new approach is (typically) muchmore accurate.

I We can compare the different approaches using plots.

28 / 35

Page 30: Nonlinear Regression - ETH Z

Profile t-Plots and Profile Traces

The profile t-plot is defined as the plot of Tk(θ∗k) against δk(θ∗k)(for varying θ∗k).

I Remember: The two tests (Tk and δk test the same thing.

I If they behave similarly, we would expect the same answers,hence the plot should show a diagonal (intercept 0, slope 1).

I Strong deviations from the diagonal indicate that the linearapproximation at the solution is not suitable and that theproblem is very non-linear in a neighborhood of θk .

29 / 35

Page 31: Nonlinear Regression - ETH Z

Profile t-Plots: Examples

Puromycin Biochem. Oxygen D.

−3

−2

−1

0

1

2

3

190 200 210 220 230 240

δ(θ1)

T1(θ

1)

θ1

−2 0 2 4

0.99

0.80

0.0

0.80

0.99

Leve

l−4

−2

0

2

4

20 40 60 80 100

δ(θ1)

T1(θ

1)

θ1

0 10 20 30

0.99

0.80

0.0

0.80

0.99

Leve

l

30 / 35

Page 32: Nonlinear Regression - ETH Z

Profile Traces

I Select a pair of parameters: θj , θk ; j 6= k.

I Keep θk fixed, estimate remaining parameters: θj(θk).

I This means: When varying θk we can plot the estimated θj(and vice versa)

I Illustrate these two curves on a single plot.

I What can we learn from this?

I The angle between the two curves is a measure for thecorrelation between estimated parameters. The smaller theangle, the higher the correlation.

I In the linear case we would see straight lines. Deviations arean indication for nonlinearities.

I Correlated parameter estimates influence each other stronglyand make estimation difficult.

31 / 35

Page 33: Nonlinear Regression - ETH Z

Profile Traces: Examples

Puromycin Biochem. Oxygen D.

190 200 210 220 230 240

0.04

0.05

0.06

0.07

0.08

0.09

0.10

θ1

θ 2

15 20 25 30 35 40

0.5

1.0

1.5

2.0

θ1

θ 2

Grey lines indicate confidence regions (80% and 95%).

32 / 35

Page 34: Nonlinear Regression - ETH Z

Parameter Transformations

In order to improve the linear approximation (and thereforeimprove convergence behaviour) it can be useful to transform theparameters.

I Transformations of parameters do not change the model, but

I the quality of the linear approximation, influencingthe difficulty of computation andthe validity of approximate confidence regions.

I the interpretation of the parameters.

I Finding good transformations is hard.

I Results can be transformed back to original parameters. Then,transformation is just a technical step to solve the problem.

33 / 35

Page 35: Nonlinear Regression - ETH Z

I Use parameter transformations to avoid side constraints, e.g.

θj > 0 −→ Use θj = exp{φj}, φj ∈ R

θj ∈ (a, b) −→ Use θj = a +b − a

1 + exp{−φj}, φj ∈ R

34 / 35

Page 36: Nonlinear Regression - ETH Z

Summary

I Nonlinear regression models are widespread in chemistry.

I Computation needs iterative procedure.

I Simplest tests and confidence intervals are based on linearapproximations around solution θ.

I If linear approximation is not very accurate, problems canoccur. Graphical tools for checking linearities are profilet-plots and profile traces.

I Tests and confidence intervals based on F -test are moreaccurate.

I Parameter transformations can help reducing theseproblems.

35 / 35