SS {sspir} | R Documentation |
Creates an SS-object describing a Gaussian state space model.
SS(y = NA, 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 method for class 'SS': C0(ssm) <- value ## S3 method for class 'SS': m0(ssm) <- value ## S3 method for class 'SS': Fmat(ssm) <- value ## S3 method for class 'SS': Gmat(ssm) <- value ## S3 method for class 'SS': Vmat(ssm) <- value ## S3 method for class 'SS': Wmat(ssm) <- value ## S3 method for class 'SS': phi(ssm) <- value
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 . |
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 . |
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. |
The state space model is given by
Y_t = F_t^T * theta_t + v_t, v_t ~ N(0,V_t)
theta_t = G_t * theta_{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 phi. The initialization is given as
theta_0 ~ N(m_0,C_0).
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 theta_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. |
Claus Dethlefsen and Søren Lundbye-Christensen
ssm
for a glm-like interface of specifying
models, kfilter
for Kalman filter and
smoother
for Kalman smoother.
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)), Vmat=function(tt,x,phi) return(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] )