73
Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019

Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor AnalysisFISH 507 – Applied Time Series Analysis

Mark Scheuerell

31 Jan 2019

Page 2: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Topics for today

Deterministic vs stochastic elements

Regression with autocorrelated errors

Regression with temporal random effects

Dynamic Factor Analysis (DFA)

Forms of covariance matrix

Constraints for model fitting

Interpretation of results

·

·

·

2/73

Page 3: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A very simple model

Consider this simple model, consisting of a mean plus error

3/73

Page 4: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A very simple model

The right-hand side of the equation is composed of deterministic andstochastic pieces

4/73

Page 5: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A very simple model

Sometime these pieces are referred to as fixed and random

5/73

Page 6: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A very simple model

This can also be seen by rewriting the model

as

6/73

Page 7: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Simple linear regression

We can expand the deterministic part of the model, as with linearregression

so

7/73

Page 8: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A simple time series model

Consider a simple model with a mean plus white noise

8/73

Page 9: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Time series model with covariates

We can expand the deterministic part of the model, as before withlinear regression

so

9/73

Page 10: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Example of linear model

10/73

Page 11: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Model residuals

These do not look like white noise!

11/73

Page 12: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

ACF of model residuals

There is significant autocorrelation at lag = 1

12/73

Page 13: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Model with autocorrelated errors

We can expand the stochastic part of the model to have autocorrelatederrors

with

13/73

Page 14: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Model with autocorrelated errors

We can expand the stochastic part of the model to have autocorrelatederrors

with

We can write this model as our standard state-space model

14/73

Page 15: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelObservation equation

with

, , , ,

15/73

Page 16: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelState equation

with

and

16/73

Page 17: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelFull form

17/73

Page 18: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelObservation model in MARSS()

y = data ## [1 x T] matrix of data a = matrix("a") ## intercept D = matrix("D") ## slope d = covariate ## [1 x T] matrix of measured covariate Z = matrix(1) ## no multiplier on x R = matrix(0) ## v_t ~ N(0,R); want y_t = 0 for all t

18/73

Page 19: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelState model in MARSS()

B = matrix("b") ## AR(1) coefficient for model errors Q = matrix("q") ## w_t ~ N(0,Q); var for model errors u = matrix(0) ## u = 0 C = matrix(0) ## C = 0 c = matrix(0) ## c_t = 0 for all t

19/73

Page 20: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

MORE RANDOM EFFECTS

20/73

Page 21: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Expanding the random effect

Recall our simple model

21/73

Page 22: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Expanding the random effect

We can expand the random portion

22/73

Page 23: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Expanding the random effect

We can expand the random portion

This is simply a random walk observed with error

23/73

Page 24: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Random walk observed with error

24/73

Page 25: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Expanding fixed & random effects

We can expand the fixed portion

25/73

Page 26: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Fixed & random effectsIn familiar state-space form

26/73

Page 27: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

MULTIPLE TIME SERIES

27/73

Page 28: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Simple model for 2+ time seriesRandom walk observed with error

with

28/73

Page 29: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Random walk observed with error

29/73

Page 30: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Random walk observed with errorIn matrix form

with

30/73

Page 31: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

31/73

Page 32: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Environmental time series

We often observe covariance among environmental time series,especially for those close to one another

32/73

Page 33: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Are there some common patterns here?

33/73

Page 34: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Common patterns in time series

34/73

Page 35: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelEx: population structure

35/73

Page 36: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

State-space modelEx: Harbor seal population structure

36/73

Page 37: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Finding common patterns

What if our observations were instead a mixture of 2+ states?

For example, we sampled haul-outs located between several breedingsites

37/73

Page 38: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Mixtures of states

38/73

Page 39: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Finding common patterns

What if our observations were a mixture of states, but we didn't knowhow many or the weightings?

What are the dimensions of ?

What are the elements within ?

39/73

Page 40: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)

DFA is a dimension reduction technique, which models observed timeseries as a function of hidden states (patterns), where

40/73

Page 41: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)State-space form

data: is

loadings: is with

states: is

41/73

Page 42: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dimension reductionPrincipal Components Analysis (PCA)

Goal is to reduce some large number of correlated variates into a fewuncorrelated factors

42/73

Page 43: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Principal Components Analysis (PCA)

Calculating the principal components requires us to estimate thecovariance of the data

There will be principal components (eigenvectors) for an matrix

We reduce the dimension by selecting a subset of the components thatexplain much of the variance (eg, the first 2)

43/73

Page 44: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Principal Components Analysis (PCA)

44/73

Page 45: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Principal Components Analysis (PCA)

45/73

Page 46: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Principal Components Analysis (PCA)

46/73

Page 47: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Relationship between PCA & DFA

We need to estimate the covariance in the data

so

In PCA, we require to be diagonal, but not so in DFA

47/73

Page 48: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Principal Components Analysis (PCA)Forms for with

48/73

Page 49: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)Forms for with

49/73

Page 50: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)

What form should we use for ?

50/73

Page 51: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)

What form should we use for ?

We'll use model selection criteria to choose (eg, AICc)

51/73

Page 52: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Fitting DFA models

It turns out that there are an infinite number of combinations of and that will equal

Therefore we need to impose some constraints on the model

52/73

Page 53: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe offset

We will set the first elements of to 0

53/73

Page 54: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe offset

For example, if and

54/73

Page 55: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe offset

For example, if and

Note, however, that this causes problems for the EM algorithm so wewill often de-mean the data and set for all

55/73

Page 56: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe loadings

We will set the upper right triangle of to 0

56/73

Page 57: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe loadings

For example, if and

For the first rows of , if

57/73

Page 58: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe loadings

An additional constraint is necessary in a Bayesian context

Diagonal of is positive: if

58/73

Page 59: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe state variance

We will set equal to the Identity matrix

59/73

Page 60: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Constraints on DFA modelsThe state variance

For example, if

This allows our random walks to have a lot of flexibility

60/73

Page 61: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)Including covariates

is a vector of covariates at time

is an matrix of covariate effects

61/73

Page 62: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)Form for

Careful thought must be given a priori as to the form for

Should the effect(s) vary by site, species, etc?

62/73

Page 63: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Dynamic Factor Analysis (DFA)Form for

For example, given 2 covariates, and

63/73

Page 64: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A note on model selection

Earlier we saw that we could use model selection criteria to help uschoose among the different forms for

However, caution must be given when comparing models with andwithout covariates, and varying numbers of states

64/73

Page 65: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A note on model selection

Think about the model form

is an undetermined random walk

is a predetermined covariate

Unless is highly correlated with , then the inclusion of a state willbe favored over

65/73

Page 66: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

A note on model selection

Thus, work out fixed effects (covariates) while keeping the randomeffects (states) constant, and vice versa

For example, compare data support for models with differentcombinations of covariates, only one state ( = 1), and a "diagonal andequal"

66/73

Page 67: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Interpreting DFA results

Recall that we had to constrain the form of to fit the model

So, the 1st common factor is determined by the 1st variate, the 2ndcommon factor by the first two variates, etc.

67/73

Page 68: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Interpreting DFA results

To help with this, we can use a basis rotation to maximize the loadingson a few factors

If is an non-singular matrix, these 2 DFA models areequivalent

How should we choose ?

68/73

Page 69: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Basis rotationVarimax

A varimax rotation will maximize the variance of the loadings in alonga few of the factors

69/73

Page 70: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

PCA of 5 wines with 8 attributes

70/73

Page 71: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Rotated loadings

71/73

Page 72: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Rotated loadings

72/73

Page 73: Dynamic Factor Analysis - GitHub Pages 4/lec_08_intro_… · Dynamic Factor Analysis FISH 507 – Applied Time Series Analysis Mark Scheuerell 31 Jan 2019. Topics for today ... To

Topics for today

Deterministic vs stochastic elements

Regression with autocorrelated errors

Regression with temporal random effects

Dynamic Factor Analysis (DFA)

Forms of covariance matrix

Constraints for model fitting

Interpretation of results

·

·

·

73/73