├── docs ├── README.txt ├── ex │ ├── dlmdemo1.png │ ├── dlmdemo2.png │ ├── dlmdemo3.png │ ├── niledemo.png │ ├── dlmdemo1_01.png │ ├── dlmdemo1_02.png │ ├── dlmdemo1_03.png │ ├── dlmdemo1_04.png │ ├── dlmdemo1_05.png │ ├── dlmdemo2_01.png │ ├── dlmdemo2_02.png │ ├── dlmdemo2_03.png │ ├── dlmdemo2_04.png │ ├── dlmdemo3_01.png │ ├── niledemo_01.png │ ├── niledemo_02.png │ ├── ozonedemo.png │ ├── ozonedemo_01.png │ ├── ozonedemo_02.png │ ├── ozonedemo_03.png │ ├── ozonedemo_04.png │ ├── ozonedemo_05.png │ ├── niledemo.html │ ├── dlmdemo3.html │ ├── dlmdemo2.html │ ├── ozonedemo.html │ └── dlmdemo1.html ├── img │ ├── ozonedemo1.png │ ├── ozonedemo2.png │ ├── ozonedemo3.png │ ├── ozonedemo4.png │ ├── ozonedemo5.png │ ├── ozonedemo1c.png │ ├── ozonedemo2c.png │ ├── seasonaldemo.png │ ├── splinedemo_diag.png │ ├── splinedemofit.png │ └── splinedemofit2.png ├── style.css ├── index.org ├── index.html └── mxdom2simplehtml.xsl ├── examples ├── kaisaniemi.mat ├── ozonedata.mat ├── puboptions.m ├── dlmdemo2.m ├── niledemo.m ├── dlmdemo3.m ├── ozonedemo.m ├── dlmdemo1.m └── ozonedata.dat ├── .gitignore ├── acfnan.m ├── armasys.m ├── armalik.m ├── dlmqqplot.m ├── mvnorrnan.m ├── dlmplotdiag.m ├── README.org ├── dlmacfplot.m ├── dlmplot.m ├── dlmplotcomp.m ├── dlmplotresid.m ├── LICENSE.txt ├── dlmdisp.m ├── dlmsmosam.m ├── dlmgensys.m ├── dlmplotfit.m ├── dlmtsfit.m ├── dlmsmo.m └── dlmfit.m /docs/README.txt: -------------------------------------------------------------------------------- 1 | documentation in this directory 2 | -------------------------------------------------------------------------------- /docs/ex/dlmdemo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo1.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo2.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo3.png -------------------------------------------------------------------------------- /docs/ex/niledemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/niledemo.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo1_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo1_01.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo1_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo1_02.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo1_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo1_03.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo1_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo1_04.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo1_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo1_05.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo2_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo2_01.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo2_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo2_02.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo2_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo2_03.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo2_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo2_04.png -------------------------------------------------------------------------------- /docs/ex/dlmdemo3_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/dlmdemo3_01.png -------------------------------------------------------------------------------- /docs/ex/niledemo_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/niledemo_01.png -------------------------------------------------------------------------------- /docs/ex/niledemo_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/niledemo_02.png -------------------------------------------------------------------------------- /docs/ex/ozonedemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/ozonedemo.png -------------------------------------------------------------------------------- /docs/img/ozonedemo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo1.png -------------------------------------------------------------------------------- /docs/img/ozonedemo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo2.png -------------------------------------------------------------------------------- /docs/img/ozonedemo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo3.png -------------------------------------------------------------------------------- /docs/img/ozonedemo4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo4.png -------------------------------------------------------------------------------- /docs/img/ozonedemo5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo5.png -------------------------------------------------------------------------------- /examples/kaisaniemi.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/examples/kaisaniemi.mat -------------------------------------------------------------------------------- /examples/ozonedata.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/examples/ozonedata.mat -------------------------------------------------------------------------------- /docs/ex/ozonedemo_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/ozonedemo_01.png -------------------------------------------------------------------------------- /docs/ex/ozonedemo_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/ozonedemo_02.png -------------------------------------------------------------------------------- /docs/ex/ozonedemo_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/ozonedemo_03.png -------------------------------------------------------------------------------- /docs/ex/ozonedemo_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/ozonedemo_04.png -------------------------------------------------------------------------------- /docs/ex/ozonedemo_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/ex/ozonedemo_05.png -------------------------------------------------------------------------------- /docs/img/ozonedemo1c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo1c.png -------------------------------------------------------------------------------- /docs/img/ozonedemo2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/ozonedemo2c.png -------------------------------------------------------------------------------- /docs/img/seasonaldemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/seasonaldemo.png -------------------------------------------------------------------------------- /docs/img/splinedemo_diag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/splinedemo_diag.png -------------------------------------------------------------------------------- /docs/img/splinedemofit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/splinedemofit.png -------------------------------------------------------------------------------- /docs/img/splinedemofit2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjlaine/dlm/HEAD/docs/img/splinedemofit2.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .DS_Store 3 | .directory 4 | .nfs* 5 | .koivikko_dir 6 | .rsync_exclude* 7 | CVS/ 8 | *.exe 9 | *.lo 10 | *.dylib 11 | *.Po 12 | *.Plo 13 | *.la 14 | *.mod 15 | *.zip 16 | *.a 17 | *.o 18 | *.obj 19 | *.so 20 | *.dll 21 | *.mex* 22 | *.dSYM 23 | -------------------------------------------------------------------------------- /examples/puboptions.m: -------------------------------------------------------------------------------- 1 | % publish options 2 | popts = struct(); 3 | popts.format = 'html'; 4 | popts.outputDir = '../docs/ex/'; 5 | popts.imageFormat = 'png'; 6 | popts.stylesheet = '../docs/mxdom2simplehtml.xsl'; 7 | 8 | popts2 = popts; 9 | popts2.evalCode = false; 10 | 11 | pub = @(file) publish(file,popts); 12 | pub2 = @(file) publish(file,popts2); 13 | 14 | -------------------------------------------------------------------------------- /acfnan.m: -------------------------------------------------------------------------------- 1 | function y=acfnan(x,lagmax) 2 | %ACFNAN Autocorrelation function 3 | % ACF(X,maxlag) 4 | % default maxlag is floor(10*log10(length(x))) 5 | 6 | x = x(:)-meannan(x); 7 | n = length(x); 8 | if nargin<2 9 | lagmax = floor(10*log10(n)); 10 | lagmax = min(lagmax, n-1); 11 | end 12 | 13 | y = zeros(lagmax,1); 14 | 15 | for i=1:lagmax 16 | y(i) = sumnan(x(1:end-i+1).*x(i:end)); 17 | end 18 | 19 | y = y./y(1); 20 | -------------------------------------------------------------------------------- /armasys.m: -------------------------------------------------------------------------------- 1 | function [G,F,W,C0] = armasys(phi,th) 2 | %ARMASYS generate state space representation of ARMA model 3 | % [G,F,W,C0] = armasys(phi,theta) 4 | 5 | % Marko Laine 6 | % $Revision: 0.0 $ $Date: 2014/12/28 $ 7 | 8 | p = length(phi); 9 | q = length(th); 10 | pq = max(p,q+1); 11 | G = [[phi(:);zeros(pq-p,1)],[eye(pq-1);zeros(1,pq-1)]]; 12 | F = [1 zeros(1,pq-1)]; 13 | R = [1;th(:);zeros(pq-q-1,1)]; 14 | W = R*R'; 15 | 16 | % C0, initial state covariance 17 | if nargout>3 18 | C0 = reshape((eye(pq^2)-kron(G,G))\W(:),pq,pq); 19 | end 20 | -------------------------------------------------------------------------------- /armalik.m: -------------------------------------------------------------------------------- 1 | function lik = armalik(y,phi,th,s) 2 | %ARMALIK -2*log(likelihood) of ARMA(p,q) model 3 | % lik = armalik(phi,theta,sig) 4 | % phi, AR coefficients 5 | % theta, MA coefficients 6 | % sig, innovation standard deviation 7 | 8 | % Marko Laine 9 | % $Revision: 0.0 $ $Date: 2014/12/28 $ 10 | 11 | [G,F,W,C0]=armasys(phi,th); 12 | V = zeros(size(y)); 13 | x0 = zeros(size(G,2),1); 14 | 15 | if exist('dlmmex') == 3 16 | % mex boosted likelihood calculations 17 | lik = dlmmex(y,F,V,x0,G,W*s^2,C0*s^2,[]); 18 | else 19 | lik = getfield(dlmsmo(y,F,V,x0,G,W*s^2,C0*s^2,[],0,0),'lik'); 20 | end 21 | -------------------------------------------------------------------------------- /dlmqqplot.m: -------------------------------------------------------------------------------- 1 | function out=dlmqqplot(dlm,ind) 2 | %DLMQQPLOT normal probability plot for DLM fit residuals 3 | 4 | if nargin<2, ind = 1; end 5 | % p = size(dlm.F,1); % number of series 6 | 7 | if isfield(dlm,'resid2') 8 | y = dlm.resid2(:,ind); 9 | else 10 | y = dlm.resid(:,ind); 11 | end 12 | igood = not(isnan(y)); 13 | yy = y(igood); 14 | h=qqplot(yy); 15 | %set(h,'markerfacecolor','black'); 16 | if isfield(dlm,'resid2') 17 | title('Normal probability plot for the residuals') 18 | else 19 | title('Normal probability plot for the raw residuals') 20 | end 21 | grid on; 22 | 23 | if nargout>0 24 | out=h; 25 | end 26 | -------------------------------------------------------------------------------- /mvnorrnan.m: -------------------------------------------------------------------------------- 1 | function y=mvnorrnan(n,mu,C,R) 2 | % Multivariate normal random numbers with possible zero variances. 3 | % C can be singular, also 4 | 5 | % marko.laine@fmi.fi, 2013 6 | 7 | if size(C,1)~=length(mu) 8 | error('sizes of mu and C do not match') 9 | end 10 | 11 | % first remove zero variances 12 | inds = diag(C) > 2*eps; 13 | 14 | y = repmat(mu(:)',n,1); 15 | 16 | C1 = C(inds,inds); 17 | mu1 = mu(inds); 18 | n1 = length(mu1); 19 | 20 | %[R,q] = chol(C1); % first try chol 21 | q=1; 22 | if q>0 % then svd 23 | % warning('sinqular cov'); 24 | [u,s,~] = svd(C1); 25 | k = find(diag(s)>1e-10,1,'last'); 26 | R = (u(:,1:k)*sqrt(s(1:k,1:k)))'; 27 | n1 = k; 28 | end 29 | 30 | %y(:,inds) = bsxfun(@plus,randn(n,n1)*R,mu1(:)'); 31 | y(:,inds) = y(:,inds) + randn(n,n1)*R; 32 | -------------------------------------------------------------------------------- /dlmplotdiag.m: -------------------------------------------------------------------------------- 1 | function out = dlmplotdiag(dlm, t, ys, yind) 2 | %DLMPLOTDIAG Default plot for DLM model diagnostics 3 | % dlmplotdiag(dlm, t, ys, yind) 4 | % dlm - output from dlmsmo 5 | % t - time axis for plots 6 | % ys - optional y axis scale factor for plots (not used) 7 | % yind - which series to plot, default = 1 8 | 9 | % Marko Laine 10 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 11 | 12 | if nargin<2 13 | t = (1:size(dlm.y,1))'; % yscale for plots 14 | end 15 | if nargin<3 16 | ys = 1; % yscale for plots 17 | end 18 | if nargin<4 19 | yind = 1; % which obs column to plot 20 | end 21 | 22 | % acf and qqplot 23 | subplot(2,1,1) 24 | dlmacfplot(dlm,yind); 25 | subplot(2,1,2) 26 | dlmqqplot(dlm,yind); 27 | 28 | if nargout>1 29 | out = []; 30 | end 31 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * DLM toolbox for Matlab 2 | 3 | This is a collection of Matlab files for Dynamic Linear Model calculations suitable for time series analysis. The code supplements the article M. Laine, N. Latva-Pukkila and E. Kyrölä: /Analyzing time-varying trends in stratospheric ozone time series using state the space approach/, in Atmospheric Chemistry and Physics 14(18), 2014, [[http://dx.doi.org/10.5194/acp-14-9707-2014][doi: 10.5194/acp-14-9707-2014]]. 4 | 5 | See https://mjlaine.github.io/dlm/ for details. 6 | 7 | Some functions depend on my MCMC toolbox, available at 8 | https://github.com/mjlaine/mcmcstat. 9 | 10 | marko.laine@fmi.fi 11 | 12 | #+DESCRIPTION: DLM toolbox readme file 13 | #+LANGUAGE: en 14 | #+TITLE: 15 | #+OPTIONS: H:3 \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t 16 | #+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc 17 | #+OPTIONS: title:nil num:nil toc:nil ^:{} creator:nil author:nil 18 | -------------------------------------------------------------------------------- /dlmacfplot.m: -------------------------------------------------------------------------------- 1 | function out = dlmacfplot(dlm,ind) 2 | % plot acf of dlm output 3 | 4 | if nargin<2, ind = 1; end 5 | p = size(dlm.F,1); % number of series 6 | 7 | if isfield(dlm,'resid2') 8 | a = acfnan(dlm.resid2(:,ind)); 9 | else 10 | a = acfnan(dlm.resid(:,ind)); 11 | end 12 | x = 0:length(a)-1; 13 | 14 | colo = [0 0.5 1]; 15 | 16 | h = plot(x,a,'o-','color',colo,'markerfacecolor',colo); 17 | xlim([x(1),x(end)]); 18 | yl = ylim;ylim([yl(1),1]); 19 | grid 20 | xlabel('lag') 21 | ylabel('acf') 22 | if isfield(dlm,'resid2') 23 | title('Estimated autocorrelation function of the DLM residuals') 24 | else 25 | title('Estimated autocorrelation function of the DLM raw residuals') 26 | end 27 | 28 | % approximate confidence limit, 95% 29 | hh = hline(2/sqrt(dlm.nobs(ind))); 30 | set(hh,'linestyle','--','color','black'); 31 | hh = hline(-2/sqrt(dlm.nobs(ind))); 32 | set(hh,'linestyle','--','color','black'); 33 | 34 | if nargout>0 35 | out=h; 36 | end 37 | -------------------------------------------------------------------------------- /examples/dlmdemo2.m: -------------------------------------------------------------------------------- 1 | %% DLM demo no 2, testing DLM functions 2 | % Generate seasonal data and fit DLM model with 12 seasons. 3 | 4 | %% 5 | % Data 6 | t = (1:1:(6*12))'; % time 7 | n = length(t); 8 | s = 0.1; % obs error std 9 | y = 2 + 0.5*(t-0)/12.*((t-0)<2*12) + ... 10 | 0.5*(2*12)/12.*((t-0)>=2*12) + ... 11 | 0.8*sin((t-0)/12*2*pi) + ... 12 | randn(n,1)*s; 13 | 14 | %% 15 | figure(1); clf 16 | plot(t,y,'o-'); xlabel('time'); ylabel('y'); title('observations');grid; 17 | 18 | %% 19 | % Model error diagonal, first non zero values. 20 | w123 = [0.0000,3.1e-5,1e-8,1e-8,1e-8,1e-8]; 21 | 22 | %% 23 | % Options for |dlmfit| function. Use harmonic functions with 2 24 | % components and 12 seasons. Optimize some variance parameters using maximum likelihood. 25 | clear options 26 | options.ns = 12; 27 | options.trig = 2; 28 | options.opt = 1; 29 | options.winds = [0 1 2 2 2 2]; 30 | 31 | %% 32 | % DLM fit. 33 | out = dlmfit(y,s,w123,[],[],[],options); 34 | %% 35 | % Default plots. 36 | dlmplot(out); 37 | 38 | -------------------------------------------------------------------------------- /examples/niledemo.m: -------------------------------------------------------------------------------- 1 | %% Classical Nile data 2 | % Here we fit the classical Nile river flow data 3 | 4 | y = [1120 1160 963 1210 1160 1160 813 1230 1370 1140 995 935 ... 5 | 1110 994 1020 960 1180 799 958 1140 1100 1210 1150 1250 ... 6 | 1260 1220 1030 1100 774 840 874 694 940 833 701 916 ... 7 | 692 1020 1050 969 831 726 456 824 702 1120 1100 832 764 ... 8 | 821 768 845 864 862 698 845 744 796 1040 759 781 865 ... 9 | 845 944 984 897 822 1010 771 676 649 846 812 742 801 ... 10 | 1040 860 874 848 890 744 749 838 1050 918 986 797 923 ... 11 | 975 815 1020 906 901 1170 912 746 919 718 714 740]'; 12 | 13 | t = (1871:1970)'; % time 14 | 15 | %% 16 | % Observation and model errors match those in Petris et al. (2009) 17 | s = sqrt(15100); 18 | w = sqrt([755 755]); 19 | 20 | %% 21 | % Fit the DLM model 22 | out = dlmfit(y,s,w); 23 | %% 24 | figure(3); 25 | dlmplotfit(out,t); 26 | title('Smoothed Nile data') 27 | %% 28 | figure(2); 29 | dlmplotdiag(out,t); 30 | 31 | -------------------------------------------------------------------------------- /dlmplot.m: -------------------------------------------------------------------------------- 1 | function out = dlmplot(dlm, t, ys, yind) 2 | %DLMPLOT Default plot for DLM model fit 3 | % dlmplot(dlm, t, ys, yind) 4 | % dlm - output from dlmsmo 5 | % t - time axis for plots 6 | % ys - optional y axis scale factor for plots 7 | % yind - which series to plot, default = 1 8 | 9 | % Marko Laine 10 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 11 | 12 | if nargin<2 | isempty(t) 13 | if isfield(dlm,'time') 14 | t = dlm.time; 15 | else 16 | t = (1:size(dlm.y,1))'; 17 | end 18 | end 19 | if nargin<3 | isempty(ys) 20 | if isfield(dlm,'ys') 21 | ys = dlm.ys; 22 | else 23 | ys = 1; % yscale for plots 24 | end 25 | end 26 | if nargin<4 27 | yind = 1; % which obs column to plot 28 | end 29 | 30 | doeb = 0; % do errorbar 31 | fex = 10*(yind-1); % figure offset 32 | 33 | % data and fit 34 | figure(fex+1); clf 35 | dlmplotfit(dlm, t, ys, yind, doeb, 0, 0); 36 | % level and trend 37 | figure(fex+2); clf 38 | dlmplotcomp(dlm, t, ys, yind); 39 | % acf and qqplot 40 | figure(fex+3); clf 41 | dlmplotdiag(dlm, t, ys, yind); 42 | 43 | if nargout>1 44 | out = []; 45 | end 46 | -------------------------------------------------------------------------------- /dlmplotcomp.m: -------------------------------------------------------------------------------- 1 | function out = dlmplotcomp(dlm, t, ys, yind) 2 | %DLMPLOTCOMP Default plot for some DLM model components 3 | % dlmplotcomp(dlm, t, ys, yind) 4 | % dlm - output from dlmsmo 5 | % t - time axis for plots 6 | % ys - optional y axis scale factor for plots 7 | % yind - which series to plot, default = 1 8 | 9 | % Marko Laine 10 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 11 | 12 | if nargin<2 13 | t = (1:size(dlm.y,1))'; % yscale for plots 14 | end 15 | if nargin<3 16 | ys = 1; % yscale for plots 17 | end 18 | if nargin<4 19 | yind = 1; % which obs column to plot 20 | end 21 | 22 | y = dlm.y; % obs 23 | s = dlm.V; % obs std 24 | 25 | p = size(dlm.F,1); % data columns 26 | m = size(dlm.G,1); % states 27 | mm = m/p; % states / obs columns 28 | 29 | dlmconf = @(dlm,ind,t,ys) confband(t,ys.*dlm.x(ind,:)',ys.*dlm.xstd(:,ind)); 30 | 31 | % level and trend 32 | ind = 1 + mm*(yind-1); 33 | subplot(2,1,1); 34 | dlmconf(dlm,ind,t,ys); 35 | grid 36 | title('level'); 37 | xlim([min(t),max(t)]); 38 | 39 | ind = 2 + mm*(yind-1); 40 | subplot(2,1,2); 41 | dlmconf(dlm,ind,t,ys); 42 | grid 43 | title('trend'); 44 | xlim([min(t),max(t)]); 45 | 46 | if nargout>1 47 | out = []; 48 | end 49 | -------------------------------------------------------------------------------- /dlmplotresid.m: -------------------------------------------------------------------------------- 1 | function out = dlmplotresid(dlm, t, yind) 2 | %DLMPLOTRESID Plot for DLM residuals 3 | % dlmplotfit(dlm, t, yind) 4 | % dlm - output from dlmsmo 5 | % t - time axis for plots 6 | % yind - which series to plot, default = 1 7 | 8 | % plots data with the level component and fitted values 9 | % with all components except possible AR 10 | 11 | % Marko Laine 12 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 13 | 14 | if nargin<2 15 | if isfield(dlm,'time') 16 | t = dlm.time; 17 | else 18 | t = (1:size(dlm.y,1))'; 19 | end 20 | end 21 | if nargin<3 22 | yind = 1; % which obs column to plot 23 | end 24 | 25 | colo = [0 0.5 1]; 26 | siz = 4; 27 | setplot = @(h) set(h,'color',colo,'markersize',siz,'markerfacecolor',colo); 28 | 29 | subplot(3,1,1) 30 | h1=plot(t,dlm.resid0(:,yind),'o-');setplot(h1);grid on 31 | title('raw smoother residuals') 32 | xlim([t(1),t(end)]); 33 | 34 | subplot(3,1,2) 35 | h2=plot(t,dlm.resid(:,yind),'o-');setplot(h2);grid on 36 | title('scaled smoother residuals') 37 | xlim([t(1),t(end)]); 38 | 39 | subplot(3,1,3) 40 | h3=plot(t,dlm.resid2(:,yind),'o-');setplot(h3);grid on 41 | title('scaled prediction residuals') 42 | xlim([t(1),t(end)]); 43 | 44 | if nargout>0 45 | out=[h1;h2;h3]; 46 | end 47 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Marko Laine 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | The views and conclusions contained in the software and documentation are those 23 | of the author and should not be interpreted as representing official policies, 24 | either expressed or implied, of his employer. 25 | -------------------------------------------------------------------------------- /examples/dlmdemo3.m: -------------------------------------------------------------------------------- 1 | %% DLM demo no 3, synthetic multivariate time series 2 | % Test the |dlmsmo| code with multivariate series with missing observations. 3 | 4 | %% 5 | % generate system matrices 6 | [G,F] = dlmgensys(struct('order',2,'trig',2)); 7 | 8 | %% 9 | % generate observations for the first series 10 | m = size(G,2); 11 | p = size(F,1); 12 | nobs = 100; 13 | t = (1:nobs)'; 14 | 15 | W = zeros(m,m); W(2,2) = 0.0004^2; for i=4:7 ; W(i,i)=0.0005^2; end 16 | V = 0.8; % obs error std 17 | x = zeros(nobs,m); 18 | y = zeros(nobs,p); 19 | 20 | x(1,:) = [0 0.0001 0.0003 1 1 2 1]; % initial values 21 | for i=2:nobs 22 | x(i,:) = x(i-1,:)*G' + randn(1,m).*sqrt(diag(W))'; 23 | y(i,:) = x(i,:)*F' + randn(1,p)*V; 24 | end 25 | 26 | %% 27 | % generate second series 28 | GG = kron(eye(2),G); 29 | FF = kron(eye(2),F); 30 | WW = diag([diag(W);diag(W)]); 31 | VV = ones(nobs,2)*V; 32 | yy = [y,y+5] + randn(nobs,2)*V; 33 | x0 = zeros(m+m,1); 34 | C0 = eye(m+m); 35 | 36 | %% 37 | % add some missing observations 38 | yy(10,1) = NaN; 39 | yy(50,:) = NaN; 40 | yy(20:30,1) = NaN; 41 | yy(end-9:end,2) = NaN; 42 | 43 | %% 44 | dlm = dlmsmo(yy,FF,VV,x0,GG,WW,C0); 45 | 46 | %% 47 | figure(1); clf 48 | confband(t,dlm.x(1,:)',dlm.xstd(:,1)); 49 | hold on 50 | confband(t,dlm.x(8,:)',dlm.xstd(:,8)); 51 | plot(t,yy,'.-') 52 | hold off 53 | title('two dimensional time serie with missing observations') 54 | xlabel('time'); ylabel('y'); -------------------------------------------------------------------------------- /dlmdisp.m: -------------------------------------------------------------------------------- 1 | function out = dlmdisp(dlm) 2 | %DLMDISP print information about the DLM fit 3 | 4 | % Marko Laine 5 | % $Revision: 0.0 $ $Date: 2015/06/03 12:00:00 $ 6 | 7 | 8 | if not(isstruct(dlm)) || not(strcmp(dlm.class,'dlmfit')||strcmp(dlm.class,'dlmsmo')) 9 | error('works only for dlm output structure'); 10 | end 11 | 12 | fprintf('DLM model output\n'); 13 | 14 | if strcmp(dlm.class,'dlmfit') 15 | 16 | fprintf('Model options\n') 17 | fprintf(' order: %d\n',dlm.options.order) 18 | if dlm.options.fullseas 19 | fprintf(' fullseas\n') 20 | else 21 | fprintf(' trig: %d\n',dlm.options.trig) 22 | end 23 | 24 | if not(isempty(dlm.options.arphi)) 25 | fprintf(' AR(%d): %d\n',length(dlm.options.arphi)) 26 | end 27 | 28 | if isfield(dlm,'chain') 29 | fprintf('MCMC: npar %d, nsimu: %d, rejected %0.3g%%\n', ... 30 | size(dlm.chain,2), size(dlm.chain,1),dlm.res.rejected*100); 31 | 32 | end 33 | 34 | fprintf('\n'); 35 | 36 | end 37 | 38 | %fprintf('Observations %d\n',dlm.nobs); 39 | nprint('Observations: ', '%d ',dlm.nobs); 40 | nprint('RMSE: ','%.3g ',sqrt(dlm.mse)); 41 | nprint('MAPE: ','%.3g ',dlm.mape); 42 | nprint('sigma: ', '%.4g ',sqrt(dlm.s2)); 43 | nprint('likelihood: ','%g ',dlm.lik); 44 | fprintf('\n'); 45 | 46 | if nargout>0 47 | out=dlm; 48 | end 49 | function nprint(s,f,x) 50 | fprintf('%s',s); 51 | fprintf(f,x); 52 | fprintf('\n'); 53 | -------------------------------------------------------------------------------- /dlmsmosam.m: -------------------------------------------------------------------------------- 1 | function out=dlmsmosam(dlm, nsample) 2 | %DLMSMOSAM sample from DLM model 3 | % out=dlmsmosam(dlm, nsample) 4 | 5 | % Marko Laine 6 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 7 | 8 | if nargin<2; nsample = 1; end 9 | 10 | [p,m] = size(dlm.F); 11 | n = length(dlm.yhat); 12 | m = m + size(dlm.XX,2)*p; 13 | out = zeros(m,n,nsample); 14 | 15 | hw = waitbar(0,'Generating sample'); 16 | % there is mcmc chain that has samples from diagonal of W 17 | for isample = 1:nsample 18 | if fix(isample/10)==isample/10;waitbar(isample/nsample,hw);end 19 | W = dlm.W; 20 | V = dlm.V; 21 | G = dlm.G; 22 | if isfield(dlm,'chain') 23 | if isfield(dlm,'vinds') && not(isempty(dlm.vinds)) 24 | vinds = dlm.vinds; % can be only 1 now 25 | else 26 | vinds = 0; 27 | end 28 | cind = ceil(rand(1)*size(dlm.chain,1)); 29 | if vinds>0 30 | V = V.* dlm.chain(cind,1); 31 | end 32 | for i = 1:length(dlm.winds) 33 | if dlm.winds(i)>0 34 | W(i,i) = dlm.chain(cind,dlm.winds(i)+vinds).^2; 35 | end 36 | end 37 | if isfield(dlm,'ginds') 38 | i0 = max(dlm.winds)+vinds; 39 | for i=1:length(dlm.ginds) 40 | G(dlm.ginds(i),dlm.ginds(i))=dlm.chain(cind,i0+i); 41 | end 42 | end 43 | end 44 | x0 = dlm.x(:,1); 45 | C0 = dlm.C(:,:,1); 46 | % x00 = mvnorrnan(1,x0,C0); 47 | o = dlmsmo(dlm.y,dlm.F,V,x0,G,W,C0,dlm.XX,1,1,0); 48 | out(:,:,isample) = o.xr; 49 | end 50 | 51 | delete(hw); -------------------------------------------------------------------------------- /dlmgensys.m: -------------------------------------------------------------------------------- 1 | function [G,F] = dlmgensys(options) 2 | %DLMGENSYS generate system matrices G and F for a DLM model 3 | % dlmgensys(options) 4 | % options.order - order of the local polynomial trend component (1) 5 | % options.fullseas - to use full seasonal component or not (0) 6 | % options.trig - how many seasonal harmonics (0) 7 | % options.ns - how many seasons (default = 12) 8 | % opitions.arphi - AR coefficients ([]) 9 | 10 | % Marko Laine 11 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 12 | 13 | if nargin<1 14 | options = struct(); 15 | end 16 | 17 | % check options field 18 | if not(isfield(options,'order')), options.order=1; end 19 | if not(isfield(options,'fullseas')), options.fullseas=0; end 20 | if not(isfield(options,'trig')), options.trig=0; end 21 | if not(isfield(options,'ns')), options.ns=12; end 22 | 23 | if not(isfield(options,'arphi')), options.arphi=[]; end 24 | 25 | if options.trig>options.ns/2 26 | error('trig must be between 0 and ns/2') 27 | end 28 | 29 | % utility to combine matrices 30 | stack = @(a,b)[a,zeros(size(a,1),size(b,2));zeros(size(b,1),size(a,2)),b]; 31 | % Generate harmonic component 32 | ns = options.ns; 33 | harm = @(k)[cosd(360/ns*k),sind(360/ns*k);-sind(360/ns*k),cosd(360/ns*k)]; 34 | % Generate polynomial trend component 35 | trend = @(o) diag(ones(o+1,1))+diag(ones(o,1),1); 36 | 37 | % Local polynomial trend 38 | Gt = trend(options.order); 39 | Ft = [1, zeros(1,options.order)]; 40 | if isempty(Gt) , Ft = []; end 41 | 42 | % Seasonal term 43 | if options.fullseas == 1 44 | Gs = diag(ones(options.ns-2,1),-1); 45 | Gs(1,:) = -1; 46 | Fs = [1,zeros(1,options.ns-2)]; 47 | else 48 | Gs = []; 49 | Fs = []; 50 | for i = 1:options.trig 51 | Gs = stack(Gs,harm(i)); 52 | Fs = [Fs,[1 0]]; 53 | end 54 | % if ns even and trig=ns/2, then remove the last element as it is redundant 55 | if options.trig == options.ns/2 56 | Gs = Gs(1:end-1,1:end-1); 57 | Fs = Fs(1:end-1); 58 | end 59 | end 60 | 61 | % AR terms (experimental) 62 | arphi=options.arphi(:); 63 | nar = length(arphi); 64 | if nar > 0 65 | Gar = [arphi,[eye(nar-1);zeros(1,nar-1)]]; 66 | Far = [1,zeros(1,nar-1)]; 67 | else 68 | Gar = []; 69 | Far = []; 70 | end 71 | 72 | % combine trend and seasonal 73 | G = stack(Gt,Gs); 74 | F = [Ft,Fs]; 75 | 76 | % add AR 77 | G = stack(G,Gar); 78 | F = [F,Far]; 79 | 80 | -------------------------------------------------------------------------------- /docs/style.css: -------------------------------------------------------------------------------- 1 | /* borrowed from org.css */ 2 | @import url(http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono|Droid+Serif); 3 | 4 | html { 5 | margin: 0; 6 | font: 300 .9em/1.6em "Droid Serif", "Open Sans", Cambria, Georgia, "DejaVu Serif", serif; 7 | } 8 | 9 | BODY { 10 | /* font-family: Verdana, Arial, helvetica, sans-serif; */ 11 | /* font-family: sans-serif;*/ 12 | color: black; 13 | background: #fffaf0 /* white */; 14 | margin-top: 1em; 15 | margin-bottom: 1em; 16 | margin-left: 10%; 17 | margin-right: 10%; 18 | } 19 | P, TD, DL, UL, OL { 20 | /* font-family: Verdana, Arial, helvetica, sans-serif;*/ 21 | /* font-family: sans-serif;*/ 22 | /* margin-left: 0%; 23 | margin-right: 0%; */ 24 | text-indent: 0cm; 25 | } 26 | H1 { 27 | font-weight: bold; 28 | font-size: 200%; 29 | margin-left: 0%; 30 | margin-right: 0%; 31 | color: brown; 32 | } 33 | H2 { 34 | font-weight: bold; 35 | font-size: 120%; 36 | color: brown; 37 | /* margin-bottom: -1em; */ 38 | } 39 | H3 { 40 | font-weight: bold; 41 | font-size: 100%; 42 | color: brown; 43 | } 44 | H4 { 45 | font-weight: bold; 46 | font-size: 100%; 47 | color: brown; 48 | } 49 | /* 50 | PRE { 51 | font-family: courier, monospace; 52 | white-space: pre; 53 | } 54 | */ 55 | 56 | code { 57 | font-family: "Droid Sans Mono"; 58 | /* background-color: #eeeeee;*/ 59 | /* padding: 2pt;*/ 60 | /* margin-right: 1pt;*/ 61 | /* box-shadow: 1px 1px 1px #aaa;*/ 62 | } 63 | 64 | pre { 65 | font-family: "Droid Sans Mono"; 66 | font-size: .8em; 67 | font-weight: normal; 68 | line-height: 1.4em; 69 | background-color: #eeeeee; 70 | padding: 2pt; 71 | margin-right: 1pt; 72 | box-shadow: 1px 1px 1px #aaa; 73 | } 74 | 75 | pre.src { 76 | position: relative; 77 | overflow: visible; 78 | padding-top: 0.2em; 79 | } 80 | 81 | pre.src:before { 82 | display: none; 83 | position: absolute; 84 | background-color: white; 85 | top: -10px; 86 | right: 10px; 87 | padding: 3px; 88 | border: 1px solid black; 89 | } 90 | 91 | pre.src-matlab:before { content: 'Matlab'; } 92 | 93 | 94 | /* 95 | pre { 96 | border: 1px solid #ccc; 97 | box-shadow: 3px 3px 3px #eee; 98 | padding: 8pt; 99 | font-family: monospace; 100 | overflow: auto; 101 | margin: 1.2em; 102 | background: #eeeeee; 103 | } 104 | */ 105 | 106 | A {text-decoration: none;} 107 | A:link {color: #cc0000;} 108 | A:visited {color: #cc0099;} 109 | A:active {color: #ff3300;} 110 | A:hover {color: #ff3300;} 111 | 112 | /* green */ 113 | A:link {color: #993300;} 114 | A:visited {color: #993300;} 115 | A:active {color: #336666;} /* #00ccff; */ 116 | A:hover {color: #336666; /* background: #ffffff; */} 117 | 118 | 119 | P:date { 120 | /* font-family: Verdana, Arial, helvetica, sans-serif;*/ 121 | /* font-family: sans-serif;*/ 122 | font-size: 80%;text-align: left;} 123 | 124 | -------------------------------------------------------------------------------- /dlmplotfit.m: -------------------------------------------------------------------------------- 1 | function out = dlmplotfit(dlm, t, ys, yind, doeb, statbox, smo) 2 | %DLMPLOTFIT Default plot for DLM model fit 3 | % dlmplotfit(dlm, t, ys, yind) 4 | % dlm - output from dlmsmo 5 | % t - time axis for plots 6 | % ys - optional y axis scale factor for plots 7 | % yind - which series to plot, default = 1 8 | 9 | % plots data with the level component and fitted values 10 | % with all components except possible AR 11 | 12 | % Marko Laine 13 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 14 | 15 | if nargin<2 | isempty(t) 16 | if isfield(dlm,'time') 17 | t = dlm.time; 18 | else 19 | t = (1:size(dlm.y,1))'; % x axis 20 | end 21 | end 22 | if nargin<3 | isempty(ys) 23 | if isfield(dlm,'ys') 24 | ys = dlm.ys; 25 | else 26 | ys = 1; % yscale for plots 27 | end 28 | end 29 | if nargin<4 30 | yind = 1; % which obs column to plot 31 | end 32 | 33 | 34 | % some extra inputs 35 | if nargin<5 36 | doeb = 0; % do errorbar 37 | end 38 | if nargin<6 39 | statbox = 0; % add "statbox" to figures 40 | end 41 | if nargin<7 42 | smo = -1; % smoother or filter "yhat", not used yet 43 | end 44 | 45 | y = dlm.y; % obs 46 | if isfield(dlm,'s') 47 | s = dlm.s; % obs std 48 | else 49 | s = dlm.V; % obs std 50 | end 51 | 52 | p = size(dlm.F,1); % data columns 53 | m = size(dlm.G,1); % states 54 | mm = m/p; % states / obs columns 55 | 56 | dlmconf = @(dlm,ind,t,ys) confband(t,ys.*dlm.x(ind,:)',ys.*dlm.xstd(:,ind)); 57 | 58 | % model output, excluding AR part, as the yfit will too "good" 59 | if isfield(dlm,'options') && isfield(dlm.options,'arphi') 60 | nar = length(dlm.options.arphi); 61 | else 62 | nar = 0; 63 | end 64 | if nar > 0 & 0 % now yhat is filter prediction observations 65 | % try to remove effect of AR 66 | m = size(dlm.G,1); p = size(dlm.XX,2); 67 | ii = 1:m-nar-p-1; 68 | % ii = [ii,m-p:m]; 69 | ii = m-nar-p:m-p; 70 | % yfit = ys.*(dlm.F(yind,ii)*dlm.x(ii,:))'; 71 | yfit = ys.*(dlm.yhat(:,yind)'-dlm.F(yind,ii)*dlm.x(ii,:))'; 72 | else 73 | yfit = ys.*dlm.yhat(:,yind); 74 | end 75 | 76 | yfit = ys.*dlm.yhat(:,yind); 77 | 78 | 79 | % data, fit, and level 80 | %ind = 1 + mm*(yind-1); 81 | ind = yind; % assume cron(G,I) 82 | hc = dlmconf(dlm,ind,t,ys); 83 | hold on 84 | if doeb 85 | h = errorbar(t,ys.*y(:,yind),2*ys.*s(:,yind),'ok'); 86 | if smo>=0 87 | hold on;plot(t,yfit,'-','color','red');hold off 88 | end 89 | else 90 | % h = plot(t,ys.*y(:,yind),'ok',t,yfit,'-'); 91 | h = plot(t,ys.*y(:,yind),'ok'); 92 | if smo>=0 93 | hold on;plot(t,yfit,'-','color','red');hold off 94 | end 95 | end 96 | colo = [0 0.5 1]; 97 | set(h(1),'color',colo,'markerfacecolor',colo,'markersize',5); 98 | hold off 99 | if statbox 100 | % some statistics in a box 101 | textbox({sprintf('RMSE=%.3g',sqrt(dlm.mse(yind))), 102 | sprintf('MAPE=%.3g',dlm.mape(yind))}); 103 | end 104 | 105 | xlim([min(t),max(t)]); % adjust xlims 106 | 107 | % try to guess if time is matlab datetime 108 | if t(1) > datenum(1960,1,1) 109 | datetick('x'); 110 | end 111 | 112 | if isfield(dlm,'label') 113 | title(dlm.label); 114 | end 115 | 116 | if nargout>0 117 | out = [hc;h]; 118 | end 119 | -------------------------------------------------------------------------------- /examples/ozonedemo.m: -------------------------------------------------------------------------------- 1 | %% Stratospheric ozone time series trend analysis 2 | % This demo reproduces calculation for article: Laine, M., Latva-Pukkila, N., Kyrölä, E., 3 | % Analyzing time varying trends in stratospheric ozone time series using state space approach, 4 | % _Atmospheric Chemistry and Physics Discussion_, *13*, pages 20503-20530, 2013. 5 | % 6 | % 7 | 8 | %% 9 | % First load example data set. Stratospheric ozone observations from 10 | % two satellite instruments SAGE II and GOMOS. The original satellite 11 | % observations has been combined and processed to produce averaged 12 | % zonal data for different altitudes. Here we use monthly avarages between 45 km to 13 | % 55 km and 40N to 50N for years 1984 to 2012. 14 | load ozonedata.mat % data, label 15 | 16 | time = data(:,1); % time in years from 1984 to 2012 17 | y = data(:,2); % ozone density [1/cm^3] 18 | s = data(:,3); % uncertainty standard deviation for y 19 | X = data(:,4:6); % proxies 20 | 21 | %% 22 | % We scale |y| for numerical stability. 23 | ys = stdnan(y); 24 | yy = y./ys; 25 | ss = s./ys; 26 | 27 | %% 28 | % Prior means for some components of |W|, the model error matrix. 29 | ym = meannan(yy); % mean observations 30 | wtrend = abs(ym)*0.00005; % trend std 31 | wseas = abs(ym)*0.015; % seasonal component std 32 | w0 = [0 wtrend wseas wseas wseas wseas]; 33 | 34 | %% 35 | % Calculate the DLM smoother solution, do MCMC over some components in the matrix |W|. 36 | options = struct('trig',2,'mcmc',1,'nsimu',2000,'winds',[0 1 2 2 2 2]); 37 | dlm = dlmfit(yy,ss,w0,[],[],X,options); 38 | 39 | %% 40 | figure(1); 41 | dlmplotfit(dlm, time, ys) 42 | title(label);xlabel('time');ylabel('average O3 density [cm^{-3}]') 43 | %% 44 | figure(2); 45 | dlmplotdiag(dlm, time, ys) 46 | 47 | %% 48 | % Produce sample from the model states using |dlmsmosam|. It accounts the posterior uncertainty 49 | % in W using the MCMC chain in |dlm.chain|. 50 | nsam = 200; % number of sampled to draw from the posterior 51 | dlm_sample = dlmsmosam(dlm,nsam); 52 | %% 53 | % Draw dome sample realizations of the level component over the plot in Figure 2. 54 | figure(1); 55 | hold on 56 | for i=1:5:nsam 57 | plot(time,ys*squeeze(dlm_sample(1,:,i)),'-') 58 | end 59 | hold off 60 | %% 61 | % The next figure shows prior and posterior distributions for 62 | % standard deviations from the diagonal of model error matrix |W|. 63 | figure(3); clf 64 | mcmcplot(dlm.chain,[],dlm.res,'denspanel',2); 65 | subplot(2,1,1);title('prior and posterior for variance parameters');xlabel('parameter w(2,2)') 66 | subplot(2,1,2);title('');xlabel('parameter w(3,3)') 67 | 68 | %% 69 | % Sample trend statistics form DLM sample. We calculate 10 year running trend. 70 | nyear = 10; 71 | tsamp = ys*squeeze(dlm_sample(1,:,:)); % sample of levels 72 | ysm = mean(tsamp(:)); % their mean 73 | ysf = 1/(ysm*nyear)*100; % scale factor to get % change / 10 year 74 | t10 = mean((tsamp(nyear*12+1:end,:)-tsamp(1:end-nyear*12,:))')*ysf; % mean trend 75 | s10 = std((tsamp(nyear*12+1:end,:)-tsamp(1:end-nyear*12,:))')*ysf; % std in the sample 76 | time10 = time(fix(nyear/2)*12+1:end); time10 = time10(1:length(t10)); % time axis for plot 77 | 78 | %% 79 | figure(4); clf 80 | confband(time10,t10,s10);grid; 81 | xlim([time(1),time(end)]); % match axis to other plots 82 | title('10 year trend'); 83 | ylabel('% change / year') 84 | -------------------------------------------------------------------------------- /examples/dlmdemo1.m: -------------------------------------------------------------------------------- 1 | %% DLM demo no 1 2 | % Generate synthetic and ideal data and fit a DLM smoother. 3 | % The command |dlmgensys| generates system evolution matrix |G| 4 | % and obs operator |F|. We use local level and trend model with 12 seasons. 5 | [G,F] = dlmgensys(struct('order',1,'fullseas',1,'ns',12)); 6 | % p = number of data sets = 1, 7 | % m = number of internal states = 13 8 | [p,m] = size(F); 9 | 10 | %% 11 | % Generate data. 12 | t = (1:1:(6*12))'; % time 13 | n = length(t); 14 | s = 0.1; % obs error std 15 | V = ones(n,p)*s; % V is matrix of std's 16 | x0 = [0;0.001;sin((1:11)/12*pi*2)']; % initial state 17 | C0 = 0.02*eye(m)*s^2; % initial state uncertainty 18 | W = zeros(m); % "model error" 19 | W(1,1) = 0.000002^2; 20 | W(2,2) = 0.002.^2; 21 | W(3,3) = 0.02.^2; 22 | 23 | %% 24 | % Observations are generated using the state space recursion. 25 | y = zeros(n,1); 26 | x = x0; 27 | for i=1:n 28 | y(i) = F*x + randn(1,1)*s; 29 | x = G*x + randn(m,1).*sqrt(diag(W)); 30 | end 31 | 32 | %% 33 | % Function |dlmsmo| calculates the estimated states using Kalman smoother. 34 | out = dlmsmo(y,F,V,x0,G,W,C0); 35 | x0 = out.x(:,1); % save smoothed estimate of x0 36 | 37 | %% 38 | % Plot observations and the fitted level with 95% (time wise) confidence bands. 39 | figure(1); clf 40 | plot(t,out.yhat,'*') 41 | hold on 42 | confband(t,out.x(1,:)',out.xstd(:,1)); 43 | errorbar(t,y,2*V,'ok-') 44 | hold off 45 | 46 | %% 47 | figure(2); clf 48 | confband(t,out.x(2,:)',out.xstd(:,2)); grid; title('Trend') 49 | 50 | %% MCMC 51 | % Gibbs sampling for the variance parameters using conjugate prior distributions. This takes some time. 52 | nsimu = 1000; 53 | chain = zeros(nsimu,4); 54 | W0 = W; % prior W 55 | n0 = 5; % prior weight 56 | V0 = s; 57 | nv0 = 10; 58 | doplot = 1; 59 | plotint = 100; 60 | 61 | %% 62 | hw = waitbar(0,'MCMC running, please wait'); 63 | for isimu = 1:nsimu 64 | waitbar(isimu/nsimu,hw); 65 | % Gibbs step for variance parameters 66 | % residual std for V, conjugate distribution is inverse chi squared 67 | sigV = sqrt(invchir(1,1,n+nv0,(out.ssy+V0.^2*nv0)/(n+nv0))); 68 | V = ones(n,p)*sigV; 69 | out = dlmsmo(y,F,V,x0,G,W,C0); % recalculate with new V 70 | % variances in diag(W) 71 | c = zeros(1,3); % fit 3 first variances 72 | for i=1:3 73 | c(i) = invchir(1,1,n+n0-1,(W0(i,i).*n0+out.ss(i))./(n+n0-1)); 74 | W(i,i) = c(i); 75 | out = dlmsmo(y,F,V,x0,G,W,C0); % recalculate smoother 76 | end 77 | chain(isimu,:) = [sigV,sqrt(c(1:3))]; 78 | if doplot & (isimu/plotint == fix(isimu/plotint)) 79 | % plot every plotint'th MCMC sampled state 80 | figure(1); 81 | hold on 82 | plot(t,out.xr(1,:),'-r') 83 | hold off 84 | end 85 | end 86 | close(hw); 87 | 88 | %% 89 | figure(3); clf 90 | mcmcplot(chain,[],{'V','W1','W2','W3'}); 91 | hold on 92 | subplot(2,2,1); h=hline(s);set(h,'linestyle','-','linewidth',2) 93 | subplot(2,2,2); h=hline(sqrt(W0(1,1)));set(h,'linestyle','-','linewidth',2) 94 | subplot(2,2,3); h=hline(sqrt(W0(2,2)));set(h,'linestyle','-','linewidth',2) 95 | subplot(2,2,4); h=hline(sqrt(W0(3,3)));set(h,'linestyle','-','linewidth',2) 96 | hold off 97 | 98 | V = ones(n,p)*sqrt(mean(chain(:,1).^2)); 99 | for i=1:3; W(i,i) = mean(chain(:,i+1).^2); end 100 | 101 | out = dlmsmo(y,F,V,x0,G,W,C0); 102 | 103 | %% 104 | % Add estimated over the initial trend. 105 | figure(2); 106 | ind = 2; % 107 | xxx = out.x(ind,:)'; 108 | hold on 109 | plot(t,xxx) 110 | plot(t,xxx-2*out.xstd(:,ind),'g-') 111 | plot(t,xxx+2*out.xstd(:,ind),'g-') 112 | hold off 113 | -------------------------------------------------------------------------------- /docs/index.org: -------------------------------------------------------------------------------- 1 | # DLM matlab code org documentation 2 | 3 | * Dynamic Linear Model Matlab toolbox 4 | 5 | This is a collection of Matlab files for Dynamic Linear Model calculations suitable for time series analysis. The code supplements the article M. Laine, N. Latva-Pukkila and E. Kyrölä: /Analyzing time-varying trends in stratospheric ozone time series using state the space approach/, in Atmospheric Chemistry and Physics 14(18), 2014, [[http://dx.doi.org/10.5194/acp-14-9707-2014][doi: 10.5194/acp-14-9707-2014]]. 6 | 7 | The code is provided as auxiliary material for the paper and might be useful to you if you are already familiar with Matlab and MCMC and state space analysis of time series. Some references are given at the end. 8 | 9 | The toolbox provides tools to estimate dynamic linear state space mode suitable for analysing univariate and multivariate time series. It uses Kalman filter, smoother and simulation smoother to estimate the states and Markov chain Monte Carlo (MCMC) to sample from the model error variance parameter posterior distribution. 10 | 11 | See [[file:dlmtut.html][DLM tutorial]] for some info on using this DLM toolbox for time series analysis. 12 | 13 | * Downloads 14 | 15 | The full Matlab code and this documentation are available from [[https://github.com/mjlaine/dlm][GitHub]]. To install the toolbox clone the folder =dlm= to a suitable directory and then add Matlab path to that directory. 16 | 17 | #+BEGIN_EXAMPLE bash 18 | git clone https://github.com/mjlaine/dlm.git 19 | #+END_EXAMPLE 20 | 21 | Alternatively, you can download the whole repository as a zip file from the GitHub page or directly as 22 | https://github.com/mjlaine/dlm/archive/master.zip 23 | 24 | In addition to the code provided below, you will need my [[https://mjlaine.github.io/mcmcstat/][Matlab MCMC Toolbox]] ([[https://github.com/mjlaine/mcmcstat][direct Github link]]). MCMC is used to infer and sample the variance parameters needed in defining the linear state space model. 25 | 26 | The code is distributed under a MIT License and comes with no warranty. The documentation is minimal at the moment. Please read the source code for details of the algorithms used. Question and suggestions are welcome. If you find the code useful, it would be kind to acknowledge me in your research articles. 27 | 28 | * Examples 29 | 30 | Some examples as Matlab demos. 31 | 32 | - [[file:ex/niledemo.html][Nile river flow]] :: Classical Nile river data, file =niledemo.m=. 33 | - [[file:ex/dlmdemo1.html][DLM demo 1]] :: Fits Kalman smoother and does Gibbs sampling on variance parameters. 34 | - [[file:ex/dlmdemo2.html][DLM demo 2]] :: Fits synthetic time series with ML optimization. 35 | - [[file:ex/dlmdemo3.html][DLM demo 3]] :: Fits synthetic multivariate time series. 36 | - [[file:ex/ozonedemo.html][Ozone time series]] :: Reproduces the fit used in the Ozone time series article. 37 | 38 | 39 | See also example in the the [[file:dlmtut.html][DLM tutorial]]. 40 | 41 | 42 | * References 43 | 44 | # <<#ref:laine2014>> 45 | Laine, M., Latva-Pukkila, N., Kyrölä, E., 46 | Analyzing time-varying trends in stratospheric ozone time series using the state space approach, /Atmospheric Chemistry and Physics/, *14(18)*, pages 9707--9725, 2014. 47 | [[http://dx.doi.org/10.5194/acpd-13-20503-2013][doi: 10.5194/acp-14-9707-2014]]. 48 | 49 | # <<#ref:durbin2011>> 50 | Durbin, T. and Koopman, S.,/Time Series Analysis by State Space Methods/, 51 | Oxford University Press, second edn, 2012. 52 | [[http://books.google.com/books?vid=ISBN019964117X][Google books link]]. 53 | 54 | # <<#ref:petris2009>> 55 | Petris, G., Petrone, S., and Campagnoli, P., 56 | /Dynamic Linear Models with R, Use R!/, Springer, 2009. 57 | [[http://books.google.com/books?vid=ISBN0387772383][Google books link]]. 58 | 59 | 60 | #+HTML:
61 | 62 | # 63 | #+TITLE: DLM Matlab Toolbox 64 | #+AUTHOR: Marko Laine 65 | #+EMAIL: marko.laine@fmi.fi 66 | #+DESCRIPTION: Matlab toolbox for some Dynamic Linear Model calculations 67 | #+KEYWORDS: DLM, MCMC, time series 68 | #+LANGUAGE: en 69 | # #+ LINK_HOME: http://helios.fmi.fi/~lainema/ 70 | # # +LINK_UP: http://helios.fmi.fi/~lainema/ 71 | # #+HTML_LINK_HOME: http://helios.fmi.fi/~lainema/ 72 | # #+HTML_LINK_UP: http://helios.fmi.fi/~lainema/dlm/ 73 | #+OPTIONS: num:nil toc:nil ^:{} creator:nil timestamp:t author:t 74 | #+STYLE: 75 | #+HTML_HEAD: 76 | #+HTML_MATHJAX: align:"left" mathml:t 77 | #+EXPORT_SELECT_TAGS: export 78 | #+EXPORT_EXCLUDE_TAGS: noexport 79 | 80 | 81 | # Local Variables: 82 | # coding: utf-8 83 | # mode: org 84 | # eval: (flyspell-mode 1) 85 | # eval: (visual-line-mode 1) 86 | # eval: (auto-fill-mode -1) 87 | # ispell-dictionary: "english" 88 | # End: 89 | 90 | -------------------------------------------------------------------------------- /dlmtsfit.m: -------------------------------------------------------------------------------- 1 | function out=dlmtsfit(t,y,s,X,options) 2 | % Fit a time series model 3 | 4 | % t time in matlab format 5 | % y n*p data matrix 6 | % s n*p std uncertainty 7 | % X n*nx proxy variables 8 | 9 | if nargin < 4 10 | X = []; 11 | end 12 | if nargin < 5 13 | options = []; 14 | end 15 | 16 | % remove NaN's from the begining and end 17 | i0 = isnan(s) | s<=0; 18 | y(i0) = NaN; 19 | if size(y,2)>1 20 | i1 = find(not(all(isnan(y'))'),1,'first')-1; 21 | i2 = find(not(all(isnan(y'))'),1,'last')+1; 22 | else 23 | i1 = find(not(isnan(y)),1,'first')-1; 24 | i2 = find(not(isnan(y)),1,'last')+1; 25 | end 26 | y([1:i1,i2:end],:) = []; 27 | s([1:i1,i2:end],:) = []; 28 | t([1:i1,i2:end],:) = []; 29 | 30 | % scale y with a global scale for all columns 31 | ys = meannan(stdnan(y)); 32 | y = y./ys; 33 | s = s./ys; 34 | 35 | o = options; 36 | o.trig = getopt(o,'trig',1); 37 | o.ns = getopt(o,'ns',12); 38 | o.order = getopt(o,'order',1); 39 | o.arphi = getopt(o,'arphi',[]); 40 | o.trend = getopt(o,'trend',struct()); 41 | o.seas = getopt(o,'seas',struct()); 42 | o.ar = getopt(o,'ar',struct()); 43 | 44 | o.level = getopt(o,'level',struct()); 45 | 46 | o.level.sig = getopt(o.level,'sig',0); 47 | o.level.clen = getopt(o.level,'clen',0); 48 | o.level.tau = getopt(o.level,'tau',0); 49 | 50 | o.trend.sig = getopt(o.trend,'sig',0.001); 51 | o.trend.clen = getopt(o.trend,'clen',5); 52 | o.trend.tau = getopt(o.trend,'tau',0); 53 | o.seas.sig = getopt(o.seas,'sig',0.001); 54 | o.seas.clen = getopt(o.seas,'clen',5); 55 | o.seas.tau = getopt(o.seas,'tau',0); 56 | o.ar.sig = getopt(o.ar,'sig',0.001); 57 | o.ar.clen = getopt(o.ar,'clen',5); 58 | o.ar.tau = getopt(o.ar,'tau',0); 59 | 60 | o.solar = getopt(o,'solar',0); 61 | o.qbo = getopt(o,'qbo',0); 62 | 63 | o.refit = getopt(o,'refit',0); 64 | 65 | 66 | if o.solar 67 | X = solarfun(t,1); 68 | % fix missing solar, at the end, hopefully 69 | ii = find(isnan(X)); 70 | y(ii,:) = []; 71 | s(ii,:) = []; 72 | t(ii,:) = []; 73 | X(ii,:) = []; 74 | end 75 | 76 | if o.qbo 77 | X = [X,qbofun(t,1)]; 78 | ii = find(isnan(X(:,2))); 79 | y(ii,:) = []; 80 | s(ii,:) = []; 81 | t(ii,:) = []; 82 | X(ii,:) = []; 83 | 84 | end 85 | 86 | % not used 87 | %o.opt = 0; 88 | %o.fitv = 0; % 89 | %o.maxfuneval = 1000; 90 | %o.winds = [0, 1, 2*ones(1,o.trig*2), ones(1,length(o.arphi)>0)*3]; 91 | %o.fitar = length(o.arphi)>0; % 92 | 93 | % generate system matrices 94 | [G0,F0] = dlmgensys(o); 95 | p = size(y,2); 96 | G = kron(G0,eye(p)); 97 | F = kron(F0,eye(p)); 98 | n = size(y,1); 99 | q = size(F,2); 100 | q0 = size(F0,2); 101 | nx = size(X,2); 102 | 103 | 104 | % distance based covariance matrix needed for multicolumn data, 105 | % correlation beween columns 106 | distmat = toeplitz(0:p-1); 107 | cfun = @(d,phi) exp(-abs(d)/phi); 108 | %cfun = @(d,phi) exp(-0.5.*(d/phi).^2); 109 | cmatfun = @(sig,phi,tau) sig.^2*cfun2(distmat,phi) + eye(size(distmat))*tau.^2; 110 | 111 | % generate full matrices for all columns 112 | W1 = zeros(p,p); % level 113 | W1 = cmatfun(o.level.sig,o.level.clen,o.level.tau); % trend 114 | W2 = cmatfun(o.trend.sig,o.trend.clen,o.trend.tau); % trend 115 | W3 = cmatfun(o.seas.sig,o.seas.clen, o.seas.tau); % seas 116 | stack = @(a,b)[a,zeros(size(a,1),size(b,2));zeros(size(b,1),size(a,2)),b]; 117 | W = stack(W1,W2); 118 | for i=1:o.trig 119 | W = stack(W,W3); 120 | W = stack(W,W3); 121 | end 122 | if length(o.arphi)>0 % AR 123 | W4 = cmatfun(o.ar.sig,o.ar.clen,o.ar.tau); 124 | W = stack(W,W4); 125 | end 126 | 127 | % for the proxies 128 | for i=1:nx 129 | W = stack(W,W1); % add W 130 | G(q+1:q+p,q+1:q+p) = eye(p); % grow G, F is taken care of by dlmsmo (fix this) 131 | q = q + p; % p more states needed 132 | end 133 | 134 | % initial values 135 | x0 = zeros(q,1); 136 | x0(1:p) = y(1,:); 137 | x0(find(isnan(y(1,:)))) = 0; 138 | C0 = eye(q,q); 139 | 140 | % run dlmsmo 141 | out = dlmsmo(y,F,s,x0,G,W,C0, X, 0, 1, 0); 142 | % again, with new initial values, as in dlmfit 143 | if o.refit 144 | x0 = out.x(:,1); 145 | C0 = 1*squeeze(out.C(:,:,1)); 146 | out = dlmsmo(y,F,s,x0,G,W,C0, X, 0, 1, 0); 147 | end 148 | 149 | % save some extra elements 150 | if isfield(o,'label') 151 | out.label = o.label; 152 | end 153 | 154 | out.ys = ys; 155 | out.y = y; 156 | out.s = s; 157 | out.time = t; 158 | out.options = o; 159 | 160 | p = size(out.F,1); 161 | 162 | % find out the indexes of various state elements, level, seas, ar, X 163 | if p==1 164 | ii = 1; 165 | out.inds.level = ii; 166 | ii = ii + o.order + 1; 167 | out.inds.seas = ii:ii+2*o.trig-1; 168 | ii = ii+2*o.trig; 169 | out.inds.ar = ones(length(o.arphi),1)+ii-1; 170 | ii = length(o.arphi) + ii; 171 | if size(X,2)>0 172 | out.inds.X = ii:ii+size(X,2)-1; 173 | else 174 | out.inds.X = []; 175 | end 176 | else 177 | 178 | ii = 1; 179 | out.inds.level = reshape(ii:p,p,1); 180 | ii = ii*p + o.order*p + 1; 181 | out.inds.seas = ii:ii+(2*o.trig)*p-1; 182 | out.inds.seas = reshape(out.inds.seas,p,numel(out.inds.seas)/p); 183 | ii = ii+(2*o.trig)*p; 184 | % out.inds.ar = ones(1,length(o.arphi)*p)+ii-1; 185 | out.inds.ar = ii:(length(o.arphi)*p)+ii-1; 186 | out.inds.ar = reshape(out.inds.ar,p,numel(out.inds.ar)/p); 187 | ii = length(o.arphi)*p + ii; 188 | if size(X,2)>0 189 | out.inds.X = ii:ii+size(X,2)*p-1; 190 | out.inds.X = reshape(out.inds.X,p,numel(out.inds.X)/p); 191 | else 192 | out.inds.X = []; 193 | end 194 | 195 | 196 | end 197 | 198 | function y=cfun2(d,phi) 199 | %y = exp(-abs(d)/phi); 200 | y = exp(-0.5*d.^2./phi.^2); 201 | y(isnan(y))=1; 202 | 203 | -------------------------------------------------------------------------------- /dlmsmo.m: -------------------------------------------------------------------------------- 1 | function out = dlmsmo(y,F,V,x0,G,W,C0,X, sample, smooth, lik) 2 | %DLMSMO DLM smoothing 3 | % out = dlmsmo(y,F,V,x0,G,W,C0, X) 4 | % Uses Kalman smoother for dynamic linear state space model: 5 | % 6 | % y(t) = F*x(t) + v 7 | % x(t) = G*x(t-1) + w, for t=1:n 8 | % 9 | % with 10 | % 11 | % x(1) ~ N(x0,C0), v ~ N(0,V), and w ~ N(0,W). 12 | % 13 | % Input: 14 | % y observations, n*p 15 | % F observation operator, p*(m-nx) 16 | % V observation uncertainty std, n*p 17 | % x0 initial state, m*1 18 | % G system evolution matrix, m*m 19 | % W model error covariance, m*m 20 | % C0 initial state uncertainty covariance, m*m 21 | % X external covariate matrix, n*nx (optional) 22 | % 23 | % Output: 24 | % out.x smoothed state m*n 25 | % out.C smoother covariance m*m*n 26 | % etc... 27 | 28 | % Marko Laine 29 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 30 | 31 | if nargin < 9 32 | sample = 1; % generate also one sampled state for MCMC 33 | end 34 | 35 | if nargin < 10 36 | smooth = 1; % calculate smoother, also, not needed for likelihood 37 | end 38 | 39 | if nargin < 11 40 | lik = 1; % calculate the likelihood (and chol(Cp)), can be slow in large models 41 | end 42 | 43 | if nargin < 8 || isempty(X) 44 | X = zeros(size(y,1),0); 45 | end 46 | 47 | [p,m] = size(F); % n_series, n_states 48 | n = size(y,1); % n_observations 49 | m = m + size(X,2)*p; % covariates, i.e. the proxy variables 50 | 51 | x = zeros(m,n); % states 52 | C = zeros(m,m,n); % state uncertainty covariances 53 | 54 | % initial values 55 | x(:,1) = x0; 56 | C(:,:,1) = C0; 57 | 58 | % collect these also 59 | Cp = zeros(p,p,n); % obs prediction uncertainty 60 | v = zeros(p,n); % prediction residuals 61 | K = zeros(m,p,n); % Kalman gain 62 | 63 | % Kalman filter recursion, now x is the one step prediction mean 64 | for i=1:n 65 | FF = [F,kron(X(i,:),eye(p))]; 66 | ig = not(isnan(y(i,:))); % non NaN y 67 | v(ig,i) = y(i,ig)' - FF(ig,:)*x(:,i); 68 | Cp(:,:,i) = FF*C(:,:,i)*FF'; 69 | Cp(ig,ig,i) = Cp(ig,ig,i) + diag(V(i,ig).^2); 70 | % if any(diag(Cp(:,:,i))<=0), keyboard;end 71 | Cp(:,:,i) = triu(Cp(:,:,i)) + triu(Cp(:,:,i),1)'; % fix symmetry ... 72 | K(:,ig,i) = G*C(:,:,i)*FF(ig,:)'/Cp(ig,ig,i); 73 | if i 4 | 5 | 6 | Classical Nile data

Classical Nile data

Here we fit the classical Nile river flow data

y = [1120 1160  963 1210 1160 1160  813 1230 1370 1140  995  935 ...
 70 |      1110  994 1020  960 1180  799  958 1140 1100 1210 1150 1250 ...
 71 |      1260 1220 1030 1100  774  840  874  694  940  833  701  916 ...
 72 |      692 1020 1050  969  831 726  456  824  702 1120 1100  832  764 ...
 73 |      821  768  845 864  862 698  845  744  796 1040  759  781  865 ...
 74 |      845  944  984  897  822 1010  771  676  649  846  812  742  801 ...
 75 |      1040  860  874 848  890  744  749  838 1050  918  986  797  923 ...
 76 |      975  815 1020  906  901 1170  912  746  919  718  714  740]';
 77 | 
 78 | t = (1871:1970)'; % time
 79 | 

Observation and model errors match those in Petris et al. (2009)

s = sqrt(15100);
 80 | w = sqrt([755 755]);
 81 | 

Fit the DLM model

out = dlmfit(y,s,w);
 82 | 
figure(3);
 83 | dlmplotfit(out,t);
 84 | title('Smoothed Nile data')
 85 | 
figure(2);
 86 | dlmplotdiag(out,t);
 87 | 
-------------------------------------------------------------------------------- /docs/ex/dlmdemo3.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | DLM demo no 3, synthetic multivariate time series

DLM demo no 3, synthetic multivariate time series

Test the dlmsmo code with multivariate series with missing observations.

generate system matrices

[G,F] = dlmgensys(struct('order',2,'trig',2));
 70 | 

generate observations for the first series

m = size(G,2);
 71 | p = size(F,1);
 72 | nobs = 100;
 73 | t = (1:nobs)';
 74 | 
 75 | W = zeros(m,m); W(2,2) = 0.0004^2; for i=4:7 ; W(i,i)=0.0005^2; end
 76 | V = 0.8; % obs error std
 77 | x = zeros(nobs,m);
 78 | y = zeros(nobs,p);
 79 | 
 80 | x(1,:) = [0 0.0001 0.0003 1 1 2 1]; % initial values
 81 | for i=2:nobs
 82 |   x(i,:) = x(i-1,:)*G' + randn(1,m).*sqrt(diag(W))';
 83 |   y(i,:) = x(i,:)*F' + randn(1,p)*V;
 84 | end
 85 | 

generate second series

GG = kron(eye(2),G);
 86 | FF = kron(eye(2),F);
 87 | WW = diag([diag(W);diag(W)]);
 88 | VV = ones(nobs,2)*V;
 89 | yy = [y,y+5] + randn(nobs,2)*V;
 90 | x0 = zeros(m+m,1);
 91 | C0 = eye(m+m);
 92 | 

add some missing observations

yy(10,1) = NaN;
 93 | yy(50,:) = NaN;
 94 | yy(20:30,1) = NaN;
 95 | yy(end-9:end,2) = NaN;
 96 | 
dlm = dlmsmo(yy,FF,VV,x0,GG,WW,C0);
 97 | 
figure(1); clf
 98 | confband(t,dlm.x(1,:)',dlm.xstd(:,1));
 99 | hold on
100 | confband(t,dlm.x(8,:)',dlm.xstd(:,8));
101 | plot(t,yy,'.-')
102 | hold off
103 | title('two dimensional time serie with missing observations')
104 | xlabel('time'); ylabel('y');
105 | 
-------------------------------------------------------------------------------- /docs/ex/dlmdemo2.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | DLM demo no 2, testing DLM functions

DLM demo no 2, testing DLM functions

Generate seasonal data and fit DLM model with 12 seasons.

Data

t = (1:1:(6*12))'; % time
 70 | n = length(t);
 71 | s = 0.1; % obs error std
 72 | y = 2 + 0.5*(t-0)/12.*((t-0)<2*12)    + ...
 73 |         0.5*(2*12)/12.*((t-0)>=2*12)  + ...
 74 |         0.8*sin((t-0)/12*2*pi) + ...
 75 |      randn(n,1)*s;
 76 | 
figure(1); clf
 77 | plot(t,y,'o-'); xlabel('time'); ylabel('y'); title('observations');grid;
 78 | 

Model error diagonal, first non zero values.

w123 = [0.0000,3.1e-5,1e-8,1e-8,1e-8,1e-8];
 79 | 

Options for dlmfit function. Use harmonic functions with 2 components and 12 seasons. Optimize some variance parameters using maximum likelihood.

clear options
 80 | options.ns = 12;
 81 | options.trig = 2;
 82 | options.opt = 1;
 83 | options.winds = [0 1 2 2 2 2];
 84 | 

DLM fit.

out = dlmfit(y,s,w123,[],[],[],options);
 85 | 
 
 86 |  Iteration   Func-count     min f(x)         Procedure
 87 |      0            1          56.4488         
 88 |      1            3          56.4488         initial simplex
 89 |      2            5          48.2807         expand
 90 |      3            7          33.1171         expand
 91 |      4            9         -166.988         expand
 92 |      5           11         -214.797         expand
 93 |      6           13         -214.797         contract outside
 94 |      7           15         -214.797         contract inside
 95 |      8           17         -214.797         contract inside
 96 |      9           19         -216.244         contract inside
 97 |     10           21         -217.027         contract inside
 98 |     11           22         -217.027         reflect
 99 |     12           24         -217.027         contract inside
100 |     13           26         -217.027         contract inside
101 |     14           28         -217.027         contract inside
102 |     15           30         -217.044         contract inside
103 |     16           31         -217.044         reflect
104 |     17           33         -217.044         contract inside
105 |     18           35         -217.045         contract outside
106 |     19           37         -217.046         contract inside
107 |     20           38         -217.046         reflect
108 |     21           40         -217.046         contract inside
109 |     22           42         -217.046         contract inside
110 |     23           44         -217.046         contract inside
111 |     24           46         -217.046         contract inside
112 |     25           48         -217.046         contract outside
113 |     26           50         -217.046         contract inside
114 |     27           51         -217.046         reflect
115 |     28           53         -217.046         contract inside
116 |     29           54         -217.046         reflect
117 |     30           56         -217.046         contract inside
118 |     31           58         -217.046         contract outside
119 |     32           60         -217.046         contract inside
120 |     33           61         -217.046         reflect
121 |     34           63         -217.046         contract inside
122 |     35           65         -217.046         contract inside
123 |     36           67         -217.046         contract inside
124 |     37           68         -217.046         reflect
125 |     38           70         -217.046         contract inside
126 |     39           71         -217.046         reflect
127 |     40           73         -217.046         contract inside
128 |     41           75         -217.046         contract outside
129 |     42           77         -217.046         contract inside
130 |     43           78         -217.046         reflect
131 |     44           80         -217.046         contract inside
132 |     45           82         -217.046         contract inside
133 |     46           84         -217.046         contract outside
134 |     47           86         -217.046         contract inside
135 |     48           88         -217.046         contract inside
136 |     49           90         -217.046         contract inside
137 |     50           94         -217.046         shrink
138 |     51           98         -217.046         shrink
139 |     52          102         -217.046         shrink
140 |     53          104         -217.046         contract outside
141 |     54          106         -217.046         contract outside
142 |     55          110         -217.046         shrink
143 |     56          112         -217.046         contract inside
144 |     57          116         -217.046         shrink
145 |  
146 | Optimization terminated:
147 |  the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04 
148 |  and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-04 
149 | 
150 | 
151 | woptv =
152 | 
153 |   0x1 empty double column vector
154 | 
155 | 
156 | woptw =
157 | 
158 |     0.0085116
159 |    1.3657e-09
160 | 
161 | 
162 | woptg =
163 | 
164 |   0x1 empty double column vector
165 | 
166 | 

Default plots.

dlmplot(out);
167 | 
-------------------------------------------------------------------------------- /dlmfit.m: -------------------------------------------------------------------------------- 1 | function out = dlmfit(y,s,wdiag,x0,C0, X, options) 2 | %DLMFIT Fit DLM time series model 3 | % Fits dlm time series model with local level, trend, seasonal, and proxies 4 | % out = dlmfit(y,s,wdiag,x0,C0, X, options) 5 | % Input: 6 | % y time series, n*p 7 | % s obs uncertainty, n*p or 1*1 8 | % w sqrt of first diagonal entries of the model error matrix W 9 | % x0 initial state m*1 (optional, i.e. can be empty) 10 | % C0 initial state uncertainty covariance matrix m*m (optional) 11 | % X covariate variables n*q (optional) 12 | % options structure 13 | % order 14 | % fullseas 15 | % trig 16 | % ns 17 | % opt 18 | % mcmc 19 | % Output: 20 | % out. 21 | 22 | % Marko Laine 23 | % $Revision: 0.0 $ $Date: 2013/07/12 12:00:00 $ 24 | 25 | if nargin < 6 26 | X=[]; % covariates, aka proxies 27 | end 28 | 29 | if nargin < 7 30 | options.trig = 0; 31 | options.opt = 0; 32 | options.mcmc = 0; 33 | end 34 | 35 | % compatibility for older version 36 | if isfield(options,'fullseas'), options.seas=options.fullseas; end 37 | 38 | if not(isfield(options,'order')), options.order=1; end 39 | if not(isfield(options,'trig')), options.trig=0; end 40 | if not(isfield(options,'seas')), options.seas=0; end 41 | if options.trig>0, options.seas=0; end 42 | if not(isfield(options,'fullseas')), options.fullseas=options.seas; end 43 | 44 | if not(isfield(options,'ns')), options.ns=12; end % number of seasons 45 | 46 | if not(isfield(options,'mcmc')), options.mcmc=0; end 47 | if not(isfield(options,'opt')), options.opt=0; end 48 | if not(isfield(options,'maxfuneval')), options.maxfuneval=400; end 49 | 50 | % fit V factor? 51 | if not(isfield(options,'fitv')), options.fitv=0; end % see also options.vcv 52 | 53 | if not(isfield(options,'winds')), options.winds=[]; end % 54 | if not(isfield(options,'logscale')), options.logscale=1; end % 55 | 56 | if not(isfield(options,'spline')), options.spline=0; end % test 57 | 58 | % These are the defaults used in the dlm acp paper 59 | if not(isfield(options,'varcv')), options.varcv=[1 1 1 1]; end 60 | if not(isfield(options,'vcv')), options.vcv=0.5; end % V factor prior CV 61 | if not(isfield(options,'nsimu')), options.nsimu=5000; end 62 | 63 | [G,F] = dlmgensys(options); % generate system matrises 64 | 65 | [p,m] = size(F); % series states 66 | n = length(y); % nobs 67 | 68 | % add covariates to system matrix G 69 | if not(isempty(X)) 70 | kk = size(X,2); 71 | G(m+1:m+kk,m+1:m+kk) = eye(kk); 72 | m = m+kk; 73 | end 74 | 75 | V = ones(n,p).*s; % V is matrix of std's 76 | W = zeros(m,m); % model error 77 | 78 | % input wdiag has diagonal std of W 79 | for i=1:length(wdiag); W(i,i) = wdiag(i).^2; end 80 | 81 | % spline 82 | if options.order==1 & options.spline 83 | W(1:2,1:2) = wdiag(2).^2 .* [1/3 1/2;1/2 1]; 84 | end 85 | 86 | 87 | % try to find sensible initial values (FIX THIS) 88 | if nargin < 4 || isempty(x0) 89 | x0 = zeros(m,1); % initial 90 | x0(1) = meannan(y(1:ceil(options.ns),:)); % how about p>1 (not yet) assume x0(1) is the level 91 | % x0(2) = (y(13)-y(1))/12; % crude estimate 92 | % if options.trig==0 93 | % x0(3) = sumnan(-y(1:11,:)); % -,,- 94 | % end 95 | end 96 | if nargin<5||isempty(C0) 97 | C0diag = ones(1,m)*(abs(x0(1))*0.5).^2; 98 | C0diag(C0diag==0) = 1e+7; 99 | C0 = diag(C0diag); 100 | end 101 | % fit, and refit to iterate the initial values 102 | out = dlmsmo(y,F,V,x0,G,W,C0, X, 0); 103 | x0 = out.x(:,1); 104 | C0 = 100*squeeze(out.C(:,:,1)); 105 | out = dlmsmo(y,F,V,x0,G,W,C0, X); 106 | 107 | %% optimization and MCMC calculations 108 | 109 | if options.opt 110 | if isfield(options,'fitfun') 111 | % use user given fitfun that returs dlm object 112 | out = options.fitfun(out,options); 113 | else 114 | % default optimization for a V and W 115 | out = dlm_dooptim(out,options); 116 | end 117 | end 118 | 119 | if options.mcmc 120 | if isfield(options,'mcmcfun') 121 | out = options.mcmcfun(out,options); 122 | else 123 | % default MCMC for W and V 124 | out = dlm_domcmc(out,options); 125 | end 126 | end 127 | 128 | out.s = s; % save original obs std also 129 | out.options = options; 130 | out.class = 'dlmfit'; 131 | 132 | %% some helper functions 133 | 134 | function out = dlm_dooptim(dlm,options) 135 | % this optimizes some parameters defining the DLM model 136 | % the costfun is at the end 137 | 138 | if options.fitv > 0; 139 | vinds = 1; 140 | else 141 | vinds = []; 142 | end 143 | 144 | % winds = map from diag(W) to optimized parameter 145 | winds = options.winds; 146 | nw = max(winds); 147 | 148 | if isfield(options,'fitar') && options.fitar>0 149 | ginds = findarinds(options); 150 | else 151 | ginds = []; 152 | end 153 | 154 | zfun = @(x) dlm_costfun(x,dlm,vinds,winds,ginds); 155 | 156 | W = dlm.W; 157 | V = dlm.V; 158 | G = dlm.G; 159 | 160 | if length(vinds)>0; 161 | v0 = 1; 162 | else 163 | v0 = []; 164 | end 165 | 166 | w0 = zeros(nw,1); 167 | for i=1:length(w0) 168 | ii=find(winds==i,1); 169 | w0(i)=sqrt(W(ii,ii)); 170 | end 171 | 172 | if length(ginds)>0 173 | g0 = options.arphi(:); 174 | else 175 | g0 = []; 176 | end 177 | 178 | w00 = [log([v0;w0]);g0]; 179 | inds = [ones(size(v0));ones(size(w0))*2;ones(size(g0))*3]; 180 | 181 | oo = optimset('disp','iter','maxfuneval',options.maxfuneval); 182 | wopt = fminsearch(zfun,w00,oo); 183 | 184 | woptv = exp(wopt(inds==1)) 185 | woptw = exp(wopt(inds==2)) 186 | woptg = wopt(inds==3) 187 | 188 | if length(vinds)>0; 189 | V = V.*woptv; 190 | end 191 | 192 | for i=1:length(winds); 193 | if winds(i)>0; 194 | W(i,i) = woptw(winds(i)).^2; 195 | end; 196 | end 197 | 198 | arinds = findarinds(options); 199 | if length(ginds)>0 200 | G(arinds,arinds(1)) = woptg; 201 | end 202 | 203 | out = dlmsmo(dlm.y,dlm.F,V,dlm.x0,G,W,dlm.C0,dlm.XX); 204 | 205 | function out = dlm_costfun(x,dlm,vinds,winds,ginds) 206 | % Helper function for dlm parameter fitting 207 | W = dlm.W; 208 | V = dlm.V; 209 | G = dlm.G; 210 | 211 | nv = length(vinds); 212 | nw = max(winds); 213 | ng = length(ginds); 214 | 215 | if nv>0; 216 | V=V.*exp(x(1)); 217 | end 218 | for i=1:length(winds) 219 | if winds(i)>0; 220 | W(i,i)=exp(x(winds(i)+nv)).^2; 221 | end 222 | end 223 | if ng>0 224 | G(ginds,ginds(1)) = x(nv+nw+1:end); 225 | end 226 | 227 | if exist('dlmmex') == 3 228 | % mex boosted likelihood calculations 229 | out = dlmmex(dlm.y,dlm.F,V,dlm.x0,G,W,dlm.C0,dlm.XX); 230 | else 231 | out = getfield(dlmsmo(dlm.y,dlm.F,V,dlm.x0,G,W,dlm.C0,dlm.XX,0,0),'lik'); 232 | end 233 | 234 | function out = dlm_domcmc(dlm,options) 235 | % this does MCMC for model parameters 236 | 237 | % fit a coefficient for obs error 238 | if options.fitv > 0; 239 | vinds = 1; 240 | else 241 | vinds = []; 242 | end 243 | 244 | % winds = map from diag(W) to optimized parameter 245 | winds = options.winds; 246 | nw = max(winds); 247 | 248 | if isfield(options,'fitar') && options.fitar>0 249 | ginds = findarinds(options); 250 | else 251 | ginds = []; 252 | end 253 | 254 | % save current values 255 | W = dlm.W; 256 | V = dlm.V; 257 | G = dlm.G; 258 | 259 | % initial values 260 | if length(vinds)>0; 261 | v0 = 1; 262 | else 263 | v0 = []; 264 | end 265 | 266 | w0 = zeros(nw,1); 267 | for i=1:length(w0) 268 | ii=find(winds==i,1); 269 | w0(i)=sqrt(W(ii,ii)); 270 | end 271 | w0ini = w0; 272 | % use option for initial values, must be of length w0 273 | if isfield(options,'varini') 274 | if length(options.varini) == length(w0) 275 | w0ini = options.varini(:); 276 | else 277 | error('options.varini length does not match') 278 | end 279 | end 280 | 281 | if length(ginds)>0 282 | g0 = options.arphi(:); 283 | else 284 | g0 = []; 285 | end 286 | 287 | w00 = [log([v0;w0]);g0]; 288 | inds = [ones(size(v0));ones(size(w0))*2;ones(size(g0))*3]; 289 | 290 | if options.logscale 291 | ffun=@(x)log(x); 292 | bfun=@(x)exp(x); 293 | parmin = -Inf; 294 | else 295 | ffun=@(x)(x); 296 | bfun=@(x)(x); 297 | parmin = 0; 298 | end 299 | 300 | npar = length(w00); 301 | p = cell(0); 302 | i1 = 0; 303 | for i=1:length(v0) 304 | i1 = i1+1; 305 | p{i1} = {'Vfact',ffun(v0(i)),parmin,Inf,NaN,options.vcv(i)}; 306 | end 307 | for i=1:length(w0) 308 | i1 = i1+1; 309 | ii = find(winds==i,1); 310 | % p{i1} = {sprintf('w%d',ii),ffun(w0(i)),parmin,Inf,NaN,options.varcv(i)}; 311 | p{i1} = {sprintf('w%d',ii),ffun(w0ini(i)),parmin,Inf,ffun(w0(i)),options.varcv(i)}; 312 | end 313 | for i=1:length(g0) 314 | i1 = i1+1; 315 | % bound [0,1] for AR rho is fixed here for now 316 | p{i1} = {sprintf('g%d',i),g0(i),0,1,NaN,options.gcv(i)}; 317 | end 318 | 319 | m = struct; o = struct; 320 | if options.logscale 321 | m.ssfun = @(th,d) fitfun_mcmc(th,dlm,vinds,winds,ginds); 322 | m.priorfun = @(th,m,s) sum(((th-m)./s).^2); % normal prior 323 | m.priortype = 1; % 324 | else 325 | m.ssfun = @(th,d) error('not defined yet'); 326 | m.priorfun = @(th,m,s) sum((log(th./m)./s).^2); % lognormal prior 327 | m.priortype=-1; % for lognormal prior in densplot 328 | end 329 | o.qcov = eye(length(w00)); 330 | i1 = 0; 331 | for i=1:length(v0) 332 | i1 = i1+1; 333 | o.qcov(i1,i1) = 0.1; % proposal for V fact fixed here 334 | end 335 | for i=1:length(w0) 336 | i1 = i1+1; 337 | o.qcov(i1,i1) = abs(p{i1}{2})*0.002; % W diag paramrs proposal 338 | if o.qcov(i1,i1) == 0, o.qcov(i1,i1) = 1; end 339 | end 340 | for i=1:length(g0) 341 | i1 = i1+1; 342 | o.qcov(i1,i1) = 0.01; % propsal for AR rhos 343 | end 344 | 345 | o.nsimu = options.nsimu; 346 | o.method = 'am'; 347 | o.adaptint = 100; 348 | o.initqcovn = 200; 349 | o.verbosity = 1; 350 | [res,chain,~,sschain] = mcmcrun(m,[],p,o); 351 | 352 | wopt = mean(chain(fix(size(chain,1)/2):end,:)); % use the last half 353 | 354 | woptv = bfun(wopt(inds==1)) 355 | woptw = bfun(wopt(inds==2)) 356 | woptg = wopt(inds==3) 357 | 358 | if length(vinds)>0; 359 | V = V.*woptv; 360 | end 361 | 362 | for i=1:length(winds); 363 | if winds(i)>0; 364 | W(i,i) = woptw(winds(i)).^2; 365 | end; 366 | end 367 | 368 | arinds = findarinds(options); 369 | if length(ginds)>0 370 | G(arinds,arinds(1)) = woptg; 371 | end 372 | 373 | out = dlmsmo(dlm.y,dlm.F,V,dlm.x0,G,W,dlm.C0,dlm.XX); 374 | 375 | if options.logscale % scale chain back to stds 376 | ii = (inds ==1|inds==2); 377 | chain(:,ii) = bfun(chain(:,ii)); 378 | res.prior(ii,1)=exp(res.prior(ii,1)); 379 | res.priorfun = @(th,m,s) sum((log(th./m)./s).^2); 380 | res.priortype=-1; 381 | end 382 | 383 | out.res = res; 384 | out.chain = chain; 385 | out.sschain = sschain; 386 | out.winds = winds; 387 | out.vinds = vinds; 388 | out.ginds = ginds; 389 | 390 | 391 | function out = fitfun_mcmc(x,dlm,vinds,winds,ginds) 392 | % Helper function for dlm parameter fitting 393 | W = dlm.W; 394 | V = dlm.V; 395 | G = dlm.G; 396 | 397 | nv = length(vinds); 398 | nw = max(winds); 399 | ng = length(ginds); 400 | 401 | 402 | if nv>0; 403 | V=V.*exp(x(1)); 404 | end 405 | for i=1:length(winds) 406 | if winds(i)>0; 407 | W(i,i)=exp(x(winds(i)+nv)).^2; 408 | end 409 | end 410 | if ng>0 411 | G(ginds,ginds(1)) = x(nv+nw+1:end); 412 | end 413 | 414 | if exist('dlmmex') == 3 415 | % mex boosted likelihood calculations 416 | out = dlmmex(dlm.y,dlm.F,V,dlm.x0,G,W,dlm.C0,dlm.XX); 417 | else 418 | out = getfield(dlmsmo(dlm.y,dlm.F,V,dlm.x0,G,W,dlm.C0,dlm.XX,0,0),'lik'); 419 | end 420 | 421 | function i = findarinds(options) 422 | % find AR indeces 423 | if not(isfield(options,'arphi')); 424 | i = []; 425 | return; 426 | end 427 | nar = length(options.arphi); 428 | i = 1; 429 | i = i + options.order + 1; 430 | if options.fullseas==1 431 | i = i + 11; 432 | elseif options.trig>0 433 | i = i+min(options.ns-1,options.trig*2); 434 | end 435 | 436 | i = i:i+nar-1; 437 | -------------------------------------------------------------------------------- /docs/ex/ozonedemo.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Stratospheric ozone time series trend analysis

Stratospheric ozone time series trend analysis

This demo reproduces calculation for article: Laine, M., Latva-Pukkila, N., Kyrölä, E., Analyzing time varying trends in stratospheric ozone time series using state space approach, Atmospheric Chemistry and Physics Discussion, 13, pages 20503-20530, 2013. doi:10.5194/acpd-13-20503-2013

First load example data set. Stratospheric ozone observations from two satellite instruments SAGE II and GOMOS. The original satellite observations has been combined and processed to produce averaged zonal data for different altitudes. Here we use monthly avarages between 45 km to 55 km and 40N to 50N for years 1984 to 2012.

load ozonedata.mat % data, label
 70 | 
 71 | time = data(:,1); % time in years from 1984 to 2012
 72 | y = data(:,2); % ozone density [1/cm^3]
 73 | s = data(:,3); % uncertainty standard deviation for y
 74 | X = data(:,4:6); % proxies
 75 | 

We scale y for numerical stability.

ys = stdnan(y);
 76 | yy = y./ys;
 77 | ss = s./ys;
 78 | 

Prior means for some components of W, the model error matrix.

ym = meannan(yy);  % mean observations
 79 | wtrend = abs(ym)*0.00005; % trend std
 80 | wseas  = abs(ym)*0.015;   % seasonal component std
 81 | w0 = [0 wtrend wseas wseas wseas wseas];
 82 | 

Calculate the DLM smoother solution, do MCMC over some components in the matrix W.

options = struct('trig',2,'mcmc',1,'nsimu',2000,'winds',[0 1 2 2 2 2]);
 83 | dlm = dlmfit(yy,ss,w0,[],[],X,options);
 84 | 
Sampling these parameters:
 85 | name   start [min,max] N(mu,s^2)
 86 | w2: -7.48787 [-Inf,Inf] N(-7.48787,1^2)
 87 | w3: -1.78409 [-Inf,Inf] N(-1.78409,1^2)
 88 | 
 89 | woptv =
 90 | 
 91 |   1x0 empty double row vector
 92 | 
 93 | 
 94 | woptw =
 95 | 
 96 |    0.00063132      0.22512
 97 | 
 98 | 
 99 | woptg =
100 | 
101 |   1x0 empty double row vector
102 | 
103 | 
figure(1);
104 | dlmplotfit(dlm, time, ys)
105 | title(label);xlabel('time');ylabel('average O3 density [cm^{-3}]')
106 | 
figure(2);
107 | dlmplotdiag(dlm, time, ys)
108 | 

Produce sample from the model states using dlmsmosam. It accounts the posterior uncertainty in W using the MCMC chain in dlm.chain.

nsam = 200; % number of sampled to draw from the posterior
109 | dlm_sample = dlmsmosam(dlm,nsam);
110 | 

Draw dome sample realizations of the level component over the plot in Figure 2.

figure(1);
111 | hold on
112 | for i=1:5:nsam
113 |   plot(time,ys*squeeze(dlm_sample(1,:,i)),'-')
114 | end
115 | hold off
116 | 

The next figure shows prior and posterior distributions for standard deviations from the diagonal of model error matrix W.

figure(3); clf
117 | mcmcplot(dlm.chain,[],dlm.res,'denspanel',2);
118 | subplot(2,1,1);title('prior and posterior for variance parameters');xlabel('parameter w(2,2)')
119 | subplot(2,1,2);title('');xlabel('parameter w(3,3)')
120 | 

Sample trend statistics form DLM sample. We calculate 10 year running trend.

nyear = 10;
121 | tsamp = ys*squeeze(dlm_sample(1,:,:)); % sample of levels
122 | ysm = mean(tsamp(:));                   % their mean
123 | ysf = 1/(ysm*nyear)*100;      % scale factor to get % change / 10 year
124 | t10 = mean((tsamp(nyear*12+1:end,:)-tsamp(1:end-nyear*12,:))')*ysf; % mean trend
125 | s10 = std((tsamp(nyear*12+1:end,:)-tsamp(1:end-nyear*12,:))')*ysf;  % std in the sample
126 | time10 = time(fix(nyear/2)*12+1:end); time10 = time10(1:length(t10)); % time axis for plot
127 | 
figure(4); clf
128 | confband(time10,t10,s10);grid;
129 | xlim([time(1),time(end)]); % match axis to other plots
130 | title('10 year trend');
131 | ylabel('% change / year')
132 | 
-------------------------------------------------------------------------------- /docs/ex/dlmdemo1.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | dlmdemo1

DLM demo no 1

Generate synthetic and ideal data and fit a DLM smoother. The command dlmgensys generates system evolution matrix G and obs operator F. We use local level and trend model with 12 seasons.

[G,F] = dlmgensys(struct('order',1,'fullseas',1,'ns',12));
 70 | % p = number of data sets = 1,
 71 | % m = number of internal states = 13
 72 | [p,m] = size(F);
 73 | 

Generate data.

t = (1:1:(6*12))'; % time
 74 | n = length(t);
 75 | s = 0.1; % obs error std
 76 | V = ones(n,p)*s; % V is matrix of std's
 77 | x0 = [0;0.001;sin((1:11)/12*pi*2)']; % initial state
 78 | C0 = 0.02*eye(m)*s^2; % initial state uncertainty
 79 | W = zeros(m); % "model error"
 80 | W(1,1) = 0.000002^2;
 81 | W(2,2) = 0.002.^2;
 82 | W(3,3) = 0.02.^2;
 83 | 

Observations are generated using the state space recursion.

y = zeros(n,1);
 84 | x = x0;
 85 | for i=1:n
 86 |   y(i) = F*x + randn(1,1)*s;
 87 |   x = G*x + randn(m,1).*sqrt(diag(W));
 88 | end
 89 | 

Function dlmsmo calculates the estimated states using Kalman smoother.

out = dlmsmo(y,F,V,x0,G,W,C0);
 90 | x0 = out.x(:,1); % save smoothed estimate of x0
 91 | 

Plot observations and the fitted level with 95% (time wise) confidence bands.

figure(1); clf
 92 | plot(t,out.yhat,'*')
 93 | hold on
 94 | confband(t,out.x(1,:)',out.xstd(:,1));
 95 | errorbar(t,y,2*V,'ok-')
 96 | hold off
 97 | 
figure(2); clf
 98 | confband(t,out.x(2,:)',out.xstd(:,2)); grid; title('Trend')
 99 | 

MCMC

Gibbs sampling for the variance parameters using conjugate prior distributions. This takes some time.

nsimu = 1000;
100 | chain = zeros(nsimu,4);
101 | W0 = W; % prior W
102 | n0 = 5; % prior weight
103 | V0 = s;
104 | nv0 = 10;
105 | doplot = 1;
106 | plotint = 100;
107 | 
hw = waitbar(0,'MCMC running, please wait');
108 | for isimu = 1:nsimu
109 |   waitbar(isimu/nsimu,hw);
110 |   % Gibbs step for variance parameters
111 |   % residual std for V, conjugate distribution is inverse chi squared
112 |   sigV = sqrt(invchir(1,1,n+nv0,(out.ssy+V0.^2*nv0)/(n+nv0)));
113 |   V = ones(n,p)*sigV;
114 |   out = dlmsmo(y,F,V,x0,G,W,C0); % recalculate with new V
115 |   % variances in diag(W)
116 |   c = zeros(1,3); % fit 3 first variances
117 |   for i=1:3
118 |     c(i) = invchir(1,1,n+n0-1,(W0(i,i).*n0+out.ss(i))./(n+n0-1));
119 |     W(i,i) = c(i);
120 |     out = dlmsmo(y,F,V,x0,G,W,C0);  % recalculate smoother
121 |   end
122 |   chain(isimu,:) = [sigV,sqrt(c(1:3))];
123 |   if doplot & (isimu/plotint == fix(isimu/plotint))
124 |     % plot every plotint'th MCMC sampled state
125 |     figure(1);
126 |     hold on
127 |     plot(t,out.xr(1,:),'-r')
128 |     hold off
129 |   end
130 | end
131 | close(hw);
132 | 
figure(3); clf
133 | mcmcplot(chain,[],{'V','W1','W2','W3'});
134 | hold on
135 | subplot(2,2,1); h=hline(s);set(h,'linestyle','-','linewidth',2)
136 | subplot(2,2,2); h=hline(sqrt(W0(1,1)));set(h,'linestyle','-','linewidth',2)
137 | subplot(2,2,3); h=hline(sqrt(W0(2,2)));set(h,'linestyle','-','linewidth',2)
138 | subplot(2,2,4); h=hline(sqrt(W0(3,3)));set(h,'linestyle','-','linewidth',2)
139 | hold off
140 | 
141 | V = ones(n,p)*sqrt(mean(chain(:,1).^2));
142 | for i=1:3;  W(i,i) = mean(chain(:,i+1).^2); end
143 | 
144 | out = dlmsmo(y,F,V,x0,G,W,C0);
145 | 

Add estimated over the initial trend.

figure(2);
146 | ind = 2; %
147 | xxx = out.x(ind,:)';
148 | hold on
149 | plot(t,xxx)
150 | plot(t,xxx-2*out.xstd(:,ind),'g-')
151 | plot(t,xxx+2*out.xstd(:,ind),'g-')
152 | hold off
153 | 
-------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | DLM Matlab Toolbox 10 | 11 | 12 | 14 | 15 | 186 | 187 | 233 | 234 | 235 |
236 |

DLM Matlab Toolbox

237 |
238 |

Dynamic Linear Model Matlab toolbox

239 |
240 |

241 | This is a collection of Matlab files for Dynamic Linear Model calculations suitable for time series analysis. The code supplements the article M. Laine, N. Latva-Pukkila and E. Kyrölä: Analyzing time-varying trends in stratospheric ozone time series using state the space approach, in Atmospheric Chemistry and Physics 14(18), 2014, doi: 10.5194/acp-14-9707-2014. 242 |

243 | 244 |

245 | The code is provided as auxiliary material for the paper and might be useful to you if you are already familiar with Matlab and MCMC and state space analysis of time series. Some references are given at the end. 246 |

247 | 248 |

249 | The toolbox provides tools to estimate dynamic linear state space mode suitable for analysing univariate and multivariate time series. It uses Kalman filter, smoother and simulation smoother to estimate the states and Markov chain Monte Carlo (MCMC) to sample from the model error variance parameter posterior distribution. 250 |

251 | 252 |

253 | See DLM tutorial for some info on using this DLM toolbox for time series analysis. 254 |

255 |
256 |
257 | 258 |
259 |

Downloads

260 |
261 |

262 | The full Matlab code and this documentation are available from GitHub. To install the toolbox clone the folder dlm to a suitable directory and then add Matlab path to that directory. 263 |

264 | 265 |
266 | git clone https://github.com/mjlaine/dlm.git
267 | 
268 | 269 |

270 | Alternatively, you can download the whole repository as a zip file from the GitHub page or directly as 271 | https://github.com/mjlaine/dlm/archive/master.zip 272 |

273 | 274 |

275 | In addition to the code provided below, you will need my Matlab MCMC Toolbox (direct Github link). MCMC is used to infer and sample the variance parameters needed in defining the linear state space model. 276 |

277 | 278 |

279 | The code is distributed under a MIT License and comes with no warranty. The documentation is minimal at the moment. Please read the source code for details of the algorithms used. Question and suggestions are welcome. If you find the code useful, it would be kind to acknowledge me in your research articles. 280 |

281 |
282 |
283 | 284 |
285 |

Examples

286 |
287 |

288 | Some examples as Matlab demos. 289 |

290 | 291 |
292 |
Nile river flow
Classical Nile river data, file niledemo.m.
293 |
DLM demo 1
Fits Kalman smoother and does Gibbs sampling on variance parameters.
294 |
DLM demo 2
Fits synthetic time series with ML optimization.
295 |
DLM demo 3
Fits synthetic multivariate time series.
296 |
Ozone time series
Reproduces the fit used in the Ozone time series article.
297 |
298 | 299 | 300 |

301 | See also example in the the DLM tutorial. 302 |

303 |
304 |
305 | 306 | 307 |
308 |

References

309 |
310 |

311 | Laine, M., Latva-Pukkila, N., Kyrölä, E., 312 | Analyzing time-varying trends in stratospheric ozone time series using the state space approach, Atmospheric Chemistry and Physics, 14(18), pages 9707–9725, 2014. 313 | doi: 10.5194/acp-14-9707-2014. 314 |

315 | 316 |

317 | Durbin, T. and Koopman, S.,/Time Series Analysis by State Space Methods/, 318 | Oxford University Press, second edn, 2012. 319 | Google books link. 320 |

321 | 322 |

323 | Petris, G., Petrone, S., and Campagnoli, P., 324 | Dynamic Linear Models with R, Use R!, Springer, 2009. 325 | Google books link. 326 |

327 | 328 | 329 |
330 |
331 |
332 |
333 |
334 |

Author: Marko Laine

335 |

Created: 2018-11-20 Ti 17:11

336 |

337 |
338 | 339 | -------------------------------------------------------------------------------- /docs/mxdom2simplehtml.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | 17 | ]> 18 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | This HTML was auto-generated from MATLAB code. 44 | To make changes, update the MATLAB code and republish this document. 45 | 46 | 47 | <xsl:value-of select="$title"/> 48 | 49 | 50 | MATLAB 51 | 52 | 53 | 54 | 55 | 56 | 57 | .m 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
69 | 70 | 71 | 72 | 73 | 74 | 75 |

76 | introduction 77 | 78 | 79 | 80 | /introduction 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | h1 100 | h2 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 |
123 | 124 | 125 | 126 | 127 | 128 |
129 | 130 | 131 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 204 | 205 | 206 | 207 | 208 | 209 |

Contents

210 |
    211 | 212 | 213 |
  • #
  • 214 |
    215 |
    216 |
217 |
218 | 219 | 220 | 221 | 222 |

223 |
224 | 225 |
226 |
227 | 228 |
229 |
230 | 231 |
  • 232 |
    233 | 234 | 235 | 236 |
    237 |
    238 | 239 |
    240 |
    241 |
    242 |
    243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 |
    
    266 | 
    267 |
    268 | 269 | 270 | 271 | 272 |
    
    273 | 
    274 |
    275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 |
    283 |              
    284 |             
    285 |             
    286 |             
    287 |         
    288 |
    289 |
    290 |
    291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | width: 302 | 303 | ; 304 | 305 | 306 | height: 307 | ; 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | width: 321 | 322 | ; 323 | 324 | 325 | height: 326 | ; 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | ##### SOURCE BEGIN ##### 347 | 348 | ##### SOURCE END ##### 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 394 | 395 | 397 | 398 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 |
    409 | -------------------------------------------------------------------------------- /examples/ozonedata.dat: -------------------------------------------------------------------------------- 1 | 1.9847919e+03 7.1426883e+10 1.2131312e+09 -2.6566396e-01 -7.9154665e-01 -9.0835191e-01 2 | 1.9848754e+03 6.5680381e+10 8.0932920e+08 -2.9577853e-01 -4.3011109e-01 -8.1912278e-01 3 | 1.9849589e+03 7.1284819e+10 2.2235540e+09 -2.7253794e-01 -1.9807970e-01 -6.4759223e-01 4 | 1.9850438e+03 6.9645305e+10 9.7264739e+08 -2.6009931e-01 1.3995139e-01 -5.2048959e-01 5 | 1.9851246e+03 7.2142164e+10 1.2629917e+09 -2.9774252e-01 3.3128543e-01 -4.3015442e-01 6 | 1.9852053e+03 7.7227173e+10 2.7402918e+09 -2.9905185e-01 4.3845278e-01 -2.9544869e-01 7 | 1.9852888e+03 6.7197314e+10 9.5998985e+08 -3.1803712e-01 6.4225384e-01 4.8324122e-02 8 | 1.9853723e+03 7.6264333e+10 9.9797728e+08 -1.6811895e-01 7.4784733e-01 3.1312340e-01 9 | 1.9854559e+03 NaN NaN -2.5584399e-01 7.5763618e-01 3.6494744e-01 10 | 1.9855394e+03 8.0285092e+10 1.1314349e+09 -3.1345447e-01 6.3815134e-01 3.2664117e-01 11 | 1.9856242e+03 8.2721655e+10 1.0192804e+09 -3.3473106e-01 6.3865850e-01 3.6727836e-01 12 | 1.9857077e+03 7.8883668e+10 7.7925324e+08 -3.1410913e-01 6.6540117e-01 4.2762625e-01 13 | 1.9857912e+03 7.3906610e+10 9.8612259e+08 -2.7908458e-01 6.7051655e-01 5.2646079e-01 14 | 1.9858747e+03 6.8709165e+10 9.3351208e+08 -2.4144138e-01 6.5908289e-01 5.1403717e-01 15 | 1.9859582e+03 7.7490396e+10 2.2138416e+09 -2.1460013e-01 5.8172116e-01 4.2038461e-01 16 | 1.9860431e+03 7.4679074e+10 1.6826132e+09 -2.6206331e-01 5.3669844e-01 3.7201849e-01 17 | 1.9861239e+03 7.3742528e+10 2.4389882e+09 -2.3489473e-01 5.9612157e-01 3.9429291e-01 18 | 1.9862047e+03 6.8922728e+10 1.6325922e+09 -3.1345447e-01 6.7017368e-01 5.3838453e-01 19 | 1.9862882e+03 6.6902396e+10 1.0013991e+09 -2.7613859e-01 5.4187002e-01 5.7270644e-01 20 | 1.9863717e+03 7.3141955e+10 7.8489128e+08 -2.9054121e-01 2.9201288e-01 5.9542341e-01 21 | 1.9864552e+03 NaN NaN -3.2065578e-01 4.6387290e-02 5.1249837e-01 22 | 1.9865387e+03 8.1297570e+10 5.6314147e+08 -2.9610586e-01 -9.5219613e-02 1.9810180e-01 23 | 1.9866235e+03 8.3620323e+10 1.7441953e+09 -3.2752976e-01 -2.7985346e-01 2.2412800e-02 24 | 1.9867070e+03 7.9098664e+10 8.3614862e+08 -3.1279980e-01 -3.0466084e-01 2.7821305e-02 25 | 1.9867906e+03 7.3462742e+10 8.8921703e+08 -2.3587673e-01 -2.7513904e-01 1.6386169e-01 26 | 1.9868741e+03 6.7763105e+10 1.3498182e+09 -2.6697329e-01 -2.1182056e-01 1.0359070e-01 27 | 1.9869576e+03 6.0525546e+10 1.7418152e+09 -2.8726789e-01 -3.1760454e-01 -1.1114193e-02 28 | 1.9870424e+03 6.4348154e+10 1.5321005e+09 -2.9086854e-01 -2.9624679e-01 -6.6257498e-03 29 | 1.9871232e+03 6.4588937e+10 1.4383785e+09 -3.0363450e-01 -3.5693423e-01 -4.0037386e-02 30 | 1.9872040e+03 6.5712399e+10 1.1818792e+09 -2.9905185e-01 -4.8781654e-01 -1.3715765e-01 31 | 1.9872875e+03 7.0765068e+10 9.2129049e+08 -1.4978835e-01 -5.7652384e-01 -2.5187094e-01 32 | 1.9873710e+03 7.5056555e+10 7.8739329e+08 -1.4553303e-01 -7.4438816e-01 -4.8481275e-01 33 | 1.9874545e+03 NaN NaN -2.5322534e-01 -7.9314622e-01 -6.9929183e-01 34 | 1.9875380e+03 8.3849133e+10 6.8206930e+08 -2.5453467e-01 -4.4300812e-01 -9.5795550e-01 35 | 1.9876229e+03 8.3542296e+10 1.5521507e+09 -1.1770979e-01 1.3390122e-01 -8.6092962e-01 36 | 1.9877064e+03 7.9257846e+10 7.8523506e+08 -2.2769342e-01 4.1171058e-01 -5.0780938e-01 37 | 1.9877899e+03 7.3033660e+10 8.1155196e+08 -5.3225336e-02 5.6043483e-01 -6.7009994e-02 38 | 1.9878734e+03 7.2091191e+10 1.5493499e+09 -1.3276707e-01 5.5416704e-01 2.3326127e-01 39 | 1.9879569e+03 6.9613660e+10 1.1378727e+09 -1.4193237e-01 5.1777647e-01 2.2172905e-01 40 | 1.9880418e+03 6.9236199e+10 1.4748785e+09 3.6791030e-02 4.8897565e-01 2.4293380e-01 41 | 1.9881239e+03 7.8409887e+10 3.8763857e+09 -9.3487202e-02 4.1962268e-01 2.5775195e-01 42 | 1.9882060e+03 7.8833514e+10 2.4726669e+09 -4.1255001e-03 4.0769476e-01 2.2720327e-01 43 | 1.9882895e+03 6.7989455e+10 9.5299083e+08 1.8998252e-01 4.3679178e-01 3.5879226e-01 44 | 1.9883730e+03 7.3084855e+10 8.1045934e+08 -1.0690782e-01 3.7761532e-01 4.6048696e-01 45 | 1.9884565e+03 8.2301950e+10 1.1315673e+09 2.7484770e-03 1.5874336e-01 4.5304887e-01 46 | 1.9885400e+03 8.2893274e+10 6.6616061e+08 2.0078448e-01 -2.5810487e-02 3.0458697e-01 47 | 1.9886249e+03 NaN NaN 1.3597270e-01 3.2948334e-02 2.1756570e-01 48 | 1.9887084e+03 7.9368546e+10 9.7886351e+08 6.3632274e-02 4.5885371e-02 2.5942078e-01 49 | 1.9887919e+03 7.3843842e+10 9.4318179e+08 3.0978612e-01 8.0328259e-02 2.8974784e-01 50 | 1.9888754e+03 6.6249959e+10 7.2912138e+08 4.7738023e-01 1.0706045e-01 3.0196521e-01 51 | 1.9889589e+03 6.9633610e+10 1.0703575e+09 8.3253571e-01 3.8048480e-02 2.0869368e-01 52 | 1.9890438e+03 7.1534878e+10 2.1346283e+09 1.1209154e+00 1.8026479e-02 2.2393132e-01 53 | 1.9891246e+03 7.6079637e+10 2.6999269e+09 8.4988432e-01 -1.1052923e-02 1.3421489e-01 54 | 1.9892053e+03 6.5529247e+10 8.0148044e+08 8.9145551e-01 7.3778072e-02 1.6313808e-01 55 | 1.9892888e+03 6.6819137e+10 1.0539475e+09 5.5528530e-01 5.5923753e-02 3.5857553e-01 56 | 1.9893723e+03 7.1897160e+10 7.1788422e+08 4.3286304e-01 -1.0359842e-01 2.7141653e-01 57 | 1.9894559e+03 8.0019655e+10 8.7318192e+08 1.2662509e+00 -2.7541667e-01 7.1017555e-03 58 | 1.9895394e+03 8.1397922e+10 7.0209126e+08 3.9685650e-01 -4.7389472e-01 -2.5383620e-01 59 | 1.9896242e+03 NaN NaN 9.0029349e-01 -6.0934859e-01 -3.8428421e-01 60 | 1.9897077e+03 7.7855523e+10 8.8701424e+08 7.4513800e-01 -6.9096140e-01 -4.8112971e-01 61 | 1.9897912e+03 7.1325123e+10 7.8752623e+08 7.5463064e-01 -7.9179666e-01 -5.2638329e-01 62 | 1.9898747e+03 6.0936487e+10 1.0590052e+09 6.7901689e-01 -6.8721177e-01 -5.2729356e-01 63 | 1.9899582e+03 6.4453778e+10 1.0275608e+09 3.8081722e-01 -4.4268668e-01 -5.5120606e-01 64 | 1.9900431e+03 6.8215283e+10 2.0835152e+09 4.9702016e-01 -2.3490932e-01 -5.0131932e-01 65 | 1.9901239e+03 7.1638737e+10 1.9314826e+09 2.2926239e-01 -1.5188552e-01 -4.8151983e-01 66 | 1.9902047e+03 6.6911305e+10 8.0888092e+08 4.2140641e-01 1.9890308e-01 -4.7194518e-01 67 | 1.9902882e+03 6.4851959e+10 1.0204391e+09 7.0127548e-01 4.0840382e-01 -3.7501788e-01 68 | 1.9903717e+03 7.3021233e+10 7.6661381e+08 8.3286304e-01 6.5722331e-01 -4.6413493e-02 69 | 1.9904552e+03 8.1013141e+10 7.3881564e+08 4.3548170e-01 7.1737932e-01 1.9017501e-01 70 | 1.9905387e+03 8.2777178e+10 9.5861194e+08 1.6281394e-01 7.0216031e-01 3.0802671e-01 71 | 1.9906235e+03 NaN NaN 6.3417237e-01 7.0719617e-01 3.7580430e-01 72 | 1.9907070e+03 7.8616905e+10 8.2740322e+08 5.5986795e-01 7.3042921e-01 3.7426691e-01 73 | 1.9907906e+03 7.2818364e+10 8.2748862e+08 6.0896779e-01 6.9352435e-01 4.9560798e-01 74 | 1.9908741e+03 6.9862673e+10 1.4318021e+09 6.1878776e-01 6.5683902e-01 5.8267609e-01 75 | 1.9909576e+03 6.7460383e+10 1.2999081e+09 5.1044078e-01 6.1537212e-01 5.7116694e-01 76 | 1.9910424e+03 7.4108438e+10 1.8011533e+09 5.2909872e-01 5.3176973e-01 4.4018410e-01 77 | 1.9911232e+03 7.5342455e+10 1.7487509e+09 5.1796943e-01 5.2039083e-01 3.7088589e-01 78 | 1.9912040e+03 7.2257202e+10 1.5200364e+09 8.9734750e-01 5.4881307e-01 4.1414484e-01 79 | 1.9912875e+03 6.8679291e+10 9.0685080e+08 9.7950789e-01 6.0989482e-01 4.6041775e-01 80 | 1.9913710e+03 7.3044319e+10 9.6408873e+08 4.1420511e-01 3.0044169e-01 4.8183853e-01 81 | 1.9914545e+03 8.1310678e+10 7.7243124e+08 4.3940969e-01 -1.1672941e-02 2.6278013e-01 82 | 1.9915380e+03 8.2811251e+10 9.1031970e+08 2.9734750e-01 -3.2148322e-01 -3.5213358e-02 83 | 1.9916229e+03 NaN NaN 9.8212655e-01 -5.0240268e-01 -2.3145691e-01 84 | 1.9917064e+03 8.1265718e+10 8.6657900e+08 3.7197925e-01 -4.6905410e-01 -1.6920947e-01 85 | 1.9917899e+03 7.5400942e+10 8.8047815e+08 3.7918056e-01 -3.9426387e-01 -6.8645969e-02 86 | 1.9918734e+03 6.4711878e+10 1.2421828e+09 3.1436877e-01 -3.9739777e-01 -7.0726593e-02 87 | 1.9919569e+03 7.0491773e+10 1.3662542e+09 6.4104635e-01 -4.1769311e-01 -1.3141077e-01 88 | 1.9920418e+03 7.3924914e+10 1.2447319e+09 2.6821493e-01 -4.7243039e-01 -1.3749324e-01 89 | 1.9921239e+03 7.1306021e+10 1.4036773e+09 5.4939332e-01 -4.8994025e-01 -1.2474211e-01 90 | 1.9922060e+03 7.2828541e+10 1.5568818e+09 2.7967155e-01 -6.0121978e-01 -2.1075554e-01 91 | 1.9922895e+03 6.7276228e+10 1.3606977e+09 2.6330494e-01 -6.3855514e-01 -2.4597583e-01 92 | 1.9923730e+03 7.2669201e+10 1.0972908e+09 -2.0164780e-02 -5.5888286e-01 -3.3027607e-01 93 | 1.9924565e+03 7.8110641e+10 7.2891281e+08 1.0604451e-02 -5.2789674e-01 -6.1272919e-01 94 | 1.9925400e+03 8.1291028e+10 8.2732558e+08 1.9161918e-01 -3.7140608e-01 -8.7561145e-01 95 | 1.9926249e+03 NaN NaN 1.1600543e-01 -5.0789773e-02 -9.1958351e-01 96 | 1.9927084e+03 7.7445876e+10 9.4863536e+08 5.9704287e-02 2.0807905e-01 -7.4255147e-01 97 | 1.9927919e+03 7.0754651e+10 7.7973353e+08 -9.0868544e-02 3.2622100e-01 -5.1728056e-01 98 | 1.9928754e+03 6.4422328e+10 1.4231380e+09 1.2582540e-01 4.2969110e-01 -3.5475347e-01 99 | 1.9929589e+03 6.7614001e+10 1.4613658e+09 2.1616910e-01 5.1240489e-01 -7.5829575e-02 100 | 1.9930438e+03 6.6709500e+10 1.2038838e+09 7.9998886e-02 5.7559955e-01 2.3308649e-01 101 | 1.9931246e+03 7.4787923e+10 2.5378699e+09 1.1338677e-01 6.2490810e-01 2.8506014e-01 102 | 1.9932053e+03 6.9066837e+10 1.1962283e+09 3.3845040e-02 6.5236603e-01 3.0601320e-01 103 | 1.9932888e+03 6.3786764e+10 9.5839142e+08 -1.7859359e-01 7.0604185e-01 4.9485642e-01 104 | 1.9933723e+03 6.9009510e+10 7.4630098e+08 -1.3080308e-01 7.3211831e-01 6.9214517e-01 105 | 1.9934559e+03 8.3102459e+10 1.8877799e+09 -2.3031208e-01 4.2758009e-01 6.0981090e-01 106 | 1.9935394e+03 7.8890319e+10 7.0774298e+08 -1.2622043e-01 1.6005197e-01 4.0361587e-01 107 | 1.9936242e+03 NaN NaN -1.7041028e-01 9.3592924e-02 2.5670325e-01 108 | 1.9937077e+03 7.2870583e+10 8.2695593e+08 -1.9299620e-01 9.1840493e-02 2.9981957e-01 109 | 1.9937912e+03 7.1185564e+10 1.3707550e+09 -1.7695692e-01 -3.5996493e-02 2.9148868e-01 110 | 1.9938747e+03 NaN NaN -1.1181781e-01 -1.0883857e-01 2.3696738e-01 111 | 1.9939582e+03 6.1589833e+10 1.3790402e+09 -2.1820079e-01 -1.2262754e-01 1.7781991e-01 112 | 1.9940431e+03 NaN NaN -9.5778528e-02 -1.9645822e-01 1.1087079e-01 113 | 1.9941239e+03 7.7390942e+10 2.1693616e+09 -8.9559215e-02 -2.8917516e-01 3.5385241e-02 114 | 1.9942047e+03 NaN NaN -2.0838082e-01 -3.6114150e-01 6.8618598e-02 115 | 1.9942882e+03 NaN NaN -2.3424007e-01 -5.0975384e-01 -1.0473559e-03 116 | 1.9943717e+03 6.6916055e+10 6.6291741e+08 -1.5928098e-01 -6.6270726e-01 -2.3252658e-01 117 | 1.9944552e+03 7.5621364e+10 6.6495623e+08 -1.9365087e-01 -8.8375738e-01 -7.0414662e-01 118 | 1.9945387e+03 7.8640260e+10 7.1789607e+08 -2.3653139e-01 -1.1187203e+00 -1.0178469e+00 119 | 1.9946235e+03 7.8050814e+10 7.3092210e+08 -2.6369997e-01 -1.0329893e+00 -1.1087273e+00 120 | 1.9947070e+03 7.4369483e+10 7.3452070e+08 -3.0559850e-01 -6.8498265e-01 -1.1614288e+00 121 | 1.9947906e+03 6.8164103e+10 8.4277076e+08 -1.6975561e-01 -2.8769654e-01 -9.4928274e-01 122 | 1.9948741e+03 6.2395450e+10 1.5781263e+09 -2.5191601e-01 1.4251956e-01 -5.8509590e-01 123 | 1.9949576e+03 5.9294437e+10 5.9657040e+08 -1.6386363e-01 4.1448066e-01 -2.3936412e-01 124 | 1.9950424e+03 7.0436691e+10 1.4116716e+09 -2.2474743e-01 5.1694073e-01 1.6275326e-03 125 | 1.9951232e+03 6.5915105e+10 1.1534111e+09 -2.1329080e-01 5.0134743e-01 1.0495611e-01 126 | 1.9952040e+03 6.4524854e+10 1.0801781e+09 -2.2049211e-01 5.4232003e-01 1.8370312e-01 127 | 1.9952875e+03 6.5499618e+10 7.0167888e+08 -1.8644956e-01 6.7337282e-01 3.5740518e-01 128 | 1.9953710e+03 NaN NaN -1.5044301e-01 8.0887050e-01 5.3433654e-01 129 | 1.9954545e+03 7.1730814e+10 6.9115740e+08 -3.0559850e-01 8.3264356e-01 5.7686769e-01 130 | 1.9955380e+03 7.7033496e+10 6.7627536e+08 -2.9185054e-01 6.6175916e-01 5.5087456e-01 131 | 1.9956229e+03 7.8807123e+10 7.1122619e+08 -3.0985381e-01 5.6235632e-01 4.7822051e-01 132 | 1.9957064e+03 7.3348873e+10 8.6298953e+08 -3.1345447e-01 4.5049122e-01 3.5211693e-01 133 | 1.9957899e+03 6.9706598e+10 7.8888704e+08 -2.1198147e-01 2.8934137e-01 3.7008888e-01 134 | 1.9958734e+03 6.3690665e+10 1.3266138e+09 -2.7221061e-01 1.0336987e-01 2.9884428e-01 135 | 1.9959569e+03 5.9063742e+10 8.4844873e+08 -3.1345447e-01 -6.1347217e-02 1.7005951e-01 136 | 1.9960418e+03 6.3044128e+10 1.3654335e+09 -3.0985381e-01 -1.1219153e-01 1.5945714e-01 137 | 1.9961239e+03 7.3896823e+10 1.8015440e+09 -3.1378180e-01 -1.6128505e-01 1.6907880e-01 138 | 1.9962060e+03 6.5032773e+10 9.4658470e+08 -3.0559850e-01 -2.9562534e-01 1.2160949e-01 139 | 1.9962895e+03 6.4468496e+10 1.0231195e+09 -3.2196511e-01 -3.4970069e-01 1.8516851e-01 140 | 1.9963730e+03 NaN NaN -3.0363450e-01 -5.1698881e-01 -6.9180807e-02 141 | 1.9964565e+03 7.7049491e+10 1.3869033e+09 -3.3113041e-01 -6.1778454e-01 -3.9697280e-01 142 | 1.9965400e+03 7.6482583e+10 8.6585370e+08 -3.3145774e-01 -9.1729310e-01 -7.0539667e-01 143 | 1.9966249e+03 7.9433618e+10 8.1298111e+08 -3.2589309e-01 -9.9857399e-01 -8.4999166e-01 144 | 1.9967084e+03 7.4663160e+10 9.1811246e+08 -3.2392910e-01 -1.0018708e+00 -8.4619257e-01 145 | 1.9967919e+03 6.8440710e+10 9.7557068e+08 -3.2032845e-01 -8.7830627e-01 -8.4046945e-01 146 | 1.9968754e+03 5.8393610e+10 1.1612521e+09 -2.8530390e-01 -6.4196523e-01 -7.7170189e-01 147 | 1.9969589e+03 5.5589075e+10 1.1775676e+09 -2.0412550e-01 -2.7660337e-01 -6.0526663e-01 148 | 1.9970438e+03 7.3815332e+10 1.5965697e+09 -2.8170324e-01 -1.0975314e-04 -5.5160457e-01 149 | 1.9971246e+03 7.1272887e+10 1.3889121e+09 -2.9905185e-01 2.3252547e-01 -4.2105169e-01 150 | 1.9972053e+03 6.6745541e+10 1.4735728e+09 -2.7548393e-01 3.5599328e-01 -4.0395785e-01 151 | 1.9972888e+03 6.7633237e+10 9.3234019e+08 -2.7810259e-01 5.5936337e-01 -8.1909948e-02 152 | 1.9973723e+03 NaN NaN -2.9446920e-01 7.0528897e-01 2.6074075e-01 153 | 1.9974559e+03 7.3470339e+10 7.9305786e+08 -2.9708786e-01 7.9659396e-01 4.7587072e-01 154 | 1.9975394e+03 7.6590233e+10 8.2881876e+08 -3.1247247e-01 7.8543412e-01 5.5748139e-01 155 | 1.9976242e+03 7.9868591e+10 7.2293264e+08 -2.6664596e-01 6.5152315e-01 5.0933549e-01 156 | 1.9977077e+03 7.5548623e+10 7.9684349e+08 -1.4455103e-01 6.7759485e-01 5.7173114e-01 157 | 1.9977912e+03 6.9006533e+10 6.8338232e+08 -1.9397820e-01 6.4468724e-01 5.5127307e-01 158 | 1.9978747e+03 6.5241351e+10 2.2315388e+09 -1.3931372e-01 5.0344368e-01 5.5439261e-01 159 | 1.9979582e+03 6.7838081e+10 1.3195599e+09 -2.1165414e-01 2.7675530e-01 4.7588191e-01 160 | 1.9980431e+03 6.6369736e+10 1.6480827e+09 -1.3604039e-01 1.7206659e-01 3.2528834e-01 161 | 1.9981239e+03 6.7058372e+10 1.2267155e+09 -6.6645958e-02 1.9505093e-02 2.5970254e-01 162 | 1.9982047e+03 6.5701346e+10 1.6120729e+09 4.7265662e-02 -7.8590567e-02 2.4800951e-01 163 | 1.9982882e+03 6.6884696e+10 8.2946311e+08 -7.2537939e-02 -1.7801484e-01 2.8896131e-01 164 | 1.9983717e+03 7.4346746e+10 8.6384649e+08 -2.2456106e-02 -4.2001461e-01 -3.7709268e-02 165 | 1.9984552e+03 7.7538553e+10 6.4757198e+08 -8.8249886e-02 -6.4023804e-01 -5.3875867e-01 166 | 1.9985387e+03 NaN NaN -9.3159870e-02 -8.5759140e-01 -8.2599737e-01 167 | 1.9986235e+03 8.1792764e+10 6.4550340e+08 1.3433604e-01 -9.0769997e-01 -9.0178704e-01 168 | 1.9987070e+03 7.5252251e+10 7.8303480e+08 7.9857929e-03 -7.7847247e-01 -9.3240843e-01 169 | 1.9987906e+03 6.8390241e+10 7.5527005e+08 1.0291214e-01 -6.5013547e-01 -9.2940984e-01 170 | 1.9988741e+03 5.8448351e+10 7.6479731e+08 4.6610997e-02 -4.2952059e-01 -6.9016743e-01 171 | 1.9989576e+03 6.0303195e+10 1.5032116e+09 1.6903326e-01 -6.7411676e-02 -4.7055041e-01 172 | 1.9990424e+03 6.1211442e+10 1.3858368e+09 2.7803489e-01 2.1456067e-01 -2.6512023e-01 173 | 1.9991232e+03 6.8579170e+10 2.1076082e+09 4.7541623e-01 3.2287090e-01 -2.1624025e-01 174 | 1.9992040e+03 6.1323746e+10 8.3959203e+08 2.4628367e-01 4.5922480e-01 -3.5559430e-02 175 | 1.9992875e+03 6.3009069e+10 1.0312479e+09 3.5481701e-02 6.8899136e-01 1.8945980e-01 176 | 1.9993710e+03 7.0196300e+10 8.8676270e+08 2.0471247e-01 8.1384922e-01 4.5809592e-01 177 | 1.9994545e+03 7.5116673e+10 6.7675739e+08 2.6265028e-01 8.1672978e-01 5.6119798e-01 178 | 1.9995380e+03 NaN NaN 1.1044078e-01 7.3889708e-01 5.3291030e-01 179 | 1.9996229e+03 8.0590037e+10 7.4782590e+08 1.2157008e-01 6.8793133e-01 4.5948021e-01 180 | 1.9997064e+03 7.4721507e+10 6.8143659e+08 2.6657826e-01 6.4430580e-01 4.7717111e-01 181 | 1.9997899e+03 6.7741046e+10 8.0901002e+08 4.3220838e-01 5.5848478e-01 5.2220306e-01 182 | 1.9998734e+03 6.3120864e+10 7.6775356e+08 7.5888596e-01 4.3562555e-01 4.9379443e-01 183 | 1.9999569e+03 5.9781131e+10 1.7816307e+09 5.2287941e-01 4.0223031e-01 5.1189432e-01 184 | 2.0000418e+03 7.2990623e+10 2.5337767e+09 5.5364864e-01 3.5135743e-01 4.8287675e-01 185 | 2.0001239e+03 6.4946813e+10 1.1813227e+09 2.6592360e-01 3.4640409e-01 4.4890930e-01 186 | 2.0002060e+03 6.1643887e+10 3.2011488e+09 4.6428694e-01 3.9919451e-01 5.3250131e-01 187 | 2.0002895e+03 6.2467905e+10 1.0745575e+09 2.7181558e-01 3.6794029e-01 7.2157943e-01 188 | 2.0003730e+03 7.1394578e+10 7.8898572e+08 9.3531804e-01 1.1885079e-01 7.8686391e-01 189 | 2.0004565e+03 7.5593687e+10 7.1966998e+08 5.2386141e-01 -1.8331451e-01 4.4026170e-01 190 | 2.0005400e+03 NaN NaN 6.9472884e-01 -4.4425101e-01 1.0845878e-01 191 | 2.0006249e+03 NaN NaN 4.1813309e-01 -5.3305355e-01 -2.0219493e-03 192 | 2.0007084e+03 NaN NaN 3.7394324e-01 -5.3706414e-01 -7.2025358e-03 193 | 2.0007919e+03 NaN NaN 2.6199561e-01 -4.8303784e-01 3.6192741e-02 194 | 2.0008754e+03 6.7963942e+10 1.4594845e+09 2.4039168e-01 -4.9677775e-01 -3.7913416e-02 195 | 2.0009589e+03 6.5298291e+10 3.4133899e+09 4.9832949e-01 -4.5829427e-01 -5.5390379e-02 196 | 2.0010438e+03 7.3362942e+10 2.7530259e+09 2.5806763e-01 -5.1775311e-01 -1.2848489e-01 197 | 2.0011246e+03 6.7015300e+10 1.9226710e+09 1.1535077e-01 -5.1016718e-01 -1.5447172e-01 198 | 2.0012053e+03 NaN NaN 1.2811673e-01 -5.7357614e-01 -1.4908139e-01 199 | 2.0012888e+03 6.3907696e+10 9.7590684e+08 3.8755024e-02 -6.2332042e-01 -3.2213372e-02 200 | 2.0013723e+03 NaN NaN 1.6445060e-01 -7.6368157e-01 -1.0356774e-01 201 | 2.0014559e+03 7.6009087e+10 6.9740105e+08 5.8998252e-01 -8.7425044e-01 -4.1647865e-01 202 | 2.0015394e+03 NaN NaN 1.9783849e-01 -9.3362214e-01 -7.1400651e-01 203 | 2.0016242e+03 7.9163805e+10 8.5867027e+08 1.7197925e-01 -7.9729682e-01 -1.0139771e+00 204 | 2.0017077e+03 7.6266523e+10 1.5323028e+09 5.8670920e-01 -4.8155779e-01 -9.8290691e-01 205 | 2.0017912e+03 NaN NaN 6.2075175e-01 -3.1770454e-01 -8.4820887e-01 206 | 2.0018747e+03 6.5945796e+10 1.3570382e+09 5.5397597e-01 -1.7312149e-02 -7.3940886e-01 207 | 2.0019582e+03 5.9773050e+10 1.5887448e+09 5.8801853e-01 2.1892508e-01 -5.5228622e-01 208 | 2.0020431e+03 6.3802933e+10 1.1674104e+09 6.3155371e-01 3.5930052e-01 -3.3833010e-01 209 | 2.0021239e+03 6.5494491e+10 2.4576214e+09 5.0749479e-01 5.0090456e-01 -1.9478381e-01 210 | 2.0022047e+03 6.6238483e+10 1.5752464e+09 4.3875502e-01 5.6945652e-01 4.6281251e-02 211 | 2.0022882e+03 7.5032110e+10 1.0899258e+09 5.1207745e-01 7.6814696e-01 3.9561498e-01 212 | 2.0023717e+03 7.8491993e+10 8.4898486e+08 2.6363227e-01 7.7178373e-01 6.0378157e-01 213 | 2.0024552e+03 7.6051701e+10 9.5790626e+08 1.2582540e-01 7.2913013e-01 6.0103327e-01 214 | 2.0025387e+03 8.0014207e+10 9.8745230e+08 4.1158645e-01 5.9329292e-01 4.5144716e-01 215 | 2.0026235e+03 8.0429628e+10 6.6203818e+08 6.7279758e-01 6.1240775e-01 4.9030155e-01 216 | 2.0027070e+03 7.7540020e+10 3.3154483e+08 4.2631640e-01 5.3894708e-01 5.2487375e-01 217 | 2.0027906e+03 7.1304472e+10 6.3289808e+08 4.1387777e-01 4.7941109e-01 5.3945420e-01 218 | 2.0028741e+03 6.4964661e+10 1.0230483e+09 5.3499070e-01 3.3680654e-01 5.1273678e-01 219 | 2.0029576e+03 7.0272835e+10 3.5194892e+09 5.9063718e-01 1.2255804e-01 3.8014593e-01 220 | 2.0030424e+03 6.9722585e+10 6.2224433e+08 1.6805126e-01 8.4942677e-02 3.0818402e-01 221 | 2.0031232e+03 6.8084438e+10 7.7672013e+08 4.0064353e-02 8.2835474e-02 3.4097692e-01 222 | 2.0032040e+03 6.6813375e+10 1.1907702e+09 5.9049623e-02 -1.0810059e-02 3.2323289e-01 223 | 2.0032875e+03 6.7206270e+10 3.2757905e+08 -1.2425643e-01 -2.4040043e-01 2.3672898e-01 224 | 2.0033710e+03 7.2812881e+10 5.4878713e+08 -9.8069854e-02 -4.7798769e-01 5.0392162e-02 225 | 2.0034545e+03 7.4664781e+10 2.4720697e+08 3.3517708e-02 -6.4550819e-01 -1.6099534e-01 226 | 2.0035380e+03 8.0429555e+10 2.7146051e+08 1.2058808e-01 -8.7508475e-01 -3.9418395e-01 227 | 2.0036229e+03 8.0585996e+10 3.6558804e+08 3.6791030e-02 -9.4005804e-01 -5.2073079e-01 228 | 2.0037064e+03 7.8543316e+10 3.1218134e+08 -1.1901912e-01 -8.4708776e-01 -5.7558138e-01 229 | 2.0037899e+03 6.6133270e+10 3.0575412e+09 -1.3407640e-01 -7.4887400e-01 -5.7275688e-01 230 | 2.0038734e+03 6.1462948e+10 4.3524096e+08 -8.5631228e-02 -6.3479074e-01 -6.3936552e-01 231 | 2.0039569e+03 6.3915541e+10 3.2662445e+08 -3.6531392e-02 -3.4334099e-01 -5.9061627e-01 232 | 2.0040418e+03 5.9686663e+10 6.5783663e+08 2.5989066e-02 -5.1354074e-02 -4.5342511e-01 233 | 2.0041239e+03 7.0479884e+10 4.5658352e+08 -1.1181781e-01 2.6437391e-01 -3.2152701e-01 234 | 2.0042060e+03 6.9881908e+10 5.4712240e+08 -5.0934011e-02 3.9913023e-01 -2.2902392e-01 235 | 2.0042895e+03 6.9739929e+10 5.6436815e+08 -1.3473106e-01 6.1355588e-01 9.2038903e-02 236 | 2.0043730e+03 7.1825455e+10 2.2585733e+08 -1.8200786e-02 7.1841792e-01 3.8295645e-01 237 | 2.0044565e+03 7.4798936e+10 2.1884986e+08 -3.9150050e-02 6.6476639e-01 4.9288416e-01 238 | 2.0045400e+03 7.9038081e+10 3.2451194e+08 1.9882049e-01 5.8526411e-01 5.0526653e-01 239 | 2.0046249e+03 8.0255764e+10 3.7214274e+08 1.1011345e-01 5.3379122e-01 5.0839166e-01 240 | 2.0047084e+03 7.8251623e+10 2.5735860e+08 -6.0099313e-02 4.6727598e-01 4.0356903e-01 241 | 2.0047919e+03 6.8910528e+10 1.1702905e+09 -1.6811895e-01 4.8646843e-01 5.2176261e-01 242 | 2.0048754e+03 6.2322243e+10 9.3874206e+08 -5.9444649e-02 3.3875517e-01 5.2188286e-01 243 | 2.0049589e+03 5.7362155e+10 1.8137542e+09 -1.8023025e-01 2.4131143e-01 5.0223578e-01 244 | 2.0050438e+03 7.2062961e+10 1.7707442e+09 1.5397597e-01 1.2577956e-01 3.9989298e-01 245 | 2.0051246e+03 7.3212860e+10 3.3932732e+09 2.7625727e-02 1.0807905e-01 3.9494311e-01 246 | 2.0052053e+03 6.4220850e+10 1.8191723e+09 -9.4796531e-02 1.1847221e-01 4.7774859e-01 247 | 2.0052888e+03 NaN NaN -2.2638409e-01 -1.5993099e-01 4.1069950e-01 248 | 2.0053723e+03 6.8951060e+10 7.7786470e+08 -1.5011568e-01 -5.3346785e-01 1.7181085e-01 249 | 2.0054559e+03 NaN NaN -1.2687509e-01 -7.7058939e-01 -1.7529963e-01 250 | 2.0055394e+03 7.7377692e+10 1.1928469e+09 -2.7679326e-01 -9.2869343e-01 -5.4066661e-01 251 | 2.0056242e+03 8.0095964e+10 5.5499292e+08 -2.6893728e-01 -1.0028098e+00 -6.7186968e-01 252 | 2.0057077e+03 7.7520296e+10 1.9495465e+08 -3.7186057e-02 -1.0859865e+00 -7.4744961e-01 253 | 2.0057912e+03 NaN NaN -2.5420733e-01 -1.1287563e+00 -8.0367051e-01 254 | 2.0058747e+03 NaN NaN -1.5371633e-01 -1.1549856e+00 -7.9738459e-01 255 | 2.0059582e+03 NaN NaN -2.0936282e-01 -9.4902972e-01 -8.1498600e-01 256 | 2.0060431e+03 6.2754655e+10 8.3331807e+08 -2.2474743e-01 -6.7105035e-01 -8.6105547e-01 257 | 2.0061239e+03 5.6979102e+10 4.1378957e+08 -2.5518933e-01 -3.5117693e-01 -7.9361346e-01 258 | 2.0062047e+03 6.0625314e+10 6.4427114e+08 -2.9643319e-01 1.4133000e-01 -6.6037591e-01 259 | 2.0062882e+03 7.0125037e+10 3.5863099e+08 -2.6828262e-01 3.7638434e-01 -5.2339239e-01 260 | 2.0063717e+03 7.2610886e+10 1.6985264e+08 -2.9937918e-01 6.0780047e-01 -2.1099674e-01 261 | 2.0064552e+03 7.4152011e+10 2.8814631e+08 -2.7613859e-01 6.5353226e-01 1.5385078e-01 262 | 2.0065387e+03 8.0850160e+10 8.5231371e+08 -3.0494383e-01 6.2313663e-01 3.2732282e-01 263 | 2.0066235e+03 7.9745847e+10 2.8238598e+08 -1.5895365e-01 6.2193659e-01 3.3874318e-01 264 | 2.0067070e+03 7.8473736e+10 2.9460671e+08 -2.5060668e-01 5.9932499e-01 5.6609612e-01 265 | 2.0067906e+03 NaN NaN -3.1378180e-01 6.2635815e-01 6.4824652e-01 266 | 2.0068741e+03 NaN NaN -1.5306167e-01 5.8816467e-01 6.9117198e-01 267 | 2.0069576e+03 NaN NaN -2.3358540e-01 4.1391636e-01 6.0128566e-01 268 | 2.0070424e+03 6.6327576e+10 1.0788930e+09 -2.5584399e-01 2.6181202e-01 4.6513271e-01 269 | 2.0071232e+03 7.3832679e+10 9.2071833e+08 -2.8726789e-01 2.5422609e-01 4.6451398e-01 270 | 2.0072040e+03 6.4949044e+10 9.0227712e+08 -3.1738246e-01 1.8818848e-01 5.4268420e-01 271 | 2.0072875e+03 6.7047796e+10 2.2229344e+08 -3.1541846e-01 -9.5906776e-02 5.2682434e-01 272 | 2.0073710e+03 7.0528860e+10 1.7672725e+08 -2.6631863e-01 -4.9164523e-01 3.3060526e-01 273 | 2.0074545e+03 7.4263990e+10 2.2000279e+08 -3.2392910e-01 -8.0333223e-01 -1.4396023e-01 274 | 2.0075380e+03 NaN NaN -2.9381453e-01 -9.6235867e-01 -5.8333828e-01 275 | 2.0076229e+03 7.7896584e+10 3.9527063e+08 -3.2752976e-01 -1.0688617e+00 -7.5720254e-01 276 | 2.0077064e+03 NaN NaN -3.3047575e-01 -1.1009703e+00 -7.5711584e-01 277 | 2.0077899e+03 NaN NaN -3.2883908e-01 -1.1368208e+00 -7.5771640e-01 278 | 2.0078734e+03 NaN NaN -3.0690782e-01 -1.0637249e+00 -8.2209200e-01 279 | 2.0079569e+03 NaN NaN -2.4144138e-01 -7.0097263e-01 -9.1568234e-01 280 | 2.0080418e+03 7.2298366e+10 1.6717580e+09 -2.8923188e-01 -3.8689223e-01 -9.6911369e-01 281 | 2.0081239e+03 6.9042579e+10 6.9661630e+08 -3.1083581e-01 -5.6279092e-02 -8.2427352e-01 282 | 2.0082060e+03 5.7976762e+10 5.7120058e+08 -3.1050848e-01 2.5268318e-01 -6.3474564e-01 283 | 2.0082895e+03 6.3476952e+10 1.0015667e+09 -3.1410913e-01 4.3890279e-01 -4.2803045e-01 284 | 2.0083730e+03 7.0620673e+10 1.5616036e+08 -3.0167051e-01 6.6137343e-01 -1.0168007e-01 285 | 2.0084565e+03 7.3149295e+10 2.5468712e+08 -3.4160504e-01 7.4243099e-01 2.9099859e-01 286 | 2.0085400e+03 7.8582837e+10 9.8447667e+08 -3.4487836e-01 7.3078256e-01 4.8125126e-01 287 | 2.0086249e+03 7.7852666e+10 4.0756946e+08 -3.3473106e-01 6.6160201e-01 4.6333943e-01 288 | 2.0087084e+03 7.8273205e+10 4.3450945e+08 -3.1476380e-01 6.5952576e-01 4.2886162e-01 289 | 2.0087919e+03 NaN NaN -3.0461650e-01 6.3186545e-01 4.6848856e-01 290 | 2.0088754e+03 6.2753667e+10 1.4179639e+09 -3.2589309e-01 5.5292700e-01 4.4613513e-01 291 | 2.0089589e+03 7.2551706e+10 4.9763869e+09 -3.1672779e-01 6.1082913e-01 4.9962451e-01 292 | 2.0090438e+03 6.8393740e+10 9.4667057e+08 -3.0199784e-01 6.2483667e-01 5.3748264e-01 293 | 2.0091246e+03 NaN NaN -3.1345447e-01 6.9311005e-01 5.2758290e-01 294 | 2.0092053e+03 6.0074183e+10 6.6647851e+08 -3.1672779e-01 6.4868021e-01 4.6316115e-01 295 | 2.0092888e+03 NaN NaN -3.1149048e-01 5.3891755e-01 6.3183084e-01 296 | 2.0093723e+03 7.2173040e+10 1.9626713e+08 -2.8399457e-01 2.0063170e-01 7.2544145e-01 297 | 2.0094559e+03 NaN NaN -3.2196511e-01 -1.0557610e-01 5.7758290e-01 298 | 2.0095394e+03 7.6417023e+10 4.6631406e+08 -3.3407640e-01 -3.9851399e-01 2.5150169e-01 299 | 2.0096242e+03 7.7891108e+10 2.0054715e+09 -3.2098311e-01 -4.9196666e-01 1.8240273e-01 300 | 2.0097077e+03 NaN NaN -3.1869178e-01 -4.6186485e-01 2.3672898e-01 301 | 2.0097912e+03 NaN NaN -3.0985381e-01 -3.7567048e-01 2.8392755e-01 302 | 2.0098747e+03 6.1310053e+10 8.4238576e+08 -2.7024661e-01 -4.6800598e-01 2.1880527e-01 303 | 2.0099582e+03 7.1053244e+10 1.3167087e+09 -2.1230881e-01 -5.4346099e-01 8.9645067e-02 304 | 2.0100431e+03 6.7818524e+10 9.6621089e+08 -2.2311077e-01 -5.6448302e-01 1.0518683e-01 305 | 2.0101239e+03 7.1405295e+10 1.5302456e+09 -1.9561486e-01 -6.0494132e-01 4.5788362e-02 306 | 2.0102047e+03 5.8634879e+10 5.6414567e+08 -2.0641683e-01 -7.3285212e-01 -4.6633720e-02 307 | 2.0102882e+03 6.9740639e+10 2.9452622e+08 -2.7941192e-01 -9.0079311e-01 -4.4534731e-01 308 | 2.0103717e+03 7.3864757e+10 1.9665750e+08 -3.1836445e-01 -1.0141744e+00 -8.4482156e-01 309 | 2.0104552e+03 7.5801921e+10 2.6152935e+08 -3.0036118e-01 -9.3989851e-01 -1.1502021e+00 310 | 2.0105387e+03 7.6605447e+10 4.7787648e+08 -2.6075398e-01 -2.6498161e-01 -1.1778053e+00 311 | 2.0106235e+03 7.6651695e+10 1.0344752e+09 -2.2638409e-01 2.2181802e-01 -7.9249135e-01 312 | 2.0107070e+03 NaN NaN -2.2900275e-01 4.4430580e-01 -2.6637029e-01 313 | 2.0107906e+03 NaN NaN -2.1099948e-01 6.2952967e-01 2.7389147e-01 314 | 2.0108741e+03 NaN NaN -1.6811895e-01 6.8380979e-01 5.5278879e-01 315 | 2.0109576e+03 7.3741262e+10 1.2215818e+09 -2.2671142e-01 6.2862250e-01 5.4049242e-01 316 | 2.0110424e+03 7.6058705e+10 1.0176229e+09 -2.3849539e-01 5.5547041e-01 3.8525310e-01 317 | 2.0111232e+03 NaN NaN -3.0639412e-02 5.9213574e-01 3.8649057e-01 318 | 2.0112040e+03 6.1177902e+10 7.0765673e+08 -1.3080308e-01 6.0998625e-01 4.0515746e-01 319 | 2.0112875e+03 6.4140427e+10 3.7806035e+08 1.1259115e-02 6.2034655e-01 4.0575802e-01 320 | 2.0113710e+03 7.1348154e+10 1.4943555e+08 -1.6779162e-01 5.7769247e-01 5.3416875e-01 321 | 2.0114545e+03 7.4927795e+10 2.2575009e+08 -9.2832538e-02 3.1466305e-01 5.9986292e-01 322 | 2.0115380e+03 7.3961292e+10 6.5198524e+08 -1.2294710e-01 1.6454495e-01 6.0209316e-01 323 | 2.0116229e+03 7.3519539e+10 1.5845938e+09 -1.4553303e-01 1.2147229e-01 5.8710721e-01 324 | 2.0117064e+03 NaN NaN 1.6772393e-01 4.4084367e-02 6.4843249e-01 325 | 2.0117899e+03 NaN NaN 2.2467974e-01 -9.6692048e-04 7.3088421e-01 326 | 2.0118734e+03 NaN NaN 1.6248661e-01 -2.6608688e-01 5.3451831e-01 327 | 2.0119569e+03 NaN NaN 1.8460425e-02 -5.7226896e-01 1.4441876e-01 328 | --------------------------------------------------------------------------------