DESCRIPTION:
Extended Kalman filter for multinomial data with k categories
assuming canonical link and linear Gaussian latent process. The
specific model is
USAGE:
kal.fil.bin.can(ssm)
REQUIRED ARGUMENTS:
 ssm:
 Object of class ssm (state space
model).
The following attributes must be specified in ssm:
 Yt:
 n × k matrix containing the multinomial
observations arranged rowwise.
 nt:
 1 × n vector containing the number of trials
at each timepoint.
Should be nt < apply(Yt,1,sum).
 Ft:
 Function returning a p × (k1) design matrix.
 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 multinomial.
 link:
 Tacitly assumed to have value canonical.
 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 m_{t} given the observations up to
and including time t. These are arranged rowwise in a matrix.
 Ct:
 Posterior variances C_{t} given the
observations up to and including time t. These are arranged in a
3dimensional array such that C_{t} is placed in filtered$Ct[,,t].
 llh:
 Loglikelihood of of the approximating Gaussian
state space model.
 Rt:
 Prior variances for the states arranged in
3dimensional array such that R_{t} 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 multinomial
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 onestep 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:
# Specify a state space model
ss < ssm(Ft = function(i,x,phi)
{t(cbind(1,diag(5)))},
Gt = function(i,x,phi)
{diag(c(0.95,rep(1,5)))},
Wt = function(i,x,phi)
{diag(c(0.1,rep(0.0010,5)))},
m0 = c(0,0.2,0.1,0,0.1,0.2),
C0 = diag(10,6),
nt = rep(20,50),
fam = "multinomial",
link = "canonical")
# Simulate observations
ss <simulate.ssm(ss, n=50)
# Apply the extended Kalman filter
ss < kal.fil.mul.can(ss)
# Extract category probabilities (i=1,...,5)
# response function
h < function(lambda) exp(lambda)/(1+sum(exp(lambda)))
props < t(apply(ss$filtered$mt[,2:6]
+ss$filtered$mt[,1],1,h))
sim.props < t(apply(ss$simulated$lambda,1,h))
# Plot the simulated and filtered signal
# on the probability scale one at a time
for (i in 1:5)
{
plot(props[,i] , ylim=c(0,0.6), type="l")
lines(sim.props[,i],lty=2)
legend(0,0.6,
legend=c("Filtered signals on probability scale",
"Simulated signals on probability scale"),
lty=c(1,2))
title(paste("Results from kal.fil.mul.can,
signal component",i))
}
