Fkfilter: Kalman filtering of Gaussian state space model using'KFS'

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

Description

Does Kalman filtering using KFS.

Usage

1
Fkfilter(ss, tvar)

Arguments

ss

object of class SS.

tvar

vector with four elements indicating the dynamic nature of matrices in the object SS. The first element corresponds to ss$Fmat, the second to ss$Gmat, the third to ss$Vmat and the fourth to ss$Wmat. If tvar[i]==1 the corresponding matrix is constant, otherwise tvar[i] is set to ss$n.

Details

The Kalman filter implemented in KFAS provides faster computations than kfilter, however requires alternative specification of the state space model. This function transform an object of class SS into an object on which the filter implemented in KFAS may be applied.

Value

List with two objects. An object kfas with components as specified in KFS, as well as the input object ss with updated m, C and loglik.

Author(s)

Anette Luther Christensen and Claus Dethlefsen.

See Also

Fkfs

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
## Formulates Gaussian state space model:
## Trend: local linear
## Seasonal variation: sine function with frequency = 1
m1 <- SS( Fmat = function(tt, x, phi) {
            Fmat      <- matrix(NA, nrow=3, ncol=1)
            Fmat[1,1] <- 1
            Fmat[2,1] <- cos(2*pi*tt/12)
            Fmat[3,1] <- sin(2*pi*tt/12)
            return(Fmat)
          },
          Gmat = function(tt, x, phi) {
            matrix(c(1,0,0,0,1,0,0,0,1), nrow=3)
          },
          Wmat = function(tt, x, phi) {matrix(c(0.01,0,0,0,0.1,0,0,0,0.1), nrow=3)},
          Vmat = function(tt, x, phi) {matrix(1)},
          m0   = matrix(c(0,0,0), nrow=1),
          C0   = matrix(c(1,0,0,0,0.001,0,0,0,0.001), nrow=3, ncol=3)
        )

## Simulates 100 observation from m1
m1 <- recursion(m1, 100)

#filtered <- Fkfilter(m1, tvar=c(m1$n, 1, 1, 1))
filtered <- kfilter(m1)

#plot(filtered$ss)

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