Projects for R: |
1-5 of
5
shown.
|
|
-
Bayesian SI mixing models
by eric.ward, last updated 11/20/09, sharing set to public
This project is a variation of stable isotope mixing models. Previous approaches have fixed source parameters (mean, variance) at their MLE estimates, and proceeded to do a Bayesian analysis of the mixture of consumer diets. This assumption is fine when sample sizes are large, but often in ecology, they are small. Incorporating this uncertainty adds additional parameters, and slightly increases the total variance of mixture estimates, but has the advantage of improving mixing and reducing bias. Often, using the traditional approach may lead to multi-modal estimates of the mixture; we demonstrate that the fully Bayesian mixing model avoids this problem. A final benefit is that it allows prior information about sources to be included. The code folder contains the code to replicate the comparison done with simulated datasets. -
Kalman-EM
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.
-
MARSS
by e2holmes, last updated 2/18/11, sharing set to public
Download the current release of MARSS 1.1 from CRAN. This project page is where we are posting code for MARSS 1.2 (bug fixes) before uploading to CRAN.
MARSS is an R package which fits mulitvariate state-space models to multivariate time-series data.
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.
Learning how to use the code: The user manual is given below. Scripts and data for all the case studies are included in the package (see the manual for instructions). The online workshop includes pdfs of our lectures.
Project news: March 10, 2011, A version of MARSS 2.0 is ready for public testing. Download MARSS 2.0. Mar 1, 2011, Testing of MARSS 2.0 is going well. I'm finishing up a dynamic factor analysis example to show Z estimation. Feb 16, 2011, Uploaded new Derivations.pdf that deals with 0s on R and Q matrices and uses a more elegant approach to missing values. Oct 2010, Coding of MARSS 2.0 is now 95% done (all algorithms coded and testing in progress).
See our personal websites for group news on papers coming out of this work: EE Holmes website, Eric Ward website, Brice Semmens website, and Mark Scheuerell website. (download stats from CRAN)
Bugs and issues fixed in 1.1: See Changes.pdf in MARSS/inst/doc folder. Issues being fixed in 2.0: adding algorithm for fully constrained estimation for all parameters (per algorithm in Derivations.pdf).
-
MixBUGS
by eric.ward, last updated 9/24/08, sharing set to public
This project includes the WinBUGS files illustrating how to include model selection in MCMC. Variances are modeled as a mixture of source/fractionation and additional residual variance. We include to variations on the MixBUGS model, 1 without residual variance, and 1 modeling variance as a mixture (to calculate posterior probabilities). We also include the R-script illustrating that the SIAR package likely contains a bug (even when data are generated from a 0.7-0.2-0.1 mixture, estimated contributions are nearly equal). -
Salmonid verebrae identification
by jorg, last updated 4/19/11, sharing set to public
The following files contain the R fitted model objects that have been developed to identify salmonid vertebrae to the species level using vertebral morphology, and a brief explanation about how to identify new specimen data. The models are from the paper:
Huber, H.R., Jorgensen, J.C., Butler, V.L., Baker, G., and Stevens, R. 2011. Can salmonids (Oncorhynchus spp.) be identified to species using vertebral morphometrics? Journal of Archaeological Science 38:136-146. doi:10.1016/j.jas.2010.08.020 [http://dx.doi.org/10.1016/j.jas.2010.08.020; a pdf of the pre-publication version is with the files below.]
We are actively researching in this area, inquire with me (jeff dot jorgensen at noaa dot gov) for details. If you check back periodically, you may notice occasional updates.
Projects for R: |
1-5 of
5
shown.
|
|