dynamic linear models - nwfsc time-series analysis · model diagnostics · · · · · 2/73. simple...

73
Dynamic Linear Models FISH 507 – Applied Time Series Analysis Mark Scheuerell 5 Feb 2019

Upload: others

Post on 07-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Dynamic Linear Models

FISH 507 – Applied Time Series Analysis

Mark Scheuerell

5 Feb 2019

Page 2: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Topics for today

Univariate response

Multivariate response

Stochastic level & growth

Dynamic Regression

Dynamic Regression with fixed season

Forecasting with a DLM

Model diagnostics

·

·

·

·

·

2/73

Page 3: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Simple linear regression

Let's begin with a linear regression model

The index has no explicit meaning in that shuffling ( ) pairs has noeffect on parameter estimation

3/73

Page 4: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Simple linear regression

We can write the model in matrix form

4/73

Page 5: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Simple linear regression

We can write the model in matrix form

with

and

5/73

Page 6: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Dynamic linear model (DLM)

In a dynamic linear model, the regression parameters change overtime, so we write

as

6/73

Page 7: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Dynamic linear model (DLM)

There are 2 important points here:

1. Subscript explicitly acknowledges implicit info in the time orderingof the data in

7/73

Page 8: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Dynamic linear model (DLM)

There are 2 important points here:

1. Subscript explicitly acknowledges implicit info in the time orderingof the data in

2. The relationship between and is unique for every

8/73

Page 9: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Constraining a DLM

Close examination of the DLM reveals an apparent problem forparameter estimation

9/73

Page 10: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Constraining a DLM

Close examination of the DLM reveals an apparent problem forparameter estimation

We only have 1 data point per time step (ie, is a scalar)

Thus, we can only estimate 1 parameter (with no uncertainty)!

10/73

Page 11: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Constraining a DLM

To address this issue, we'll constrain the regression parameters to bedependent from to

11/73

Page 12: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Constraining a DLM

In practice, we often make time invariant

or assume is an identity matrix

In the latter case, the parameters follow a random walk over time

12/73

Page 13: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

DLM in state-space form

Observation model relates covariates to data

State model determines how parameters "evolve" over time

13/73

Page 14: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

DLM in MARSS notation

Full state-space form

14/73

Page 15: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Contrast in covariate effects

Note: DLMs include covariate effect in the observation eqn muchdifferently than other forms of MARSS models

DLM: is covariates, is parameters

Others: is covariates, is parameters

15/73

Page 16: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Other forms of DLMs

The regression model is but one type

Others include:

stochastic "level" (intercept)

stochastic "growth" (trend, bias)

seasonal effects (fixed, harmonic)

·

·

·

16/73

Page 17: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

The most simple DLM

Stochastic level

17/73

Page 18: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

The most simple DLM

Stochastic level = random walk with obs error

18/73

Page 19: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Ex of stochastic level model

19/73

Page 20: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Ex of stochastic level model

20/73

Page 21: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for level & growth

Stochastic "level" with deterministic "growth"

21/73

Page 22: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for level & growth

Stochastic "level" with deterministic "growth"

This is just a random walk with bias

22/73

Page 23: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for level & growth

Stochastic "level" with stochastic "growth"

Now the "growth" term evolves as well

23/73

Page 24: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for level & growth

Evolution of and

24/73

Page 25: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for level & growth

Evolution of and

25/73

Page 26: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for level & growth

Observation model for stochastic "level" & stochastic "growth"

26/73

Page 27: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for regression

Stochastic intercept and slope

27/73

Page 28: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM for regression

Parameter evolution follows a random walk

28/73

Page 29: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

Dynamic linear regression with fixed seasonal effect

29/73

Page 30: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

30/73

Page 31: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

How should we model the fixed effect of ?

31/73

Page 32: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

We don't want the effect of quarter to evolve

32/73

Page 33: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

OK, but how do we select the right quarterly effect?

33/73

Page 34: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

Let's separate out the quarterly effects

But how do we select only the current quarter?

34/73

Page 35: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

We can set some values in to 0 ( = 1)

35/73

Page 36: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

We can set some values in to 0 ( = 2)

36/73

Page 37: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

But how would we set the correct 0/1 values?

37/73

Page 38: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

We could instead reorder the within ( = 1)

38/73

Page 39: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

We could instead reorder the within ( = 2)

39/73

Page 40: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Univariate DLM with seasonal effect

But how would we shift the within ?

40/73

Page 41: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Example of non-diagonal

We can use a non-diagonal to get the correct quarter effect

41/73

Page 42: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Evolving parameters

42/73

Page 43: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Evolving parameters

43/73

Page 44: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

DLMs are often used in a forecasting context where we want aprediction for time based on the data up through time

44/73

Page 45: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

Pseudo-code

1. get estimate of today's parameters from yesterday's

2. make prediction based on today's parameters & covariates

3. get observation for today

4. update parameters and repeat

45/73

Page 46: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

1. Define the parameters at time

46/73

Page 47: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

1. Define the parameters at time

47/73

Page 48: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

1. Define the parameters at time

48/73

Page 49: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

1. Define the parameters at time

49/73

Page 50: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

1. Make a forecast of at time

50/73

Page 51: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

Putting it all together

51/73

Page 52: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Forecasting with a DLM

Putting it all together

Using MARSS() will make this easy to do

52/73

Page 53: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Diagnostics for DLMs

Just as with other models, we'd like to know if our fitted DLM meets itsunderlying assumptions

We can calcuate the forecast error as

and check if

with a QQ-plot (1) and an ACF (2)

53/73

Page 54: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

MULTIVARIATE DLMs

54/73

Page 55: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

The most simple multivariate DLM

Multiple observations of a stochastic level

with

55/73

Page 56: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Another simple multivariate DLM

Multiple observations of multiple levels

with

56/73

Page 57: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Regression model

Our univariate model

becomes

57/73

Page 58: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Kronecker products

If is an matrix and is a matrix

then will be an matrix

58/73

Page 59: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Kronecker products

For example

so

59/73

Page 60: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Regression model with

60/73

Page 61: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

61/73

Page 62: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Covariance of observation errors

62/73

Page 63: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Parameter evolution

becomes

63/73

Page 64: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Parameter evolution

If we have 2 regression parameters and , then

64/73

Page 65: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Parameter evolution

65/73

Page 66: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

66/73

Page 67: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Parameter evolution

67/73

Page 68: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Evolution variance

What form should we choose for ?

68/73

Page 69: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Evolution variance

Diagonal and equal (IID)

69/73

Page 70: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Evolution variance

Diagonal and unequal

70/73

Page 71: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Evolution variance

Unconstrained

71/73

Page 72: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Multivariate DLMs

Evolution variance

In practice, keep as simple as possible

72/73

Page 73: Dynamic Linear Models - NWFSC Time-Series Analysis · Model diagnostics · · · · · 2/73. Simple linear regression ... We only have 1 data point per time step (ie, is a scalar)

Topics for today

Univariate response

Multivariate response

Stochastic level & growth

Dynamic Regression

Dynamic Regression with fixed season

Forecasting with a DLM

Model diagnostics

·

·

·

·

·

73/73