|
| 1 | +%% ARFITCAPS |
| 2 | +% Capsule function to call the arfit.m routine, part of |
| 3 | +% "ARfit: Multivariate Autoregressive Model Fitting" package. |
| 4 | +% |
| 5 | +%% Syntax: |
| 6 | +% [pf,A,ef] = ARFITCAPS(u,IP) |
| 7 | +% |
| 8 | +%% Input Arguments |
| 9 | +% u: time series |
| 10 | +% IP: VAR model order |
| 11 | +% |
| 12 | +%% Output Arguments |
| 13 | +% pf: covariance matrix provided by ARFIT routine |
| 14 | +% A: AR estimate matrix provided by ARFIT routine |
| 15 | +% ef: forward residuals provided by ARRES routine |
| 16 | +% |
| 17 | +%% Description: |
| 18 | +% ARFITCAPS is capsule that calls arfit.m and arres.m routines, part of |
| 19 | +% Autoregressive Model Fitting" package, which implements algorithms |
| 20 | +% as described in the following articles: |
| 21 | +% |
| 22 | +% [1] Neumaier A & Schneider T, 2001. Estimation of parameters and |
| 23 | +% eigenmodes of multivariate autoregressive models. ACM Trans Math |
| 24 | +% Softw, 27:27-57. |
| 25 | +% [2] Schneider T & Neumaier A, 2001. Algorithm 808: ARfit - A Matlab |
| 26 | +% package for the estimation of parameters and eigenmodes of multivariate |
| 27 | +% autoregressive models. ACM Trans Math Softw, 27:58-65. |
| 28 | +% |
| 29 | +% If you are interested in using ARfit algorithm for VAR model estimation, we |
| 30 | +% advise you to get the software from Tapio Schneider's website at |
| 31 | +% https://climate-dynamics.org/software/#arfit |
| 32 | +% or from Mathworks.com File Exchange site (verified on August 27, 2021, but |
| 33 | +% not tested) |
| 34 | +% https://www.mathworks.com/matlabcentral/fileexchange/174-arfit, |
| 35 | +% |
| 36 | +% and, before using it, verify the license terms, it seems to be a copyrighted |
| 37 | +% material by the Association for Computing Machinery, Inc. |
| 38 | +% |
| 39 | +%% Note: As described by the authors, acf.m in ARfit needs Signal Processing |
| 40 | +% Toolbox (TM), as it requires XCORR, a cross-correlation function estimator. |
| 41 | +% |
| 42 | +% ARfit availability was checked on August 13, 2015, and August 27, 2021. KS |
| 43 | +% |
| 44 | +% The version we have tested and included was obtained on February 24, 2011 from |
| 45 | +% www.gps.caltech.edu/~tapio/arfit/index.html, |
| 46 | +% which is now obsolete. |
| 47 | +% |
| 48 | +%% See also: ARFIT, MVAR, MCARNS, MCARVM, CMLSM |
| 49 | + |
| 50 | +% (C) Koichi Sameshima & Luiz A. Baccalá, 2022. |
| 51 | +% See file license.txt in installation directory for licensing terms. |
| 52 | + |
| 53 | +%% |
| 54 | + |
| 55 | +function [pf,A,ef] = arfitcaps(u,IP) |
| 56 | + |
| 57 | +if ~exist('arfit.m','file') |
| 58 | + help arfitcaps |
| 59 | + error('ARfit.m not found. Get the ARfit package from Tapio Schneider''s web site.') |
| 60 | +end; |
| 61 | + |
| 62 | +v = u'; |
| 63 | +[w, Au, C, sbc, fpe, th] = arfit(v,IP,IP); |
| 64 | +pf = C; |
| 65 | + |
| 66 | +if IP >= 20 |
| 67 | + [siglev,res] = arres(w,Au,v,IP+1); |
| 68 | +else |
| 69 | + [siglev,res] = arres(w,Au,v); |
| 70 | +end; |
| 71 | + |
| 72 | +% Variable 'siglev' is not used. |
| 73 | + |
| 74 | +ef = res'; |
| 75 | +A = zeros(length(w),length(w),IP); |
| 76 | +for i = 1:IP |
| 77 | + A(:,:,i) = Au(:,(i-1)*length(w)+1:i*length(w)); |
| 78 | + wu = ceil(length(ef)*rand(size(w))); |
| 79 | + if length(ef)<length(v) |
| 80 | + ef = [ef ef(:,wu(1))]; |
| 81 | + else |
| 82 | + ef = ef(:,1:length(v)); |
| 83 | + end |
| 84 | +end |
0 commit comments