kfs {sspir}R Documentation

(Iterated extended) Kalman smoother

Description

Runs the Kalman smoother on an ssm object if the family-attribute of the object is gaussian. If not, the iterated extended Kalman smoother is used.

Usage

kfs(ss, ...)

Arguments

ss an object of class ssm.
... further arguments passed to the Kalman smoother.

Details

The function is a wrapper for kfilter followed by smoother in the Gaussian case. For other family types, extended is called. The kfs function is called by default in the call to ssm unless the option \code{fit=FALSE} is given.

Value

The returned value from either smoother (Gaussian case) or extended.

Author(s)

Claus Dethlefsen and Søren Lundbye-Christensen.

See Also

kfilter, smoother, extended, ssm.

Examples

data(mumps)
index <- 1:length(mumps)
phi.start <- c(0,0,0.0005,0.0001)
m3 <- ssm( mumps ~ -1 + tvar(polytime(index,1)) +
                  tvar(polytrig(index,12,1)),
                  family=poisson(link=log),
                  phi=phi.start, C0 = diag(4),
                  fit=FALSE
) 

## The option "fit=FALSE" means that the Kalman Filter/Smoother is not
## run.
## At this point you may inspect/change the setup before running 'kfs'
C0(m3)
C0(m3) <- 10*diag(4)
## incorporate possible structural 'jump' at timepoint 10
Wold <- Wmat(m3)
Wmat(m3) <- function(tt,x,phi) {
    W <- Wold(tt,x,phi)
    if (tt==10) {W[2,2] <- 100*W[2,2]; return(W)}
    else return(W)
}

m3.fit <- kfs(m3)

plot(mumps,type='l',ylab='Number of Cases',xlab='')
lines(exp(m3.fit$m[,1]),type='l',lwd=2)

[Package sspir version 0.2.3 Index]