kfs: (Iterated extended) Kalman smoother

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

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

1
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 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

 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
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)

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