This archive contains Matlab functions and scripts for fitting state-space models with trends and change points to time series data, as described in Spencer et al, in preparation.

All the models fitted here are univariate, linear, Gaussian state-space models.

REQUIREMENTS

Matlab, with the Optimization and Statistics Toolboxes.

Tested with Matlab Version 7.9.0.529 (R2009b), Optimization Toolbox Version 4.3, Statistics Toolbox Version 7.2, operating system Linux 2.6.26-2-686.

EXAMPLE

Run example_script.m to do the following:

-generate and plot a simulated data set. This one has trend, step change, and change in trend. The change point is shown as the vertical dashed line

-fit all the models described in the manuscript

-draw a model selection plot

-produce diagnostic plots for the selected model

Expect this to take a couple of minutes to run. Note that the number of parametric bootstrap replicates is set to 9, for demonstration only (you need a much larger number in practice).

To analyze your own data, edit example_script.m to read in data from a file instead of simulating. Increase the number of parametric bootstrap replicates (reps, set on line 12 of example_script.m) to a sensible value (e.g. 999). You might want to add code to save intermediate results, as this will take a long time to run.

FUNCTIONS

From Matlab, type help [name of function] for detailed help on usage.

ACF.m                                  
sample autocorrelation function

kalman_diffuse2.m                      
univariate Kalman filter

kalman_diffuse_backparms2.m            
back-transform parameters for kalman_diffuse2

kalman_diffuse_est2.m                  
maximum likelihood estimation using Kalman filter

kalman_diffuse_shiftgeneral_bootone.m  
fit two state-space models and compare using parametric bootstrap

kalman_diffuse_shiftgeneral.m          
estimate location of change point in a state-space model			       
kalmanPCdiagnostics.m	     	       
diagnostic plots for state-space model

plotselectstatespace.m	     	       
plot model selection hierarchy

selectstatespace.m	     	       
select model given parametric bootstrap results

univariate_sim.m		       
generate simulated data from state-space model

Xfromv.m                      	       
generate explanatory variables for state-space model, possibly with change point

LICENSE

 This file is part of rsstatespace.

    rsstatespace is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    stochmap is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with rsstatespace.  If not, see <http://www.gnu.org/licenses/>.

See gpl-3.0.txt for full information.
