Welcome State space notation Functions > kal.fil.po.log
Last update Jul 10, 2004

DESCRIPTION:

Extended Kalman filter for Poisson data assuming log link and linear Gaussian latent process. The specific model is
Observation equation:
(yt | ht)
~
Po(mt),
Link function:
log(mt)
=
FtTqt,
System equation:
qt
=
Gtqt-1 + wt,
    wt
~
Np(0,Wt),
Initial prior:
q0
~
Np(m0,C0).

USAGE:

      kal.fil.po.log(ssm)

REQUIRED ARGUMENTS:

ssm:
Object of class ssm (state space model).
The following attributes must be specified in ssm:
Yt:
1 × n vector containing the Poisson observations.
Ft:
Function returning a p × 1 design vector.
Gt:
Function returning a p × p evolution transfer matrix.
Wt:
Function returning a p × p evolution variance matrix.
m0:
p × 1 vector (prior mean).
C0:
p × p matrix (prior variance).

OPTIONAL ARGUMENTS:

The following attributes of the ssm object might be needed:
Xt:
Matrix containing the covariates needed in Ft, Gt and/or Wt. This matrix must have n rows, such that row t contains the covariates needed for generating the system matrices at time t.
psi:
Parameter vector must be supplied if it is needed in the calculation of the system matrices.
The following attributes of the ssm object are optional:
fam:
Tacitly assumed to have value Poisson.
link:
Tacitly assumed to have value log.
m.start:
Used to specify the Taylor expansion points. These are not meant to be set by the user. Applying the Kalman smoother on a ssm object that has been filtered will set the m.start attribute to the smoothed states. This is needed in the iterated extended Kalman filter and smoother.

VALUE:

Returns an object of class ssm with the same attributes as the object in the call, but with attribute filtered updated with:
mt:
Posterior means mt given the observations up to and including time t. These are arranged row-wise in a matrix.
Ct:
Posterior variances Ct given the observations up to and including time t. These are arranged in a 3-dimensional array such that Ct is placed in filtered$Ct[,,t].
llh:
Log-likelihood of of the approximating Gaussian state space model.
Rt:
Prior variances for the states arranged in 3-dimensional array such that Rt is placed in filtered$Rt[,,t]. The reason for returning these is that they are needed in the Kalman smoother.

SIDE EFFECTS:

None

DETAILS:

The filter works by sequentially approximating the Poisson observation density with a Gaussian density based on a Taylor expansion around the values supplied in the attribute m.start of the ssm object. If m.start is not supplied, the Taylor expansion will be around the one-step forecast mean of the observation.

REFERENCES:

Durbin & Koopman, (2002), Time Series Analysis by State Space Models, Oxford Statistical Science Series.
Fahrmeir & Tutz, (1994), Multivariate Statistical Modelling Based on Generalized Linear Models, Springer Series in Statistics.
Klein, (2003), State Space Models for Exponential Family Data, Ph.D. Thesis, Department of Statistics, University of Southern Denmark.

EXAMPLES:


# Organize the data from the data frame vandrivers
death <- vandrivers[,1]
indi  <- matrix(vandrivers[,2],ncol=1)

# Design vector
Ft <- function(i,Xt,phi) c(1,1, rep(0,10), Xt[1])

# Evolution transfer matrix
Gt <- function(i, Xt, phi)
{
  trend <- c(1, rep(0,12))
  season <- cbind(0,rbind(rep(-1,11), cbind(diag(rep(1,10)),0)),0)
  seat <- c(rep(0,12),1)
  result <- rbind(trend,season,seat)
  result
}

# Evolution variance matrix
Wt <- function(i,Xt,phi)
{
  result <- matrix(0,nrow=13,ncol=13)
  result[1,1] <- phi
  result
}

# Initial prior parameterss
C0 <- 1000*diag(rep(1,13))
m0 <- rep(0,13)

# Specify state space model
van.ss <- ssm(Ft=Ft, 
              Gt=Gt,
              Wt=Wt,
              Xt=indi, 
              phi=0.0245^2,
              m0=m0,
              C0=C0,
              Yt=death,
              fam="Poisson",
              link="log",
              m.start=NA)

# Apply extended Kalman filter
van.ss.fil <- kal.fil.po.log(van.ss)

# Apply the iterated extended Kalman filter and smoother
van.ss <- ieks(van.ss)

# Sum trend and effect of seat belt legislation
FFt <- function(i,Xt,phi)       c(1, rep(0,11), Xt[1])

tmp <- matrix(NA, nrow=192, ncol=2)
for (i in 1:192)
{
        FF <- FFt(i,indi[i,],phi)
        tmp[i,1] <- FF%*%van.ss$smoothed$m.tilde[i,]
        tmp[i,2] <- t(FF)%*%van.ss$smoothed$C.tilde[,,i]%*%(FF)
}

# PRODUCE PLOT (like Figure 2.6)
plot(exp(tmp[,1]), ylim=c(0,20), lty=1, type="l")
lines(exp(tmp[,1]+2*sqrt(tmp[,2])), lty=3)
lines(exp(tmp[,1]-2*sqrt(tmp[,2])), lty=3)