by eric.ward, last updated 2/22/09, sharing set to public
Before you begin with this code, make sure you download the latest release of OpenBUGS(now 3.0.3) and it is installed to the default directory, "C:\Program Files\OpenBUGS". We've also found that it helps to have a cleaned up registry + defregmented hard drive before using OpenBUGS. The version of R that you're using should also be noted - R 2.5.1 and 2.7.0 work great with OpenBUGS, but there was a glitch in R 2.6.0 that prevented OpenBUGS from ever running through R. When using BUGS, I think that you can obviously use WinBUGS or OpenBUGS. While both programs should yield the same result, I had much more success with OpenBUGS, particularly in terms of the program not crashing during the burn-in (anyone familiar with 'trap' error messages knows what I'm talking about). There are 2 project files. The first (writeModel.r) is sourced by the second file (runDataCloning2.r). If you want to modify the bounds on parameters, you'll need to edit writeModel.r - otherwise, everything will be done behind the scenes. I've tried to predict many of the errors that might occur - for example, it doesn't make sense to have all sites belonging to the same group (m = 1) and an unconstrained covariance matrix. These files won't automate every possible MSSM that you want to fit, but they will do the majority of them. The R script files actually write the BUGS code for you, so you don't have to know any BUGS coding. You should however, be aware of the priors. Uniform priors are used on SDs and growth rates - to change these, look anywhere in the file for (~ dunif(a,b), where a and b are the limits). The code also includes the option of including an interaction matrix (multiple species) or density dependence matrix (multiple populations). The priors for all of these terms are bounded (0,1). Included are several examples of summarizing parameters, including the median, mean, and using density to estimate the mode. The actual MLEs are going to be the points associated with the best (lowest) density.
by e2holmes, last updated 10/21/09, sharing set to public
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.
LAMBDA is a MatLab toolkit designed to do MAR-1 based data analysis on long-term datasets and is based on the methods described in Ives et al. 2003, Ecological Monographs 73:301-330. LAMBDA is designed to allow the user to step through the entire modeling process, from importing the data, to obtaining descriptive statistics of the dataset, to, finally, performing a MAR-1 regression model and obtaining output parameters. A MAR-1 process is a Multivariate, Auto-Regressive first (1st) order process. Essentially, it is a means of estimating interactions between multiple variates from time series data, using matrix algebra. A MAR-1 model is a stochastic, non-mechanistic model that uses time series data on species numbers and co-variates to deduce inter-population interactions and the effects of covariates (e.g., physical variables) on populations.
How to get started? Download the executable file (next line) and follow the instructions in the "LAMBDA installation instructions.pdf" which you download below.
Download the LAMBDA executable (Windows): LAMBDA_MCR_pkg.exe Warning: This is a 138 MB file!
Installation Instructions: See the pdf below which details installation. The executable version of LAMBDA does not require MatLab. Its system requirements are Windows XP/2000, 256 MB of RAM, and 150 MB of Hard Drive Space. Mac and unix users (and Windows users if they wish) can run LAMBDA through Matlab using the source code, which is provided in a zip file below.
LAMBDA is a product of the Mathematical Biology program at the Northwest Fisheries Science Center in Seattle, WA, and was developed with support by NOAA/NMFS and the National Research Council. It is open-source software released under the GNU GPL license, meaning you are free to use and modify it in (almost) any way you see fit. LAMBDA was developed by Steven Viscido while on a National Research Council postdoctoral associateship with Elizabeth Holmes. LAMBDA is based on the techniques outlined in the paper Ives et al. 2003, Ecological Monographs 73:301-330. The code for the actual MAR-1 regression was based on the "MARbasic.m" MatLab script written by Tony Ives (available at the Ecological Archives). The parameter search code was based on an unpublished script written by Tony Ives. All other code was written by Steven Viscido.
If Installation hangs This is a bug on MatLab's side. To work around it, you will need to install vcredist_x86.exe (32 bit systems) or vcredist_x64.exe (64 bit system) first (given below) and then repeat the LAMBDA installation. But read the If_Installation_Hangs.txt readme file if this happens to you. This bug affects about 20% of computers, randomly it would seem.
Matlab Source Code This is not needed if you are using the executable version. Current source code version is LAMBDA_0.9.2Beta.zip. The source code can be downloaded below. Requirements for running LAMBDA from the source code are
- MatLab version 7.0.1 (R14) w/service Pack 1, or later
- MatLab's Statistics and Optimization toolboxes
- At least 256 MB of RAM on your system
- 5 MB of Hard Drive space for the LAMBDA installation
by e2holmes, last updated 8/3/10, sharing set to public
Please download the current release of MARSS from CRAN. The current User Guide can be found there also.
A MARSS model is a multivariate auto-regressive time-series model of the form:
x(t) = B x(t-1) + u + v(t), v(t)~MVN(0,Q)
y(t) = Z x(t) + a + w(t), w(t)~MVN(0,R)
where all elements of these equations are matrices as this is a multivariate auto-regressive model.
What you need to use this code: MARSS is an R package, thus you need to install R from CRAN in order to use the package Once you have R installed, then install the MARSS package using the standard R package instructions (if you are using an R GUI, then you use the "Install Packages" menu.) If you have never done this, see the instructions on CRAN.
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 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: WORKSHOPS Our EM algorithm is similar to that in Shumway and Stoffer (1982) but actually was inspired by Ghahramani and Hinton (1996). Most other software uses the BFGS algorithm (a quasi-Newton method) for maximization, which often works great but for some models needs a bit of fiddling to get it to work (not throw numerical errors). Some researchers will use the EM algorithm to "get close" and then polish off with the BFGS algorithm. MARSS includes functions for bootstrapping (parametric and innovations), model selection (AIC, AICc, and bootstrap bias-corrected AICb), confidence intervals (approximate via Hessian, parametric bootstrap, and innovations bootstrap), parameter bias estimation (via bootstrapping), simulation, and initial condition searching. MARSS was developed by Eli Holmes, Eric Ward, and Kellie Wills.
See what is coming in the next MARSS version: This is our development site MARSS development site
Learning how to use the code: The user manual gives detailed examples. Scripts and data for all the case studies are included in the package. Our online workshops at EE Holmes' website include pdfs of our lectures.