[696a78]: / Supporting Functions / ARMA_BIC.m

Download this file

32 lines (26 with data), 888 Bytes

 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
%GET ARMA PARAMS.
function [arma_mod] = ARMA_BIC(x,op,oq)
%Compute the autocorrelation coefficients.
%[d1,p1] = aryule(x(:,1),3);
%Brockwell and Davis recommend using AICc for finding p-AR and q-MA
LOGL = zeros(op,oq);
PQ = zeros(op,oq);
for p = 1:op
parfor q = 1:oq
mod = arima(p,0,q);
[fit,~,logL] = estimate(mod,x,'print',false);
LOGL(p,q) = logL;
PQ(p,q) = p+q;
end
end
%Find the values that minimize the BIC
LOGL = reshape(LOGL,size(LOGL,1)*size(LOGL,2),1);
PQ = reshape(PQ,size(PQ,1)*size(PQ,2),1);
[~,bic] = aicbic(LOGL,PQ+1,100);
bicmat = reshape(bic,op,oq);
[p_val,q_val] =find(bicmat == min(min(bicmat)));
%Extract the parameters for the AR_model
mod = arima(p_val,0,q_val)
arma_mod = estimate(mod,x)
%armax(x,[p_val,qval])
end