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

DESCRIPTION:

Conjugated Kalman filter for Poisson data assuming log link and partially specified linear latent process. The conjugated prior on the mean parameter is gamma. The specific model is
Observation equation:
(yt | ht)
~
Po(mt),
Signal:
lt
=
FtTqt,
System equation:
qt
=
Gtqt-1 + wt,
    wt
~
[0,Wt],
Initial prior:
q0
~
[m0,C0].

USAGE:

      ckal.fil.po.gam.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:
Not used in the conjugate filter.

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].
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.
The returned object can the be given as argument to the Kalman smoother.

SIDE EFFECTS:

None

DETAILS:

This is the conjugate filter introduced for the class of dynamic generalized linear models by West, Harrison and Migon (1985). Instead of approximating the observational model with a Gaussian one like in the extended Kalman filter, the latent process guides the choice of the conjugate prior on the natural parameter.

REFERENCES:

Klein, (2003), State Space Models for Exponential Family Data, Ph.D. Thesis, Department of Statistics, University of Southern Denmark.
West & Harrison, (1997), Bayesian Forecasting and Dynamic Models, Springer Series in Statistics.
West, Harrison & Migon, (1985),Dynamic Generalized Linear Models and Bayesian Forecasting (with discussion), Journal of the American Statistical association, 80, 73-97.

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 the conjugated filter
van.ss <- ckal.fil.po.gam.log(van.ss)

# Apply the Kalman smoother
van.ss <- kalman.smoother(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)