SS: Representation of Gaussian State Space Model

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Creates an SS-object describing a Gaussian state space model.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
SS(y = NA, x = list(x = NA),
   Fmat = function(tt,x,phi) { return(matrix(1)) },
   Gmat = function(tt,x,phi) { return(matrix(1)) },
   Vmat = function(tt,x,phi) { return(matrix(phi[1])) },
   Wmat = function(tt,x,phi) { return(matrix(phi[2])) },
   m0 = matrix(0),
   C0 = matrix(100),
   phi = c(1,1))

## S3 method for class 'SS'
C0(ssm) 
## S3 method for class 'SS'
m0(ssm) 
## S3 method for class 'SS'
Fmat(ssm)
## S3 method for class 'SS'
Gmat(ssm)
## S3 method for class 'SS'
Vmat(ssm)
## S3 method for class 'SS'
Wmat(ssm)
## S3 method for class 'SS'
phi(ssm) 
## S3 replacement method for class 'SS'
C0(ssm) <- value
## S3 replacement method for class 'SS'
m0(ssm) <- value
## S3 replacement method for class 'SS'
Fmat(ssm) <- value
## S3 replacement method for class 'SS'
Gmat(ssm) <- value
## S3 replacement method for class 'SS'
Vmat(ssm) <- value
## S3 replacement method for class 'SS'
Wmat(ssm) <- value
## S3 replacement method for class 'SS'
phi(ssm) <- value

Arguments

y

a matrix giving a multivariate time series of observations. The observation at time tt is y[tt,]. The dimension of y is n \times d. Preferably, y is a ts object.

x

a list of entities (eg. covariates) passed as argument to the functions Fmat, Gmat, Vmat, and Wmat.

Fmat

a function depending on the parameter-vector phi, covariates x and returns the p \times d design matrix at time tt.

Gmat

a function depending on the parameter-vector phi, covariates x and returns the p \times p evolution matrix at time tt.

Vmat

a function depending on the parameter-vector phi, covariates x and returns the d \times d (positive definit) variance matrix at time tt. The matrix Vmat may be specified as a constant matrix not depending on phi coded with matrix.

Wmat

a function depending on the parameter-vector phi, covariates x and returns the p \times p (positive semidefinite) evolution variance matrix at time tt. The matrix Wmat may be specified as a constant matrix not depending on phi coded with matrix.

m0

a 1 \times p matrix giving the initial state.

C0

a p \times p variance matrix giving the variance matrix of the initial state.

phi

a (hyper) parameter vector passed as argument to the functions Fmat, Gmat, Vmat, and Wmat.

ssm

an object of class SS.

value

an object to be assigned to the element of the state space model.

Details

The state space model is given by

Y_t = F_t^T * θ_t + v_t, v_t ~ N(0,V_t)

θ_t = G_t * θ_{t-1} + w_t, w_t ~ N(0,W_t)

for t=1,...,n. The matrices F_t, G_t, V_t, and W_t may depend on a parameter vector φ. The initialization is given as

θ_0 ~ N(m_0,C_0).

Value

An object of class SS, which is a list with the following components

y

as input.

x

as input.

Fmat

as input.

Gmat

as input.

Vmat

as input.

Wmat

as input.

m0

as input.

C0

as input.

phi

as input.

n

the number of time points

d

the dimension of each observation.

p

the dimension of the state vector at each timepoint.

ytilde

adjusted observations for use in the extended Kalman filter, see extended.

iteration

an integer giving the number of iterations used in the extended Kalman filter, see extended.

m

after Kalman filtering (or smoothing), holds the conditional mean of the state vectors given the observations up till time t (filtering) or all observations (smoothing). This is organised in a n \times p dimensional matrix holding m_t (m_t^*) in rows. Is returned as a ts object.

C

after Kalman filtering (or smoothing), holds the conditional variance of the state vectors given the observations up til time t (filtering) or all observations (smoothing). This is organised in a list holding the p \times p dimensional matrices C_t (C_t^*).

mu

after Kalman smoothing, holds the conditional mean of the signal (μ_t=F_t^\top θ_t) given all observations. This is organised in a n \times d dimensional matrix holding μ_t in rows.

loglik

the log-likelihood value after Kalman filtering.

Author(s)

Claus Dethlefsen, Søren Lundbye-Christensen and Anette Luther Christensen

See Also

ssm for a glm-like interface of specifying models, kfilter for Kalman filter and smoother for Kalman smoother.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
data(kurit)  ## West & Harrison, page 40
m1 <- SS(y=kurit,
         Fmat=function(tt,x,phi) return(matrix(1)),
         Gmat=function(tt,x,phi) return(matrix(1)),
         Wmat=function(tt,x,phi) return(matrix(5)), ## Alternatively Wmat=matrix(5)
         Vmat=function(tt,x,phi) return(matrix(100)), ## Alternatively Vmat=matrix(100)
         m0=matrix(130),C0=matrix(400)
         )

plot(m1$y)
m1.f <- kfilter(m1)
m1.s <- smoother(m1.f)
lines(m1.f$m,lty=2,col=2)
lines(m1.s$m,lty=2,col=2)

## make a model with an intervention at time 10
m2 <- m1
Wmat(m2) <- function(tt,x,phi) {
  if (tt==10) return(matrix(900))
  else return(matrix(5))
}

m2.f <- kfilter(m2)
m2.s <- smoother(m2.f)
lines(m2.f$m,lty=2,col=4)
lines(m2.s$m,lty=2,col=4)

## Use 'ssm' to construct an SS skeleton
phi.start <- StructTS(log10(UKgas),type="BSM")$coef[c(4,1,2,3)]
gasmodel <- ssm( log10(UKgas) ~ -1+
                 tvar(polytime(time,1))+
                 tvar(sumseason(time,12)),
                 phi=phi.start)

m0(gasmodel)
C0(gasmodel)
phi(gasmodel)

fit <- getFit(gasmodel)
plot( fit$m[,1:3]  )

ClausDethlefsen/sspir documentation built on May 6, 2019, 7 p.m.