1、文件包中程序均收集、整理、汇总自网络。
2、文件包完整内容:
1)【ARIMA-功能函数】仅包含一个ARIMA算法函数,需要调用到自己的程序中使用。
函数部分代码及预览图:
function [result] = ARIMA_algorithm(data, Periodicity, ACF_P, PACF_Q, n)
m1 = length(data);
%the number of raw data
for i = Periodicity+1:m1
y(i-Periodicity) = data(i)-data(i-Periodicity);
end
%eliminating the periodicity
w = diff(y);
%first-order differential, for eliminating the Trending
m2 = length(w);
%the number of data after first-order differential
k = 0;
%the number of initial exploration models
for i = 0:ACF_P
for j = 0:PACF_Q
if i == 0 && j == 0
continue
elseif i == 0
ToEstMd = arima('MALags',1:j,'Constant',0);
elseif j == 0
ToEstMd = arima('ARLags',1:i,'Constant',0);
else
ToEstMd = arima('ARLags',1:i,'MALags',1:j,'Constant',0);
end
%specify the structure of the model
k = k+1;
R(k) = i;
M(k) = j;
[EstMd, EstParamCov, logL, info] = estimate(ToEstMd,w');
%model fitting
numParams = sum(any(EstParamCov));
%calculate the number of fitting parameters
[aic(k), bic(k)] = aicbic(logL, numParams, m2);
end
end
2)【ARIMA-时间序列分析-浓度数据预测】是根据浓度数据进行预测的完整程序。
主函数部分代码及预览图:
%计算相关函数
r11=autocorr(a); %计算自相关函数
r12=parcorr(a); %计算偏自相关函数
da=diff(a); %数据不平稳所以计算 1 阶差分
r21=autocorr(da); %计算自相关函数
r22=parcorr(da); %计算偏相关函数
n=length(da);
%模型的定阶p、q
u=iddata(da);
test=[];
原始数据集:
运行结果可视化:
3)【ARIMA-时间序列模型的讲解与matlab代码实现】
函数部分代码及文件预览图:
clear;
P = sin(0.1:0.1:9.6);
F = sin(0.1:0.1:9);
%----------------------由于时间序列有不平稳趋势,进行两次差分运算,消除趋势性----------------------%
for i=2:96
Yt(i)=P(i)-P(i-1);
end
for i=3:96
L(i)=Yt(i)-Yt(i-1);
end
L=L(3:96);
Y=L(1:88);
function [yhat , se ] = arimapred(y,phi,theta,d,mu,sa2,l)
% ARIMAPRED(Y,PHI,THETA,D,MU,SA2,L) Forecast ARIMA process
% INPUTS:
% y = observed data; n by 1
% phi = vector of AR coefficients; p by 1
% theta = vector of MA coefficients; q by 1
% d = order of differencing; 1 by 1 integer
% mu = mean of d times differenced y process; 1 by 1
% sa2 = variance of "shocks"; 1 by 1 and positive
% l = forecast lead time; 1 by 1 positive integer
% OUTPUTS:
% yhat = point forecasts; l by 1
% se = prediction standard deviations; 1 by 1
[n m ] = size(y);
z = y;
if d > 0
for k = 1:d
z = z(2:(n-k+1)) - z(1:(n-k));
end
end
ARIMA简单序列的Matlab预测实例.PDF(Page67)