state space models - jyväskylän yliopistousers.jyu.fi/~jovetale/posters/kfasposter.pdf ·...

1
Jouni Helske University of Jyv ¨ askyl¨ a, Department of Mathematics and Statistics [email protected] generalized linear models dynamic factor analysis ARIMA models cubic splines structural time series dynamic linear regression exponential smoothing mixed models generalized linear mixed models state space models multivariate linear models Exponential family state space model with p time series: p Y i=1 p i (y t | Z t α t ) p i = Gaussian Poisson Binomial Negative binomial Gamma α t+1 = T t α t + R t η t , η t N (0,Q t ), α 1 N (a 1 ,P 1 ) Main features of KFAS Kalman filtering and smoothing Simulation smoothing for Gaussian models Importance sampling and Laplace approximation for non-Gaussian models Exact diffuse initialization of unknown states Multivariate models with different distributions for each series Maximum likelihood estimation Prediction intervals Multiple types of residuals References J. Durbin and S. J. Koopman. Time series analysis by state space methods (Second edition). Oxford University Press, New York, 2012. J. Helske. KFAS: Exponential family state space models in R. Submitted, 2015. github.com/helske/KFAS tinyurl.com/KFASvignette tinyurl.com/KFASposter Alcohol related deaths in Finland p(y t |θ t )= Poisson(u t e θ t ) u t = population at time t θ t = μ t + t , t N (0,Q noise ) t = additional white noise μ t+1 = μ t + ν t + ξ t , ξ t N (0,Q level ) μ t = random walk with drift ν t+1 = ν t ν t = constant slope Parameter estimation and prediction alcoholPred <- window(alcohol, start = 1969, end = 2007) # build model mod <- SSModel(alcoholPred[,1:4] ˜ SSMtrend(2, Q = list(matrix(NA,4,4), diag(0,4))) + SSMcustom(Z = diag(4), T = diag(0,4), Q = matrix(NA,4,4), P1 = matrix(NA,4,4)), distribution = "poisson", u = alcoholPred[,5:8]) # model updating function for fitSSM updatefn <- function(pars, model, ...){ Q <- diag(exp(pars[1:4])); Q[upper.tri(Q)] <- pars[5:10] model["Q", etas = "level"] <- crossprod(Q) Q <- diag(exp(pars[11:14])); Q[upper.tri(Q)] <- pars[15:20] model["Q", etas = "custom"] <- model["P1", states = "custom"] <- crossprod(Q) model } model <- fitSSM(mod, updatefn = updatefn, inits = init, method = "BFGS")$model # prediction pred <- predict(model, newdata = SSModel(ts(matrix(NA,6,4), start = 2008) ˜-1 + SSMcustom(Z = model$Z, T = model$T, R = model$R, Q = model$Q), distribution = "poisson"), interval = "prediction", nsim = 10000) out <- KFS(model, nsim = 1000) trend <- exp(signal(out, states = "trend")$signal) death at age 30-39 1970 1980 1990 2000 2010 10 15 20 25 30 35 death at age 40-49 1970 1980 1990 2000 2010 20 40 60 80 death at age 50-59 1970 1980 1990 2000 2010 50 100 150 200 death at age 60-69 1970 1980 1990 2000 2010 50 100 150 Number of alcohol related deaths per 100,000 persons in Finland Year Figure 1: Observed number of alcohol related deaths per 100,000 persons in Finland (blue), smoothed trend (orange), and count predictions for years 2008–2012 together with 95% pre- diction intervals (green). Acknowledgements Author is grateful for the financial support of Emil Aaltonen Foundation.

Upload: others

Post on 25-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: state space models - Jyväskylän yliopistousers.jyu.fi/~jovetale/posters/KFASposter.pdf · non-Gaussian models Exact diffuse initialization of unknown states Multivariate models

Jouni HelskeUniversity of Jyvaskyla, Department of Mathematics and [email protected]

generalizedlinear modelsdynamic

factoranalysis

ARIMA

modelscubicsplines

structural

time series

dynamic

linear

regression

exponentialsmoothing

mixed

modelsgenera

lized

linear m

ixed

models

state space models

multivariate

linear models

Exponential family state space model with p time series:

p∏i=1

pi(yt | Ztαt) pi =

GaussianPoissonBinomialNegative binomialGamma

αt+1 = Ttαt +Rtηt, ηt ∼ N(0, Qt), α1 ∼ N(a1, P1)

Main features of KFAS

•Kalman filtering and smoothing•Simulation smoothing for Gaussian models• Importance sampling and Laplace approximation for

non-Gaussian models•Exact diffuse initialization of unknown states•Multivariate models with different distributions for each series•Maximum likelihood estimation•Prediction intervals•Multiple types of residuals

ReferencesJ. Durbin and S. J. Koopman. Time series analysis by state space methods (Second edition). Oxford

University Press, New York, 2012.J. Helske. KFAS: Exponential family state space models in R. Submitted, 2015.

github.com/helske/KFAS tinyurl.com/KFASvignette tinyurl.com/KFASposter

Alcohol related deaths in Finlandp(yt|θt) = Poisson(uteθt) ut = population at time t

θt = µt + εt, εt ∼ N(0, Qnoise) εt = additional white noiseµt+1 = µt + νt + ξt, ξt ∼ N(0, Qlevel) µt = random walk with driftνt+1 = νt νt = constant slope

Parameter estimation and prediction

alcoholPred <- window(alcohol, start = 1969, end = 2007)# build modelmod <- SSModel(alcoholPred[,1:4] ˜

SSMtrend(2, Q = list(matrix(NA,4,4), diag(0,4))) +SSMcustom(Z = diag(4), T = diag(0,4),

Q = matrix(NA,4,4), P1 = matrix(NA,4,4)),distribution = "poisson", u = alcoholPred[,5:8])

# model updating function for fitSSMupdatefn <- function(pars, model, ...){Q <- diag(exp(pars[1:4])); Q[upper.tri(Q)] <- pars[5:10]model["Q", etas = "level"] <- crossprod(Q)Q <- diag(exp(pars[11:14])); Q[upper.tri(Q)] <- pars[15:20]model["Q", etas = "custom"] <- model["P1", states = "custom"] <-crossprod(Q)

model}model <- fitSSM(mod, updatefn = updatefn, inits = init,

method = "BFGS")$model# predictionpred <- predict(model, newdata =

SSModel(ts(matrix(NA,6,4), start = 2008) ˜ -1+ SSMcustom(Z = model$Z, T = model$T,

R = model$R, Q = model$Q),distribution = "poisson"),interval = "prediction", nsim = 10000)

out <- KFS(model, nsim = 1000)trend <- exp(signal(out, states = "trend")$signal)

death at age 30−39

1970 1980 1990 2000 2010

1015

2025

3035

death at age 40−49

1970 1980 1990 2000 2010

2040

6080

death at age 50−59

1970 1980 1990 2000 2010

5010

015

020

0

death at age 60−69

1970 1980 1990 2000 2010

5010

015

0

Num

ber

of a

lcoh

ol r

elat

ed d

eath

s pe

r 10

0,00

0 pe

rson

s in

Fin

land

Year

Figure 1: Observed number of alcohol related deaths per 100,000 persons in Finland (blue),smoothed trend (orange), and count predictions for years 2008–2012 together with 95% pre-diction intervals (green).

AcknowledgementsAuthor is grateful for the financial support of Emil Aaltonen Foundation.