Outline Dynamic linear models - IME-USP

20
State Space Models in R Giovanni Petris Department of Mathematical Sciences University of Arkansas [email protected] useR! 2011 Outline 1 State space models; filtering, smoothing and forecasting 2 A bag of models Structural time series models Model composition Other useful models 3 Model building Maximum likelihood estimation Filtering, smoothing and forecasting in R Residuals and diagnostics Model selection 4 Multivariate models 5 Bayesian inference Simulation-based inference Bayesian inference in structural time series 6 Discrete observations Giovanni Petris (U of Ark) State Space Models in R useR! 2011 2 / 85 State space models Unobservable states x0, x1,..., xt ,... Markov chain Observations y1,..., yt ,... conditionally independent, given the states x0 -→ x1 -→ x2 -→ ··· -→ xt-1 -→ xt -→ xt+1 -→ ··· y1 y2 yt-1 yt yt+1 A SSM is specified by the distributions p(x0) p(xt |xt-1) t =1, 2,... p(yt |xt ) t =1, 2,... Giovanni Petris (U of Ark) State Space Models in R useR! 2011 4 / 85 Dynamic linear models Special case x0 ∼Np(m0, C0) xt |xt-1 ∼Np(Gt xt-1, Wt ) yt |xt ∼Nm(Ft xt , Vt ) Ft ’s are p × m matrices Gt ’s are p × p matrices Vt ’s are m × m variance/covariance matrices Wt ’s are p × p variance/covariance matrices Equivalent formulation xt = Gt xt-1 + wt wt ∼Np(0, Wt ) system equation yt = Ft xt + vt vt ∼Nm(0, Vt ) observation equation Harvey (1989), Durbin and Koopman (2001), Petris, Petrone and Campagnoli (2009), Prado and West (2010), West and Harrison (1997),. . . Giovanni Petris (U of Ark) State Space Models in R useR! 2011 5 / 85

Transcript of Outline Dynamic linear models - IME-USP

Page 1: Outline Dynamic linear models - IME-USP

State Space Models in R

Giovanni Petris

Department of Mathematical SciencesUniversity of [email protected]

useR! 2011

Outline1 State space models; filtering, smoothing and forecasting

2 A bag of modelsStructural time series modelsModel compositionOther useful models

3 Model buildingMaximum likelihood estimationFiltering, smoothing and forecasting in RResiduals and diagnosticsModel selection

4 Multivariate models

5 Bayesian inferenceSimulation-based inferenceBayesian inference in structural time series

6 Discrete observations

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 2 / 85

State space models

Unobservable states x0, x1, . . . , xt , . . . Markov chainObservations y1, . . . , yt , . . . conditionally independent, given the states

x0 −→ x1 −→ x2 −→ · · · −→ xt−1 −→ xt −→ xt+1 −→ · · ·↓ ↓ ↓ ↓ ↓y1 y2 yt−1 yt yt+1

A SSM is specified by the distributions

p(x0)

p(xt |xt−1) t = 1, 2, . . .

p(yt |xt) t = 1, 2, . . .

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 4 / 85

Dynamic linear modelsSpecial case

x0 ∼ Np(m0,C0)

xt |xt−1 ∼ Np(Gtxt−1,Wt)

yt |xt ∼ Nm(Ftxt ,Vt)

Ft ’s are p ×m matricesGt ’s are p × p matricesVt ’s are m ×m variance/covariance matricesWt ’s are p × p variance/covariance matrices

Equivalent formulation

xt = Gtxt−1 + wt wt ∼ Np(0,Wt) system equation

yt = Ftxt + vt vt ∼ Nm(0,Vt) observation equation

Harvey (1989), Durbin and Koopman (2001), Petris, Petrone andCampagnoli (2009), Prado and West (2010), West and Harrison(1997),. . .

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 5 / 85

Page 2: Outline Dynamic linear models - IME-USP

Example: the local level modelStochastically varying level – random walk – observed with noise

xt = xt−1 + wt wt ∼ N (0,Wt)

yt = xt + vt vt ∼ N (0,Vt)

Here Ft = Gt =[1]

(1 by 1 matrix)

0 10 20 30 40

05

1015

Vt = 4, Wt = 1

x[[2

]]

0 10 20 30 40

05

1015

Vt = 0.2, Wt = 1

stateobservation

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 6 / 85

Filtering: Kalman filterLet y t = (y1, . . . , yt)

The filtering distributions p(xt |y t) can be computed recursively in t,starting from x0 ∼ N (m0,C0) at t = 0

Posterior at time t − 1: xt−1|y t−1 ∼ N (mt−1,Ct−1)

One-step forecast for the state

xt |y t−1 ∼ N (at ,Rt)

with at = Gtmt−1 and Rt = GtCt−1G ′t + Wt

One-step forecest for the observation

yt |y t−1 ∼ N (ft ,Qt)

with ft = Ftat and Qt = FtRtF′t + Vt

Posterior at time txt |y t ∼ N (mt ,Ct)

with at + RtF′tQ−1

t (yt − ft) and Ct = Rt − RtF′tQ−1t FtRt

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 7 / 85

Filtering: comments

Updating is sequential – allows for online processing

All the relevant distributions are Normal

The formulae shown are numerically unstable, but other more stablealgorithms are available – square-root filters

Package dlm implements a filter algorithm based on the singular valuedecomposition (SVD) of all the variance-covariance matrices

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 8 / 85

Smoothing

Backward recursive calculation of smoothing distributions p(xt |yT ), for afixed T and t = 0 . . . ,T , starting from xT |yT ∼ N (mT ,CT )

For t = T − 1, . . . , 0xt |yT ∼ N (st ,St)

with

st = mt + CtG′t+1R−1

t+1(st+1 − at+1)

St = Ct − CtG′t+1R−1

t+1(Rt+1 − St+1)R−1t+1Gt+1Ct

Comments:

Inherently offline data processing

All the relevant distributions are Normal

Same stability issues as in filtering recursion

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 9 / 85

Page 3: Outline Dynamic linear models - IME-USP

Forecasting

Recursive calculation of forecast distributions, starting fromxT |yT ∼ N (mT ,CT )For k = 1, 2, . . .

Forecast for the state

xT+k |yT ∼ N (aTk ,RTk )

with aTk = GT+kaTk−1 and RTk = GT+kRT

k−1G ′T+k + WT+k

Forecast for the observation

yT+k |yT ∼ N (f Tk ,Q

Tk )

with f Tk = FT+kaTk and QT

k = FT+kRTk F ′T+k + VT+k

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 10 / 85

DLM analysis in R

Base R – StructTS (Ripley)

Package KFAS (Helske)

Package dse (Gilbert)

Package sspir (Dethlefsen)

Package dlm (Petris)

Package FKF (Erb)

Package dlmodeler (Szymanski) – unified interface for dlm, KFAS,and FKF

Tusell, “Kalman filtering in R”. JSS, 2011Petris & Petrone, “State Space Models in R”. JSS, 2011

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 11 / 85

DLM analysis in RA quick comparison

dse sspir dlm FKF KFAS2009.10-2 0.2.8 1.1-1 0.1.0 0.6.0

Coded in : R + Fortran R R + C R + C R + FortranClass model (if any) S3 S3 S3 S3Algorithm CF CF SRCF CF CFSequential processing XExact diffuse initialization XMissing values allowed X X XTime varying matrices X X X XSimulator X XSmoother X X X XSimulation smoother X X XDisturbance smoother XMLE routine X X XNon-Gaussian models X X

Feature comparison. CF = Covariance filter, SRCF = Square root covariance

filter. (Adapted from Tusell (2011))

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 12 / 85

Local linear trend model

Dynamic “straight line” observed with noise

µt = µt−1 + δt−1 + wµt wµ

t ∼ N (0,W µ)

δt = δt−1 + w δt w δ ∼ N (0,W δ)

yt = µt + vt vt ∼ N (0,V )

Used to describe a level µt that is a locally linear function of time

Only a straight line if W µ = W δ = 0

For any fixed T and given data yT , the forecast functionaTk = E(yT+k |yT ) is a linear function of k

Sometimes called a polynomial model of order two

Generalizes the local level model and can be generalized to higherorder polynomial models

When W µ = 0, µt follows an integrated random walk

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 14 / 85

Page 4: Outline Dynamic linear models - IME-USP

Seasonal factor model

For quarterly seasonal data

st = −st−1 − st−2 − st−3 + wSt wS

t ∼ N (0,W S)

yt = st + vt vt ∼ N (0,V )

Used to describe a zero-mean locally cyclical departure st from a level

If W S = 0 then st + st−1 + st−2 + st−3 = 0 for every t

Typically used as a building block in more complex models

The extension to other sampling frequencies (e.g., 12 for monthlydata) is straightforward

Not a parsimonious model, especially for medium- or high-frequencydata – trigonometric models based on truncated Fourier sums providea parsimonious alternative

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 15 / 85

Objects of class “dlm”

Constant models are defined in package dlm as lists with components FF,

V, GG, W, with S3 class attribute "dlm"

Functions to get/set the components of a model are available

> mod <- dlmModPoly(2) # local linear trend

> names(mod)

[1] "m0" "C0" "FF" "V" "GG" "W" "JFF" "JV" "JGG" "JW"

> FF(mod) # observation matrix

[,1] [,2]

[1,] 1 0

> GG(mod) # system matrix

[,1] [,2]

[1,] 1 1

[2,] 0 1

> class(mod)

[1] "dlm"

Components JFF, JV, JGG, JW are used to represent time-varying models –details later

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 16 / 85

Easy creation of common DLMCreators for common DLM’s are available

Function Model

dlmModARMA ARMA processdlmModPoly nth order polynomial DLMdlmModReg Linear regressiondlmModSeas Periodic – Seasonal factorsdlmModTrig Periodic – Trigonometric form

Default argument values help to set up quickly a model skeleton, but theyare not always meaningful.

> args(dlmModPoly)

function (order = 2, dV = 1, dW = c(rep(0, order - 1), 1),

m0 = rep(0, order), C0 = 1e+07 * diag(nrow = order))

The function dlm allows to define any general DLM by specifying all of itselements – no defaults here.

Warning: in order for the filtering and smoothing algorithms implementedin package dlm to work correctly, V must be strictly positive, or positivedefinite in the multivariate case!

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 17 / 85

Model compositionInner sums

Thanks to the linear nature of the DLM, different models can be “added”together – in at least two different ways

Example of Inner sumCombine a model describing a trend with a model describing a quarterlyseasonal departure from the trend

> mod <- dlmModPoly() + dlmModSeas(4)

> FF(mod)

[,1] [,2] [,3] [,4] [,5]

[1,] 1 0 1 0 0

> GG(mod)

[,1] [,2] [,3] [,4] [,5]

[1,] 1 1 0 0 0

[2,] 0 1 0 0 0

[3,] 0 0 -1 -1 -1

[4,] 0 0 1 0 0

[5,] 0 0 0 1 0

Note the operator + acting on dlm objects

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 18 / 85

Page 5: Outline Dynamic linear models - IME-USP

Model compositionOuter sums

ExampleCombine two local linear trends to describe GDP of two different countries

> mod <- dlmModPoly() %+% dlmModPoly()

> FF(mod)

[,1] [,2] [,3] [,4]

[1,] 1 0 0 0

[2,] 0 0 1 0

> GG(mod)

[,1] [,2] [,3] [,4]

[1,] 1 1 0 0

[2,] 0 1 0 0

[3,] 0 0 1 1

[4,] 0 0 0 1

To combine large numbers of the same “base” univariate model, usedo.call and dlmSum

> mod <- do.call(dlmSum, rep(list(dlmModPoly()), 25))

> dim(FF(mod))

[1] 25 50

> dim(GG(mod))

[1] 50 50

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 19 / 85

Trigonometric modelsAny zero-mean periodic function g(t) defined on the integers, having evenperiod s, can be written as

g(t) =

s/2∑j=1

aj cos(tωj) + bj sin(tωj)︸ ︷︷ ︸jth harmonic

where ωj = 2πj/s are the Fourier frequencies

Drop the high frequency harmonics to obtain a smoothed version of g(t)

g(t) ≈q∑

j=1

aj cos(tωj) + bj sin(tωj)

Example: describe monthly economic data using the first two harmonics

> mod <- dlmModTrig(s = 12, q = 2) + dlmModPoly()

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 20 / 85

ARMA models as DLM components

ARMA models lack the clean interpretation of other common DLM’s, butare sometimes used as additional components to explain autocorrelatedresiduals

For example, the code

> dlmModPoly(2) + dlmModSeas(4) +

+ dlmModARMA(ar = c(0.8, -0.2), ma = 0.3, sigma2 = 5)

sets up a model for quarterly data, with a local linear trend, seasonalfactor component, and ARMA(2, 1) error termThe ARMA model specified by the code is

yt = 0.8yt−1 − 0.2yt−2 + εt + 0.3εt−1 εt ∼ N (0, 5)

Multivariate ARMA models can be set up similarly

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 21 / 85

Regression models

Static and dynamic linear regression can be cast in DLM formLet X = [ut,j ] be the T × p design matrix

State xt = (β1,t , . . . , βp,t)′, regression coefficients at time t

Observation matrix Ft =[ut,1 . . . ut,p

], t-th row of the design matrix

System matrix Gt = Ip, each regression coefficient evolves accordingto a random walkWhen Wt = 0 the βj ,t ’s do not change with time – static regression

Note: here the model is time-varying – Ft does change with t

> T <- 100

> p <- 5

> X <- matrix(rnorm(T * p), nrow = T, ncol = p) # a simulated design matrix

> mod <- dlmModReg(X, addInt = FALSE)

The default addInt = TRUE adds an intercept to the design matrix

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 22 / 85

Page 6: Outline Dynamic linear models - IME-USP

Maximum likelihood

Let ψ be a vector of unknown model parametersThe evaluation of the likelihood function can be done in two steps

Plug the value ψinto the model

=⇒ Evaluate the joint density ofthe data under the model

The joint probability density of the data, i.e., the likelihood, can be easilycomputed as a byproduct of Kalman filter

The first step is highly dependent on the specific model being considered

User needs to specify a function that performs the first step

The maximum of the likelihood function can then be found by yourfavorite tool – e.g., optim

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 24 / 85

Maximum likelihood in RExample: MLE of unknown variances for the Nile river level

> buildLocalLevel <- function(psi)

+ dlmModPoly(1, dV = psi[1], dW = psi[2], C0 = 1e8)

> mleOut <- dlmMLE(Nile,

+ parm = c(0.2, 120), # initial values for optimizer

+ build = buildLocalLevel,

+ lower = c(1e-7, 0)) # V must be positive

> mleOut$convergence # always check this!!!

[1] 0

> mod <- buildLocalLevel(psi = mleOut$par) # the fitted model

> drop(V(mod)) # observation variance

[1] 15098.65

> drop(W(mod)) # system variance

[1] 1469.101

> StructTS(Nile, type = "level") # A call to StructTS() for comparison

Call:

StructTS(x = Nile, type = "level")

Variances:

level epsilon

1469 15099

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 25 / 85

Standard errors

The inverse of the Hessian matrix of the negative loglikelihood function atthe MLE provides an estimate of the asymptotic variance of the MLE.Standard errors can be derived from the diagonal elements.

My recommended way of obtaining the Hessian in R is to rely on thefunction hessian in package numDeriv (Gilbert, 2011)

> hs <- hessian(function(x) dlmLL(Nile, buildLocalLevel(x)), mleOut$par)

> all(eigen(hs, only.values = TRUE)$values > 0) # positive definite?

[1] TRUE

> aVar <- solve(hs) # asymptotic variance/covariance matrix

> aVar

[,1] [,2]

[1,] 9894760 -2457095

[2,] -2457095 1639308

> sqrt(diag(aVar))

[1] 3145.594 1280.355

Large standard errors are the rule rather than the exception

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 26 / 85

General recommendations about MLE

Common issuesI Multiple local maxima of the loglikelihoodI Fairly flat loglikelihood surface

FixesI Repeat the optimization process several times, starting at different

parameter values, to gain confidence that you actually found a globalmaximum

I Make sure the Hessian of the negative loglikelihood at the maximum ispositive definite

I Compute standard errors of MLEs to get a feeling for the accuracy ofthe estimates

What is not easy is the optimization, and I am now convincedthat many of the published examples are incorrect.

Brian Ripley, R News June 2002

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 27 / 85

Page 7: Outline Dynamic linear models - IME-USP

Filtering in R

> nileFilt <- dlmFilter(Nile, mod) # Kalman filter

The filtering routine returns

the series of filtering means mt = E(xt |y t) – includes t = 0

the series of filtering variances Ct = Var(xt |y t) – includes t = 0

the series of one-step forecasts for the state at = E(xt |y t−1)

the series of one-step forecast variances for the stateRt = Var(xt |y t−1)

the series of one-step forecasts for the observation ft = E(yt |y t−1)

Variances are returned in terms of their singular value decomposition, e.g.,Ct = UtD

2t U ′t , with Dt diagonal and Ut orthogonal

For one-dimensional states Ct = D2t

In general the sequence of variance matrices can be recovered using

> Ct <- with(nileFilt, dlmSvd2var(U.C, D.C))

> Rt <- with(nileFilt, dlmSvd2var(U.R, D.R))

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 28 / 85

Filtering in R: example

1880 1900 1920 1940 1960

600

800

1000

1400

datafiltered level90% probability interval

> level <- dropFirst(nileFilt$m) # filtered level

> sdC <- abs(dropFirst(nileFilt$D.C)) # filtering standard deviations

> ci <- drop(sdC %o% qnorm(c(0.05, 0.95))) + as.vector(level) # 90% interval

> ci <- ts(ci, start = start(Nile))

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 29 / 85

Smoothing in R

> nileSmooth <- dlmSmooth(Nile, mod) # Kalman smoother

> nileSmooth <- dlmSmooth(nileFilt) # the same

The smoothing routine returns

the series of smoothing means st = E(xt |yT ) – includes t = 0

the series of smoothing variances St = Var(xt |yT ) – includes t = 0

As is the case for filtering, smoothing variances are returned in terms oftheir SVD. To recover variance/covariance matrices

> St <- with(nileSmooth, dlmSvd2var(U.S, D.S)) # smoothing variance

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 30 / 85

Smoothing in R: example

1880 1900 1920 1940 1960

600

800

1000

1200

1400

datasmoothed level90% probability interval

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 31 / 85

Page 8: Outline Dynamic linear models - IME-USP

Forecasting in R

The function dlmForecast returns, for k = 1, 2, . . .

the series of k-step-ahead forecasts of the states aTk = E(xT+k |yT )

the series of forecast variances for the states RTk = Var(xT+k |yT )

the series of k-step-ahead forecasts of the observationsf Tk = E(yT+k |yT )

the series of forecast variances for the observationsQT

k = Var(yT+k |yT )

simulated new states and observations, if argument sampleNew isspecified

Forecast variances are returned as matrices – no SVD here

The function can also be called on a model – an object of class dlm – toobtain forecasts at time t = 0 and simulate from the model

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 32 / 85

Forecasting: R code

> nileForecast <- dlmForecast(nileFilt, n = 20)

> nileForecast <- dlmForecast(nileFilt, n = 20, sampleNew = 50)

> str(nileForecast, 1)

List of 6

$ a : ts [1:20, 1] 798 798 798 798 798 ...

..- attr(*, "dimnames")=List of 2

..- attr(*, "tsp")= num [1:3] 1971 1990 1

$ R :List of 20

$ f : ts [1:20, 1] 798 798 798 798 798 ...

..- attr(*, "dimnames")=List of 2

..- attr(*, "tsp")= num [1:3] 1971 1990 1

$ Q :List of 20

$ newStates:List of 50

$ newObs :List of 50

> nodataForecast <- dlmForecast(mod, n = 100, sampleNew = 100)

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 33 / 85

Forecasting in R: example

1930 1940 1950 1960 1970 1980 1990

500

700

900

1100

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 34 / 85

Residuals

One-step forecast errors, or innovations

et = yt − E(yt |y t−1)

The innovations are a sequence of independent Gaussian random variablesStandardize to obtain a sequence of iid standard normal random variables

et = et/√

Qt

Both ft = E(yt |y t−1) and Qt = Var(yt |y t−1) are obtained from Kalmanfilter

Use to assess whether or not the model assumptions hold

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 35 / 85

Page 9: Outline Dynamic linear models - IME-USP

Model checkingExample: Nile river data

> nileRes <- residuals(nileFilt, sd = FALSE) # standardized innovations

> qqnorm(nileRes) # graphical normality assessment

> qqline(nileRes)

> tsdiag(nileFilt) # standard diagnostics

1880 1900 1920 1940 1960

600

800

1200

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 36 / 85

●●

●●

●●

●●

●●

●●●

●●

●●

●●

●●●

●●

●●

−2 −1 0 1 2

−3

−2

−1

01

2

Normal Q−Q Plot

Theoretical Quantiles

Sam

ple

Qua

ntile

s

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 37 / 85

Standardized Residuals

Time

1880 1900 1920 1940 1960

−3

−2

−1

01

2

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 38 / 85

0 5 10 15 20

−0.

20.

20.

61.

0

Lag

AC

F

ACF of Residuals

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 39 / 85

Page 10: Outline Dynamic linear models - IME-USP

● ●

● ●●

2 4 6 8 10

0.0

0.2

0.4

0.6

0.8

1.0

p values for Ljung−Box statistic

lag

p va

lue

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 40 / 85

Model selection

Model selection for DLMs is usually based on either of the followingcriteria

Forecasting accuracy

Information criteria – AIC, BIC

Bayes factors and posterior model probabilities (in a Bayesian setting)

If the model is going to be used to predict future outcomes of the process,then forecasting accuracy makes a lot of sense as a model selectioncriterion

We will focus here on the first two general criteria

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 41 / 85

Forecasting accuracy

The most commonly used measures of forecasting accuracy are

Mean square error: MSE =1

T

T∑t=1

(yt − E(yt |y t−1)

)2

Mean absolute deviation: MAD =1

T

T∑t=1

∣∣yt − E(yt |y t−1)∣∣

Mean absolute percentage error: MAPE =1

T

T∑t=1

∣∣yt − E(yt |y t−1)∣∣

yt

Theil’s U: U =

√∑nt=2(yt − E(yt |y t−1))2∑n

t=2(yt − yt−1)2

Criteria are all based on the innovations et = yt − E(yt |y t−1)May consider averages after “burn-in”

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 42 / 85

Information criteria

For DLMs, AIC and BIC are defined in the usual way

AIC = −2`(ψ) + 2k

BIC = −2`(ψ) + k log T

where `() is the loglikelihood function, ψ is the MLE of the unknownparameter vector ψ, k is the number of independent parameters of themodel, and T is the number of observations

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 43 / 85

Page 11: Outline Dynamic linear models - IME-USP

Model selection: example

For the Nile river data, consider four different models

1 Local level

2 Local level, accounting for the construction of the first Aswan dam(1899–1902). This 3-parameter model assumes that the systemvariance at time t = 1899 is different from the rest of the series,allowing for a big jump in the level between 1899 and 1900.

3 Local linear trend

4 Integrated random walk plus noise

Want the data to tell which of the four is the best model

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 44 / 85

Model selection: results

MSE MAD MAPE U logLik k AIC

local level 20992 114.22 0.13 0.86 −550.8 2 1105.6dam effect 18542 105.74 0.12 0.81 −543.3 3 1092.6linear trend 22405 117.55 0.13 0.89 −558.2 3 1122.5irw 23476 119.51 0.14 0.91 −560.6 2 1125.1

Adding one extra parameter to the local level model in order to accountfor a jump in the level at a single time point is definitely worth the effort

The local level model with dam effect is the best model across the board

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 45 / 85

Model selection: R detailsThe following code was used to fit the local linear trend model andcompute the model selection criteria

> buildLinearTrend <- function(psi)

+ dlmModPoly(2, dV = psi[1], dW = psi[2 : 3], C0 = diag(1e8, 2))

> mleLinearTrend <- dlmMLE(Nile,

+ parm = c(0.2, 120, 20),

+ build = buildLinearTrend,

+ lower = c(1e-7, 0, 0))

> mleLinearTrend$conv

[1] 0

> linearTrend <- buildLinearTrend(psi = mleLinearTrend$par)

> linearTrend_filtered <- dlmFilter(Nile, linearTrend)

> linearTrend_resid <- residuals(linearTrend_filtered, type = "raw", sd = FALSE)

> linearTrend_resid <- tail(linearTrend_resid, -burn_in)

> MSE["linear trend"] <- mean(linearTrend_resid^2)

> MAD["linear trend"] <- mean(abs(linearTrend_resid))

> MAPE["linear trend"] <- mean(abs(linearTrend_resid) / tail(Nile, -burn_in))

> U["linear trend"] <- sqrt(mean(linearTrend_resid^2) /

+ mean(tail(diff(Nile)^2, -(burn_in-1))))

> logLik["linear trend"] <- -mleLinearTrend$value

> k["linear trend"] <- length(mleLinearTrend$par)

> AIC <- -2 * (logLik - k) # vectorized, for all models at once

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 46 / 85

Time-varying models in R

Recall the “dam effect” local level model. The only time-varyingparameter is the system variance Wt . Formally

xt = xt−1 + wt wt ∼ N (0,Wt)

yt = xt + vt vt ∼ N (0,V )

with

Wt =

{W if t 6= 1899

W? if t = 1899

In R we have to set up a model skeleton – a constant local level model, –let R know that W is really time-varying, and tell R where to find thevalue of W at any time

In general for p > 0, W is a variance covariance matrix and we have tospecify the entries of W which are time-varying

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 47 / 85

Page 12: Outline Dynamic linear models - IME-USP

Time-varying models: example

Set up a model skeleton

> mod <- dlmModPoly(1, dV = 16300, C0 = 1e8)

Define an additional component X of the dlm object that holds the valuesof all the time-varying entries of Wt

> X(mod) <- matrix(0, nrow = length(Nile))

> X(mod)[time(Nile) == 1899] <- 60580

Tell R that the values of Wt at any time are to be found in the firstcolumn of the matrix X

> JW(mod) <- 1

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 48 / 85

MLE of the dam effect model parametersHere is how the local level model with dam effect was fit to the Nile riverlevel data

> buildDamEffect <- function(psi) {

+ mod <- dlmModPoly(1, dV = psi[1], C0 = 1e8)

+ X(mod) <- matrix(psi[2], nr = length(Nile))

+ X(mod)[time(Nile) == 1899] <- psi[3]

+ JW(mod) <- 1

+ mod

+ }

> mleDamEffect <- dlmMLE(Nile,

+ parm = c(0.2, 120, 20),

+ build = buildDamEffect,

+ lower = c(1e-7, 0, 0))

> mleDamEffect$conv

[1] 0

> damEffect <- buildDamEffect(psi = mleDamEffect$par)

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 49 / 85

Regression models in RRecall that for the DLM form of the dynamic linear regression model

Ft =[ut,1 . . . ut,p

]t-th row of the design matrix

xt = (β1,t , . . . , βp,t)′ regression coefficients at time t

Example: sales data and leading indicator – use linear term and log

> BJmod <- dlmModReg(X = cbind(BJsales.lead, log(BJsales.lead)))

> X(BJmod)

BJsales.lead log(BJsales.lead)

1 10.01 2.303585

2 10.07 2.309561

...stuff deleted...

> JFF(BJmod)

[,1] [,2] [,3]

[1,] 0 1 2

> FF(BJmod)

[,1] [,2] [,3]

[1,] 1 1 1

Warning message:

In FF.dlm(BJmod) : Time varying F

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 50 / 85

Seemingly Unrelated Time Series EquationsSUTSE is a multivariate model used to describe univariate series that canbe marginally modeled by the “same” DLM – same observation matrix F0

and system matrix G0, p-dimensional state vectors have the sameinterpretation.Example: GDPs of different countries can all be described by a local lineartrend – but obviously they are not independent

For k such series, define the observation and system matrices of the jointmodel as

F = F0 ⊗ Ik G = G0 ⊗ Ik

where Ik is the k × k identity matrix and ⊗ is Kronecker product

The pk × pk system variance W is typically given a block-diagonal form,with p k × k blocks, implying a correlated evolution of the j-thcomponents of the state vector of each series. The k × k observationvariance V may be non-diagonal to account for additional correlationamong the different series.

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 52 / 85

Page 13: Outline Dynamic linear models - IME-USP

SUTSE: exampleConsider GDP of Germany, UK, and USA. The series are obviouslycorrelated and, for each of them – possibly on a log scale – a local lineartrend model or possibly a more parsimonious integrated random walk plusnoise seems a reasonable choice. (Scales of the plots differ)

1950 1955 1960 1965 1970 1975 1980

GERMANYUKUSA

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 53 / 85

SUTSE in R (1)Read the data in and set up a model skeleton, to be used in conjunctionwith MLE routine

> gdp0 <- read.table("http://definetti.uark.edu/~gpetris/UseR-2011/gdp.txt",

+ skip = 3, header = TRUE)

> gdp <- ts(10 * log(gdp0[, c("GERMANY", "UK", "USA")]), start = 1950)

> uni <- dlmModPoly() # the ’base’ univariate model

> gdpSUTSE <- uni %+% uni %+% uni # to get the matrices of the correct dim

> ## now redefine matrices to keep levels together and slopes together

> FF(gdpSUTSE) <- FF(uni) %x% diag(3)

> GG(gdpSUTSE) <- GG(uni) %x% diag(3)

> W(gdpSUTSE)[] <- 0 # ’clean’ the system variance

Define a “build” function to be given to MLE routine

> buildSUTSE <- function(psi) {

+ U <- matrix(0, nrow = 3, ncol = 3)

+ U[upper.tri(U)] <- psi[1 : 3]

+ diag(U) <- exp(0.5 * psi[4 : 6])

+ W(gdpSUTSE)[4 : 6, 4 : 6] <- crossprod(U)

+ diag(V(gdpSUTSE)) <- exp(0.5 * psi[7 : 9])

+ gdpSUTSE

+ }

Note log-Cholesky parametrization of the covariance matrix WGiovanni Petris (U of Ark) State Space Models in R useR! 2011 54 / 85

SUTSE in R (2)

Find the MLE of the unknown parameters and set up the fitted model

> gdpMLE <- dlmMLE(gdp, rep(-2, 9), buildSUTSE,

+ control = list(maxit = 500))

> gdpMLE$conv

[1] 0

> gdpSUTSE <- buildSUTSE(gdpMLE$par)

Look at the estimated variance/covariance matrices

> W(gdpSUTSE)[4 : 6, 4 : 6]

[,1] [,2] [,3]

[1,] 0.0766 0.0370 0.0396

[2,] 0.0370 0.0212 0.0307

[3,] 0.0396 0.0307 0.0602

> cov2cor(W(gdpSUTSE)[4 : 6, 4 : 6]) # correlations (slopes)

[,1] [,2] [,3]

[1,] 1.000 0.916 0.583

[2,] 0.916 1.000 0.860

[3,] 0.583 0.860 1.000

> sqrt(diag(V(gdpSUTSE))) # observation standard deviations

[1] 0.000459 0.147465 0.114126

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 55 / 85

SUTSE in R (3)The fitted model can be used to smooth GDP for the three countries

> gdpSmooth <- dlmSmooth(gdp, gdpSUTSE)

The first three columns of gdpSmooth$s contain the time series ofsmoothed GDP level, the last three the smoothed slopes

1950 1955 1960 1965 1970 1975 19801950 1955 1960 1965 1970 1975 1980

GERMANYUKUSA

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 56 / 85

Page 14: Outline Dynamic linear models - IME-USP

SUTSE in R (4)Finally, the slopes of the local linear trends can be compared. As expected,they tend to move together for the three countries considered here

0.0

0.4

0.8

GE

RM

AN

Y

0.0

0.2

0.4

UK

−0.

10.

10.

3

1950 1955 1960 1965 1970 1975 1980

US

A

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 57 / 85

Dynamic factor models (1)The dynamic factor model provides another useful approach to modelmultivariate time series. Suppose that a q-dimensional vector of factors ztevolves according to a DLM

xt = Gxt−1 + wt wt ∼ Np(0,W )

zt = F0xt + εt εt ∼ Nq(0,Σ)

and the m-dimensional observation yt at any time t is a linear combinationof the factor components, subject to additive observation noise

yt = Azt + vt , vt ∼ Nm(0,V )

Setting Σ = 0, so that εt = 0 for every t, we have the DLM

xt = Gxt−1 + wt wt ∼ Np(0,W )

yt = Fxt + vt vt ∼ Nm(0,V )

where F = AF0

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 58 / 85

Dynamic factor models (2)

Fm×p

= Am×q

F0q×p

Typically, in factor models q < m ≤ p

From the filtering/smoothing estimates of the states xt one can obtain thecorresponding estimates of the unobservable factors as

zt = F0xt

where xt = E(xt |y t) – filtering – or xt = E(xt |yT ) – smoothingVariance/covariance matrices of the factors can be obtained using the“sandwich formula”:

Var(zt |y t) = F0Var(xt |y t)F ′0 = F0CtF′0

and similarly for the smoothing variances

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 59 / 85

Dynamic factor models (3)

The matrix of factor loadings A needs to be estimated from the data andhas to satisfy, together with the system variance/covariance matrix W ,some identifiability constraints.

We will make the identifiability assumption that

Ai ,j =

{0 if i < j

1 if i = j

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 60 / 85

Page 15: Outline Dynamic linear models - IME-USP

Factor models: example (1)

Consider again the GDP of Germany, UK, and USA. In view of the strongsimilarities among the three time series, one may try to fit a dynamicfactor model with one or two independent local linear trend factors

For the one-factor model

A =

1a21

a31

, F0 =[1 0

], F = AF0 =

1 0a21 0a31 0

, G =

[1 10 1

]

The system and observation variances V and W are assumed to bediagonal of order 3 and 2, respectively

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 61 / 85

Factor models: example (2)

For the two-factor model

A =

1 0a21 1a31 a32

, F0 =

[1 0 0 00 0 1 0

]

F = AF0 =

1 0 0 0a21 0 1 0a31 0 a32 0

, G =

[1 10 1

]

with V and W diagonal of order 3 and 4, respectively

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 62 / 85

Factor models: example (3)

Maximum likelihood estimates for the two models are as follows

One-factor model

A =

1.000.180.71

diag(V ) = (0.00, 1.47, 0.92)√diag(W ) = (0.20, 0.08)

AIC = 81.36

Two-factor model

A =

1.00 0.000.38 1.000.62 −0.42

diag(V ) = (0.00, 0.06, 0.70)√diag(W ) = (0.19, 0.09, 0.17, 0.00)

AIC = −29.22

Based on AIC, the two-factor model is much better. However, the SUTSEfor the same data has AIC = −57.01 and is even better

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 63 / 85

Factor models: example (4)The following plot shows the smoothed factors of the two-factor model.Note the negative sign of the second factor

1822

2630

Ser

ies

1

−6.

5−

5.5

−4.

5

1950 1955 1960 1965 1970 1975 1980

Ser

ies

2

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 64 / 85

Page 16: Outline Dynamic linear models - IME-USP

Bayesian inferenceInclude in the model a prior distribution p(ψ) for the unknown vectorparameter ψ = (ψ1, . . . , ψd)Posterior distributions of interest include

p(ψ|yT ) posterior distribution of ψp(xT |yT ) posterior distribution of the statesp(xT , ψ|yT ) joint posterior distribution of states

and parameterp(xT+1, . . . , xT+k |yT ) forecast distribution of the states

Bayesian inference in DLMs requires, except in trivial cases, approximatecomputational methods. Monte Carlo methods are currently the mostpopular choices

Smoothing −→ Markov chain MCFiltering −→ Particle filter

We will consider the smoothing problem only, using the Gibbs sampler, aparticular MCMC method

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 66 / 85

Gibbs sampling for DLMs

Let us focus on the target distribution p(xT , ψ|yT ). The Gibbs samplerdraws a sample asymptotically from the target by starting with anarbitrary value ψ0 and iterating, for n = 1, 2, . . . ,N, the two steps

(1) draw xTn ∼ p(xT |yT , ψ = ψn−1)

(2) draw ψn ∼ p(ψ|yT , xT = xTn )

The distribution in (1) is Gaussian; a sample from it can be drawnefficiently using a sampling analog of the backward smoothing recursioncalled forward filtering backward sampling (FFBS) algorithm

The distribution in (2) depends on the specific model and prior used, butusually it is easier to draw ψ from this distribution than it is to draw itfrom p(ψ|yT )

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 67 / 85

The d-inverse gamma model (1)

In many univariate structural models (local level, local linear trend,seasonal factor components,...) the only unknown parameters are theobservation and system variances. In this case, assuming independentinverse gamma priors for these variances, it is easy to set up a Gibbssampler – conditionally conjugate model

Suppose there are d unknown variances σ21, . . . , σ

2d to be estimated.

Define the corresponding precisions ψi = σ−2i and let the prior be

ψi ∼ G(αi , βi )

where βi is the rate parameter of the distribution

Some of the variances of the model may be known – typically zero in thiscase

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 68 / 85

The d-inverse gamma model (2)

Combining prior and likelihood – considering for example the observationprecision ψ1, say – after some easy calculations we see that

p(ψ1|xT , yT ) ∝ p(ψ1)∏t

p(yt |xt , ψ1)

∝ ψα1−11 e−β1ψ1ψ

T/21 exp

{−ψ1

2

∑t

(yt − Fxt)2

}

∝ ψα1+T2−1

1 exp

{−ψ1

(β1 +

1

2

∑t

(yt − Fxt)2

)}

Hence, ψ1|xT , yT ∼ G

(α1 +

T

2, β1 +

1

2

∑t

(yt − Fxt)2

)

Similar distributional results hold for the other precisions

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 69 / 85

Page 17: Outline Dynamic linear models - IME-USP

The d-inverse gamma model: example

Consider quarterly gas consumption in UK. On a log scale a reasonablemodel could be a local linear trend plus a seasonal factor component

F =[1 0 1 0 0

]V =

[σ2

1

]

G =

1 1 0 0 00 1 0 0 00 0 -1 -1 -10 0 1 0 00 0 0 1 0

W = diag(σ2

2, σ23, σ

24, 0, 0)

1960 1965 1970 1975 1980 1985

4.5

5.0

5.5

6.0

6.5

7.0

Unknown parameter ψ = (σ−21 , σ−2

2 , σ−23 , σ−2

4 )

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 70 / 85

The d-inverse gamma model in RThe Gibbs sampler is performed in R by the function dlmGibbsDIG

> outGibbs <- dlmGibbsDIG(lgas,

+ dlmModPoly(2) + dlmModSeas(4), # model

+ a.y = 1, b.y = 1000, # mean and var of gamma prior

+ a.theta = 1, b.theta = 1000, # same, for system vars

+ n.sample = 1100,

+ ind = 1 : 3, # which elmts of diag(W) are estimated

+ save.states = FALSE)

The output consists of simulated values of V = σ21 and diagonal elements

of W , σ22, σ

23, σ

24

Trace plots of the simulated values of the standard deviations σi and ofthe relative ergodic means

σ(n)i =

1

n

n∑j=1

σ(j)i , n = n0, . . . ,N

are shown in the next slide

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 71 / 85

Gibbs sampler output: univariate plots

0 200 600 1000

0.02

0.04

0.06

σ1

0 200 600 1000

0.01

0.03

0.05

σ2

0 200 600 1000

0.00

80.

012

0.01

60.

020

σ3

0 200 600 1000

0.04

0.05

0.06

0.07

0.08

σ4

0.03

20.

034

0.03

60.

038

500 1000

0.02

40.

026

500 1000

0.01

350.

0140

0.01

45

500 1000

0.05

90.

061

0.06

3

500 1000

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 72 / 85

Gibbs sampler output: multivariate plots

The output from the Gibbs samplerallows to visualize joint posteriordistributions. The graph on the rightshows the jointly simulated values ofσ2 and σ3

0.01 0.02 0.03 0.04 0.05 0.06

0.00

80.

012

0.01

60.

020

σ2

σ 3

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 73 / 85

Page 18: Outline Dynamic linear models - IME-USP

Gibbs sampler: Bayes estimates

From the Gibbs sampler output we can compute Bayes estimate of theparameter or of any function thereof. Monte Carlo standard errors –computed accounting for the autocorrelation of the sampler’s output – arereturned as well

Below it is shown how to obtain Bayes estimate of all the standarddeviations in R

> mcmcMean(cbind(sqrt(dV[-(1:burn)]), sqrt(dW[-(1:burn), ])))

W.1 W.2 W.3

0.038085 0.023786 0.013370 0.058695

(0.001503) (0.000849) (0.000253) (0.000963)

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 74 / 85

Dynamic Generalized Linear Models

DLMs are among the nicest state space models, allowing severalcomputations to be performed exactly, and leaving at the same time a lotof flexibility in the choice of a specific model.

To retain at least part of these features and account for discreteobservations, we can leave the system dynamics untouched – i.e., linearand Gaussian – and replace the observation equation with the following

yt |xt ∼ p(yt |ηt = Fxt)

where p(y |η) is an exponential family distribution with natural parameterη

Binomial(n, π), with η = logπ

1− πPoisson(λ), with η = log λ

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 76 / 85

DGLM: example

To illustrate how to fit a DGLM in R, consider the data set ldeaths,containing monthly counts of deaths from lung diseases in the UK,1974–1979. Count data suggest to use a Poisson distribution for theobservations. To model the state vector a local level plus seasonal factormodel seems appropriate

The two packages KFAS and sspir can treat univariate DGLMs, bothconstant and time-varying, using approximate filtering and smoothingtechniques.

In this application we will use sspir, which has a nice formula interface –relieving the user from specifying explicitely all the matrices of the model

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 77 / 85

DGLM with sspir

The code below illustrates the model fitting and smoothing procedures1 set up a model skeleton

> lungPoi <- ssm(ldeaths ~ tvar(1) + tvar(sumseason(time, period = 12)),

+ family = poisson(link = "log"),

+ phi = c(1, 0.2, 0.2),

+ C0 = diag(x = 1e5, 12))

> lungPoi <- getFit(lungPoi)

2 define a function that returns the loglikelihood and maximise it> loglik <- function(psi) {

+ lungPoi$phi[-1] <- exp(psi)

+ extended(lungPoi)$loglik

+ }

> optimOut <- optim(c(-2, -2), loglik, method = "BFGS",

+ control = list(fnscale = -1))

> optimOut$conv

[1] 0

> exp(optimOut$par) # MLE of variances

[1] 1.184461e-02 2.075678e-07

3 use the fitted model to compute smoothing means and variances> lungPoi$phi[-1] <- exp(optimOut$par) # fitted model

> lungPoiSmooth <- extended(lungPoi) # iterated extended Kalman smoother

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 78 / 85

Page 19: Outline Dynamic linear models - IME-USP

Example: smoothed counts

1974 1975 1976 1977 1978 1979 1980

1500

2000

2500

3000

3500

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 79 / 85

Short bibliography: general references

Durbin J, Koopman SJ (2001).Time Series Analysis by State Space Methods.Oxford University Press, Oxford.

Harvey A (1989).Forecasting, Structural Time Series Models and the Kalman filter.Cambridge University Press, Cambridge.

Kim C-J, Nelson, C (1999).State Space Models with Regime Switching.MIT Press, Cambridge.

West M, Harrison J (1997).Bayesian Forecasting and Dynamic Models.2nd edition. Springer, New York.

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 81 / 85

Short bibliography: state space models in R

Dethlefsen C, Lundbye-Christensen S (2006).

Formulating State Space Models in R with focus on longitudinal regression models.

Journal of Statistical Software, 16(1), 1–15.

http://www.jstatsoft.org/v16/i01.

Dethlefsen C, Lundbye-Christensen S, Luther Christensen A (2009).

sspir: State Space Models in R.

R package version 0.2.8, http://CRAN.R-project.org/package=sspir.

Gilbert P (2011).

dse: Dynamic Systems Estimation.

R package version 2011.3-1

Helske J (2010).

KFAS: Kalman filter and smoothers for exponential family state space models.

R package version 0.5.1, http://CRAN.R-project.org/package=KFAS.

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 82 / 85

Short bibliography: state space models in R (cont.)

Luethi D, Erb P, Otziger S (2010).

FKF: Fast Kalman Filter.

R package version 0.1.1, http://CRAN.R-project.org/package=FKF.

Petris G, Petrone S, Campagnoli P (2009).

Dynamic linear models with R.

Springer, New York.

Petris G (2010).

dlm: Bayesian and likelihood analysis of dynamic linear models.

R package version 1.1-2, http://CRAN.R-project.org/package=dlm.

Petris G (2010).

An R Package for dynamic linear models.

Journal of Statistical Software, 36(12), 1–16.

http://www.jstatsoft.org/v36/i12.

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 83 / 85

Page 20: Outline Dynamic linear models - IME-USP

Short bibliography: state space models in R (cont.)

Petris G and Petrone S (2011).

State Space Models in R.

Journal of Statistical Software, 41(4), 1–25.

http://www.jstatsoft.org/v41/i4.

Ripley B (2002).

Time series in R 1.5.0.

R News, 2(2), 2–7.

http://CRAN.R-project.org/doc/Rnews/.

Tusell F (2011).

Kalman filtering in R.

Journal of Statistical Software, 39(2), 1–27.

http://www.jstatsoft.org/v39/i2.

Giovanni Petris (U of Ark) State Space Models in R useR! 2011 84 / 85