代碼摘錄如下:
LogL = zeros(pMax,qMax);%pMax,qMax來自於自相關、偏自相關序列圖顯著階數最(較)大值
SumPQ = LogL;
for p = 1:pMax
for q = 1:qMax
Mdl = arima(p,0,q);
[fit,~,LogL(p,q)] = estimate(Mdl,X,'print',false);%X是待檢驗序列
SumPQ(p,q) = p+q;
end
end
logL = reshape(LogL,pMax*qMax,1);
numParams = reshape(SumPQ,pMax*qMax,1) + 1;
[~,bic] = aicbic(logL,numParams,500);
BIC = reshape(bic,pMax,qMax)
minBIC = min(bic)
[BICbestP,BICbestQ] = find(BIC == minBIC)
Mdl = arima(BICbestP,0,BICbestQ);
[fit,~,~] = estimate(Mdl,lnR,'print',false)