Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf ·...

55
Least squares and Regression Techniques Goodness of fits (and tests) Non linear least square techniques Glover, D. M., W. J. Jenkins, S. C. Doney: Modeling Methods for Marine Science, Cambridge University Press, Chapter 3

Transcript of Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf ·...

Page 1: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Least squares andRegression Techniques

Goodness of fits (and tests)Non linear least square techniques

Glover, D. M., W. J. Jenkins, S. C. Doney: ModelingMethods for Marine Science, Cambridge UniversityPress, Chapter 3

Page 2: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression1. The Chi Squared χ2

How can we judge the goodness of a fit (outside from “eyeball”) ?

The “BEST” fit wants to reduce the “distance” between the collecteddata an the model.

If the distribution has a Gaussian nature, then the “chi-squared” χ2 provides a standard measure of this distance:

“estimation from our model” “real” (collected) data

sample index(ex: time index)

Uncertainty in the individualmeasurement y

i

Page 3: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression1. The Chi Squared χ2

σi could :

● be the size of your smallest graduation on your measuring stick● be related to some fundamental physical limitation of your

measurement technique● depend on some internal statistics associated with the measurement

(ex: you may take as your measurement the “actual time average”over some given time)

Page 4: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression2. The reduced Chi Squared χ2

The Root Mean Square (RMS) deviation normalized tomeasurement error should tend to one if things are working“correctly”. Here we define such a measure, as the reducedChi-Squared:

degrees of freedom

number ofcollected samples

number of parametersused by “your

regression fit” (your“model”)

Page 5: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression2. The reduced Chi Squared χ2

Example 1:

You have N measurements

You “best estimate” is the mean:

Your “model” has therefore ONE parameter: n=1

And you have N-1 degrees of freedom (or N-1 independent variables.Knowing the mean and N-1 variables, you can deduce the Nth one)

Page 6: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression2. The reduced Chi Squared χ2

Example 2:

You have N measurements

You “best estimate” is a linear fit (regression)

Your “model” has therefore TWO parameters: n=2

And you have N-2 degrees of freedom

Page 7: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression2. The reduced Chi Squared χ2

If you are “doing a bad job” at collecting your measurements, or if your“model” is inappropriate, then your reduced chi-squared will havelarge values (much larger than 1)

If you have been too pessimistic about your measurement errors, thanyour chi-squared value will be very small (<0.1)

Page 8: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

I. Basics Statistics used for Regression3. Look at the residuals

A good chi-squared” may not mean that you have a good fit (or “model”)

Always look at the “shape” of the residuals

Page 9: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Minimizing the chi-squared is thefoundation of all the least squares

regression techniques !

Page 10: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line Introduction

The most common data regression model (aside from the mean andstandard deviation) is the fit to a straight line.

We therefore define the following “mode”l:

This model is based on TWO parameters: a1 and a2

yi is the dependent variable

xi is the independent variable

Page 11: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line Introduction

We want to find the “BEST” estimates for the two parameters a1 and a2

TYPE I regression techniques: no uncertainty on the dependent variable x: σ

x~ 0

The “BEST” estimates for the two parameters are the ones thatminimize the chi-squared, i.e the VERTICAL distance betweenthe estimated y values and the measured y values

Page 12: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line Introduction

Page 13: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 1. The normal equations

Page 14: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 1. The normal equations

“normal”equations

Page 15: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Cramers'rule:

Page 16: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 17: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 2. Uncertainties in the coefficients

Error onmeasurements

Page 18: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 2. Uncertainties in the coefficients

If there is no systematic error (uncorrelated noise)between TWO distinct measurements (taken at adifferent time or at a different location, i≠j), then: - the cross-terms cancel

sample meanof the error

square(”dispersion”)

Page 19: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 2. Uncertainties in the coefficients

Back to the Type I regression fitting to a straight line:

The amplitude of the error does NOT depend on the collected data (the yivalues)

The amplitude of the error depends: - on where (or at which time) you made the measurements (the xi values) - the uncertainties in the measurements (the σi values)

Maximizing Δ (the determinant of A) is a good thing !

Page 20: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 2. Uncertainties in the coefficients

Maximizing Δ is equivalent to maximizing the spreading of themeasurements in time or space (increasing the range of the x-values):the larger you spread the data, the lower the uncertainty on theintercept and the slope. We want to spread the cloud of data around thecentroid.

Increasing the number of measurements ?It makes Sxx (which is always positive) grow.Therefore the determinant Δ also grows

Page 21: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 2. Uncertainties in the coefficients

Largely spread data improves the uncertainty on the slope

Page 22: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 2. Uncertainties in the coefficients

Poorly spread data far away for the x=0 axis leads to largeuncertainty on the interceptor

Page 23: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 3. Uncertainties in the estimated y-values

Page 24: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 4. Type 2 regression

for (2 independent variables)

We have assumed so far that we know x infinitely well

What about if we also have uncertainties on both the yi values and thexi values ?

Should we perform a fit of y against x or x against y ? If you performboth on scattered data, you will get significant difference in thepredicted slopes

Minimizing the vertical distances between the y-data and the fit is nowINCORRECT

You should consider the “TRUE” distance, and minimize theperpendicular distance

Page 25: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 4. Type 2 regression

for (2 independent variables)

For a straight line, it becomes:

Page 26: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

III. General Least squares techniques

You can derive the normal equations for any set of basis functions. Basisfunctions can be thought as building blocks for describing your data.

The more complicated the functions, the more difficult it is to write the normalequations, and the more the risk that the solution to the normal equationsbecomes numerically ill-behaved.

Example: polynomial sharpness

Page 27: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

III. General Least squares techniquesThe design matrix approach

Example:

Linear in the parameter spaceCan be fit with linear least squares

Problem: A is not a square matrixWhere are the weighted factors, the σi ?

Page 28: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Where are the weighted factors, the σi ?

Page 29: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

III. General Least squares techniquesSolving design matrix approach with

SVD

The problem turns out in minimizing the square of the residuals:

This is exactly what singular decomposition does !

Page 30: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

II. Least squares fitting a straight line 3. Uncertainties in the estimated y-values

Page 31: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Singular Value decomposition (SVD)

For any matrix A (N rows x M columns), there exists a triple product of

U: column orthonormal matrix (i.e any column vector is orthogonal to theothers and the sum of the squares of elements is ONE)of size NxM

V: orthonormal square of size M*M matrix

S: diagonal matrix of size M x M. The diagonal elements are called thesingular values. These values may be zeros if the matrix is rank deficient(i.e the rank is less than the shortest dimension of the matrix A)

Page 32: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

W is a diagonal matrix defined from diagonal matrix S

with εw a small threshold value

Page 33: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

W is a diagonal matrix defined from diagonal matrix S

with εw a small threshold value

Page 34: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

How do you compute the uncertainties ?

Page 35: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Covariance Matrix ofuncertainties

Page 36: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 37: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

USEFUL MATRIX ALGEBRA:

Identity 1:

Identity 2:

Demo:

k=1,...,N

Page 38: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Looking for an extremum, and anticipating that thisextremum is a minimum...

To have a solution, this matrix must be invertibleIf not, then SVD methods

Generalization of the linear regression

Residuals Sum of Squares (RSS):

Page 39: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 40: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

2 methods:ATA is invertible ATA is not invertible

Covariance matrix of

Page 41: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Covariance matrix of

Page 42: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Estimatimator of σε

Page 43: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques

Student Distributionwithy n=N-K degrees offreedom

Page 44: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 45: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 46: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 47: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 48: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 49: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 50: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 51: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 52: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 53: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 54: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques
Page 55: Least squares and Regression Techniquesstockage.univ-brest.fr/~herbette/...least-squares.pdf · Regression Techniques Goodness of fits (and tests) Non linear least square techniques