-
Notifications
You must be signed in to change notification settings - Fork 10
/
arord.m
85 lines (70 loc) · 3.09 KB
/
arord.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function [sbc, fpe, logdp, np] = arord(R, m, mcor, ne, pmin, pmax)
%ARORD Evaluates criteria for selecting the order of an AR model.
%
% [SBC,FPE]=ARORD(R,m,mcor,ne,pmin,pmax) returns approximate values
% of the order selection criteria SBC and FPE for models of order
% pmin:pmax. The input matrix R is the upper triangular factor in the
% QR factorization of the AR model; m is the dimension of the state
% vectors; the flag mcor indicates whether or not an intercept vector
% is being fitted; and ne is the number of block equations of size m
% used in the estimation. The returned values of the order selection
% criteria are approximate in that in evaluating a selection
% criterion for an AR model of order p < pmax, pmax-p initial values
% of the given time series are ignored.
%
% ARORD is called by ARFIT.
%
% See also ARFIT, ARQR.
% For testing purposes, ARORD also returns the vectors logdp and np,
% containing the logarithms of the determinants of the (scaled)
% covariance matrix estimates and the number of parameter vectors at
% each order pmin:pmax.
% Modified 17-Dec-99
% Author: Tapio Schneider
imax = pmax-pmin+1; % maximum index of output vectors
% initialize output vectors
sbc = zeros(1, imax); % Schwarz's Bayesian Criterion
fpe = zeros(1, imax); % log of Akaike's Final Prediction Error
logdp = zeros(1, imax); % determinant of (scaled) covariance matrix
np = zeros(1, imax); % number of parameter vectors of length m
np(imax)= m*pmax+mcor;
% Get lower right triangle R22 of R:
%
% | R11 R12 |
% R=| |
% | 0 R22 |
%
R22 = R(np(imax)+1 : np(imax)+m, np(imax)+1 : np(imax)+m);
% From R22, get inverse of residual cross-product matrix for model
% of order pmax
invR22 = inv(R22);
Mp = invR22*invR22';
% For order selection, get determinant of residual cross-product matrix
% logdp = log det(residual cross-product matrix)
logdp(imax) = 2.*log(abs(prod(diag(R22))));
% Compute approximate order selection criteria for models of
% order pmin:pmax
i = imax;
for p = pmax:-1:pmin
np(i) = m*p + mcor; % number of parameter vectors of length m
if p < pmax
% Downdate determinant of residual cross-product matrix
% Rp: Part of R to be added to Cholesky factor of covariance matrix
Rp = R(np(i)+1:np(i)+m, np(imax)+1:np(imax)+m);
% Get Mp, the downdated inverse of the residual cross-product
% matrix, using the Woodbury formula
L = chol(eye(m) + Rp*Mp*Rp')';
N = L \ Rp*Mp;
Mp = Mp - N'*N;
% Get downdated logarithm of determinant
logdp(i) = logdp(i+1) + 2.* log(abs(prod(diag(L))));
end
% Schwarz's Bayesian Criterion
sbc(i) = logdp(i)/m - log(ne) * (ne-np(i))/ne;
% logarithm of Akaike's Final Prediction Error
fpe(i) = logdp(i)/m - log(ne*(ne-np(i))/(ne+np(i)));
% Modified Schwarz criterion (MSC):
% msc(i) = logdp(i)/m - (log(ne) - 2.5) * (1 - 2.5*np(i)/(ne-np(i)));
i = i-1; % go to next lower order
end