model fitting part 1perfeval.epfl.ch/printme/modfit.pdf4. bootstrap : computation of confidence...

52
Model Fitting Part 1 JeanYves Le Boudec March 2019

Upload: others

Post on 04-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Model FittingPart 1

Jean‐Yves Le Boudec

1March 2019

Page 2: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Contents

1. What is model fitting ?2. Least Squares

3. norm minimization4. The bootstrap

2

Page 3: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Virus Infection Data

We would like to capture the growth of infected hosts(explanatory model)

An exponential model seems appropriate

How can we fit the model, in particular, what is the value of  ?

3

Page 4: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Least Square Fit of Virus Infection Data

4

Least square fit

= 0.5173

Mean doubling time 1.34 hours

Prediction at +6 hours: 100 000 hosts

Page 5: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Least Square Fit of Virus Infection Data In Log Scale

5

Least square fit

= 0.39

Mean doubling time 1.77 hours

Prediction at +6 hours: 39 000 hosts

Page 6: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Compare the Two

6

LS fit in natural scale

LS fit in log scale

Page 7: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Which scale should I use ?

A. The natural scale because it is the simplest (principle ofparsimony)

B. The log scale because it is betteradapted to exponential growth

C. I don’t know

7

Page 8: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

What is model fitting ?

Given some data  and a parametric model  we assume that :

The model fitting problem is to estimate the unknown parameter 

For example:  the model is or

These two models are equivalent; the parameter is 

9

Page 9: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

The signal processing interpretation

Given a model  and a score function, find  that minimizes the score

Classical scoresLeast Square: Weighted Least Square: 

score: Weighted  score: 

Which one should we use ?

10

Page 10: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

The statistical interpretation

The data  is output by a simulator, with parameter  , which we want to estimate

This forces us to make some assumption about the noise term; for example, we could consider any one of the following models

For each of these models, the parameter is now 

11

Page 11: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Estimating a statistical model: maximum likelihoodPrinciple: find  that maximizes the pdf   , also called likelihood, where  is the dataThis is a robust and consistent estimation method

Example: model 1 :    ∑

the problem is to find  that maximizes   (1)

12

Page 12: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Least Square Score = Gaussian iid Noise

Assume model (homoscedasticity)

i.e. the signal processing method with Least Squares score is the same as the statistical method with iid gaussian noise

13

Page 13: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Example: model 1 :    ∑

the problem is to find  that maximizes   (1)

Thm 3.3.1

,

14

Page 14: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

The residuals can help validate a fitting methodResiduals  = estimate of noise terms (after estimation of parameter) –they should be consistent with the model

Model 1 appears not to fit, residuals have a variance that grows with , model 3 appears OK; we should prefer it for fitting this data set

15

Model1:, ∼ 0,

Model3:log log , ∼ 0,

Page 15: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

LS score functions

Given a model to be fitted 

we have the equivalences:

i.e. WLS gives a weight inversely proportional to  of noise

16

Score Statistical modelLeastSquare:

score ∑ noisenoise ∼ iid 0,

WeightedLeastSquare:score ∑ noise noise ∼ iid 0,

Page 16: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Which score corresponds to which model ?

A. A1 B2 C3B. A1 B3 C2C. A2 B1 C3D. A2 B3 C1E. A3 B1 C2F. A3 B2 C1G. I don’t know

17

: :

: log log

Page 17: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Compare models 2 and 3Assume model 2 and take log:

So we expect models 2 and 3 to be approximately equivalent.

19

Page 18: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Take‐Home Message

In order to fit a model you need to find an appropriate score function.

One easy way to determine one is to consider an explicit model of the noise, and verify it by looking at residuals

A common mistake is to assume that noise has same variance when it is obviously wrong (e.g. model 1) 

Furthermore, we may be interested in finding confidence intervals for the estimated parameters.

20

Page 19: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

2. Least Squares 

Very commonly usedEfficient solution, lots of softwaresAnd gives confidence intervals

21

Page 20: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Confidence Intervals

22

Page 21: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Example:  model 3

with  ; let

, , , ,

23

Page 22: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Example:  model 3

 

24

Matlabcalls thevariance‐covariancematrix

Page 23: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

An approximate 95% confidence interval for  is(with  )

D. None of the aboveE. I don’t know

25

Page 24: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Linear RegressionModel 3 is a special case of linear regressionBy definition, a linear regression model (with least squares) means a model of the form

where  is linear with respect to 

For such models, there are closed form solutions in matrix form for the maximum likelihood estimation solution, including exact confidence intervals – see thm 3.3

27

Page 25: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

28

Page 26: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Example: Joe’s shop

29

1 1 , ∼ iid 0,with

Page 27: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Is this a linear regression model ?

A. YesB. Yes if we assume  is knownC. No, even if  is not knownD. I don’t know

30

1 1 , ∼ iid 0,with

Page 28: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Validate the Assumptions with Residuals

33

Page 29: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Non‐linear case: use the likelihood function

34

Page 30: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

35

Page 31: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

3.  ‐ Norm MinimizationLaplace NoiseRecall that the pdf of the  distribution is and its CDF is 

Consider the following sampling method:Draw With probability 0.5, let with probability 0.5 let 

The output  is called Laplace Noise

What is its pdf ?

36

Page 32: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

The PDF of Laplace noise is …

| |

| |

| | | |

E. I don’t know

37

Page 33: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

‐Norm Minimization = Laplace Noise

Assume model (homoscedasticity)

i.e. the signal processing method with  score is the same as the statistical method with iid Laplace noise.

41

Page 34: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

LS and  score functions

Given a model to be fitted 

we have the equivalences:

42

Score Statistical modelLeastSquare:

score ∑ noisenoise ∼ iid 0,

WeightedLeastSquare:score ∑ noise noise ∼ iid 0,

ℓ score ∑ |noise | noise ∼ iidLaplaceℓ score ∑ |noise | noise ∼ iidLaplace

Page 35: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

LS versus  ‐ norm minimization

Virus propagation example: both fits give the same result in log‐scale

43

Page 36: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

‐ norm minimization is more robust to « Outliers »

44

LS

Page 37: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

To understand the difference between LS and consider the simple example i.e. fit a cloud of data to a single value

Least SquareModel: 

What is m ?

Confidence interval ?

L1 NormMinimizationModel: 

What is m ?

Confidence interval ?

45

Page 38: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

What is the LS fit of  in 

median of 

where 

where 

E. I don’t know

46

Page 39: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

What is the  fit of  in 

median of 

where 

where 

E. I don’t know

48

Page 40: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Linear Regression with  norm minimization

=  norm minimization + linear dependency on parameterMore robust than LS linear regressionLess traditional

51

Page 41: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

This is convex programming

52

Page 42: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

53

Page 43: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Confidence Intervals

No closed form

We can use an approximate solution based on simulation (“Bootstrap”)

54

Page 44: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

4. Bootstrap : Computation of Confidence Interval

We have a parametric model with parameters  and want to find a confidence interval  for, say, ; let  be our estimator of 

Recall that  is a function of the data (hence is random); we want to have  , for any 

Assume someone tells us the true value of  ; in theory, we can compute  the quantiles of the distribution of  ; let 

, quantile of  and  , quantile of We have

, , ,

We have computed an estimator  ; we take as approximate confidence interval  , and  ,

55

Page 45: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Parametric Bootstrap Computation of CI (cont’d)Let  , quantile of  and  , quantile of 

We take as approximate confidence interval  , and  ,

How can we practically compute  , ,  , ?By Monte‐Carlo simulation:Assume you know 

Do simulate  from the model obtain an estimate 

end, ,

e.g. with , and  ,

Do the above with  ) – this is called Parametric Bootstrap

56

Page 46: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Example

We have obtainedFor   we draw  residuals 

and simulate  artificial data points  from the fitted modelFor each replay experiment we estimate  and obtain  

estimatesA confidence interval for  is 

57

a 1.49 0.601

b 0.079 0.0143

c 11.2 2.96

d 0.062 0.0368

Page 47: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Bootstrap with Resample From Residuals

Instead of simulating the noise from the model (by drawing from Laplace( ) assume we draw  noise samples from the residuals with replacementThis method is called Bootstrap with Resampling from Residuals

58

Page 48: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

59

Page 49: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

60

a 1.49 0.601

b 0.079 0.0143

c 11.2 2.96

d 0.062 0.0368

69

CIwithParametricBootstrap,999replays

CIwithBootstrap,ResamplingfromResiduals,999replays

Page 50: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Other Uses of the Bootstrap

The idea of the bootstrap is to use the data itself as estimate of the unknown distribution of the data

Can be used to obtain confidence or predictions intervals in a very simple way ‐‐‐ tends to underestimate

Example: CI for the mean of a data set 

the model is  and the problem is to estimate the mean of 

with the bootstrap we replace the unknown  by the empirical distribution of the data itself, i.e. the distribution that puts probability  at every 

61

Page 51: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Which algorithm is a correct implementation of the bootstrap for a 95% CI of the mean of  ?

A. AB. BC. BothD. NoneE. I don’t know

62

Algorithm Afor  1: 999for  1:draw one integer

∼ unif 1, … , ,

endendfor  1: 999

mean , , … , ,endCI = ,

Algorithm Bfor  1: 999draw a random permutation

of  1,… , , , 1…

endendfor  1: 999

mean , , … , ,endCI = ,

Page 52: Model Fitting Part 1perfeval.epfl.ch/printMe/modfit.pdf4. Bootstrap : Computation of Confidence Interval We have a parametric model with parameters and want to find a confidence interval

Example: Compiler Options, CI for mean

64

Assumingdataisnormal(Thm2.3)

Assuming islargeandvarianceisfinite(Thm 2.2)

Bootstrap