Project information

Project members



KalmanEM has been replaced by our MARSS R package.  Please go to the MARSS project page (where you'll find the manual).  You can download MARSS from CRAN or directly from the R GUI using "Install packages".  MARSS will appear on the list of available packages.

KalmanEM.R fits mulitvariate state space models to multivariate time series data.

x(t) = B x(t-1) + u + e(t), E~MVN(0,Q)

y(t) = Z x(t) + a + eta(t), eta~MVN(0,R)

What you need to use this code: Download KalmanEM.R (or scroll down to download all the files).  Open R and source("KalmanEM.R").  That's it.  For basic analyses, all the packages you need are included in the base R distribution.

About this code: This code is used to estimate maximum likelihood parameters for multivariate state space time series models via an EM algorithm using the Kalman filter+smoother. We assume that there are N observation time series over T years, and that there may be shared parameters (growth rates, process error, observation error) across sites. Further, the errors may be correlated between sites and the N sites may be clustered into groups. We have a number of online workshops on multivariate state-space models available with case studies and examples for estimating trends, evaluating population structure, estimating interactions, and analyzing movement data: MSSM workshop  The EM algorithm is similar to that in Shumway and Stoffer (1982) but actually was actually motivated by Ghahramani and Hinton (1996). EM is a hill-climbing algorithm and many times the likelihood surface is multi-model. Use KalmanEM(...,MonteCarloInit = TRUE) to turn on searching of the initial condition space. This will deal with the vanilla multi-model problems.

Learning how to use the code: Case Studies.pdf is effectively the current manual. Scripts and data for all the case studies are in the zip file Case studies scripts.zip. The easiest way to learn this code to read case studies 1 and 2 in the Case Studies.pdf. That will walk you through four applications. I have removed Case Study 4 which is on estimation of interactions. Currently we are researching the robustness of estimating interaction terms using MARSS models when the R matrix is free (estimated). One approach is to use a fixed R matrix, but that option is not in the current code. So use caution (meaning test, test, test) if you are using the option B.constraint="unconstrained".

Project news (June 2010):  MARSS 1.0, our R package has been relaased.  You can download from CRAN MARSS or install directly from your R GUI using "Install packages". MARSS will appear on the list of available packages from R. The package is fully documented with help files, a user manual with well-developed examples, and a paper on the derivation behind the EM algorithm.  MARSS 1.0 limits a bit what MARSS models you can fit, but these restrictions will be lifted with MARSS 2.0 which we are coding right now.  MARSS 2.0 uses a more general EM algorithm to allow you to fit any models of the MARSS form above with fixed and shared values arbitrarily distributed throughout the matrices.   See our personal websites for group news on papers and code coming out of this work: EE Holmes website, Eric Ward website, Brice Semmens website, and Mark Scheuerell website.


Kalman-EM /
  • Download Kalman-EM as zip archive Download
Name Status Rev Size Updated Downloads Brief Description Actions
9 23.9 KB 10/08/2009 13:04 PDT 2832 2832 f
The MARSS fitting functions
5 645.1 KB 10/21/2009 14:36 PDT 2715 2715 f
The manual as a series of case studies. You need to download the scripts to go with the case studies.
Case studies scripts.zip
4 51.4 KB 10/21/2009 13:08 PDT 1445 1445 f
R scripts to run the case studies
help files.pdf
1 150.1 KB 01/29/2009 16:34 PST 602 602 f
90% complete; KalmanEM() and bootstrapEMSSM() functions
4 2.6 KB 10/04/2009 13:14 PDT 705 705 f



334 project downloads
8299 individual file downloads

Sculpin 0.2 | xhtml | problems or comments? | report bugs