• 第68步 时间序列建模实战:ARIMA建模(Matlab)


    基于WIN10的64位系统演示

    一、写在前面

    这一期,我们使用Matlab进行SARIMA模型的构建。

    不同样,这里使用另一个数据:

    采用《PLoS One》2015年一篇题目为《Comparison of Two Hybrid Models for Forecasting the Incidence of Hemorrhagic Fever with Renal Syndrome in Jiangsu Province, China》文章的公开数据做演示。数据为江苏省2004年1月至2012年12月肾综合症出血热月发病率。运用2004年1月至2011年12月的数据预测2012年12个月的发病率数据。

    Matlab语言,估计很多人没听说过。

    所以,直接上我封装好的Matlab小程序即可。

    二、Matlab建立SARIMA实战

    1.界面介绍

    1.1.数据输入 输入用于预测的原始数据,如图一。

    1.2.原始数据绘图 点击弹出原始数据曲线图,以便观察数据的消长趋势以及周期性。

    1.3.实际值输入 如果用于测试模型的预测精度,此时要预测的数据已知,则输入该数据集。如果用于预测数据,则要预测的数据未知,此时全部输入0。例如要预测6个数据,则需输入6个0。

    1.4.平稳检验和相关图模块

    1.4.1.原始数据 点击原始数据按钮,在相关图模块显示原始数据的自相关图以及偏相关图,并在显示检验结果(是否平稳)。

    1.4.2.一般拆分 填入拆分次数,点击一般拆分按钮,在相关图模块显示经过一般拆分数据的自相关图以及偏相关图,并在显示检验结果(是否平稳);拆分次数即为d值。

    1.4.2.季节性拆分 填入拆分次数,点击季节性拆分按钮,在相关图模块显示经过季节性拆分数据的自相关图以及偏相关图,并在显示检验结果(是否平稳);拆分次数即为D值。

    1.4.3.一般+季节性拆分 点击一般+季节性拆分按钮,在相关图模块显示经过一般和季节性拆分数据的自相关图以及偏相关图,并在显示检验结果(是否平稳)。

    1.5.自动参数寻找模块

    1.5.1.Log 勾选后,原始数据经过Log变换。此选项影响所有步骤,包括平稳性检验、模型构建、拟合和预测。

    1.5.2寻找 必须手动输入参数d和D,周期s默认为12,可以根据实际情况修改。点击寻找按钮后,程序自动寻找最优p、q、P、Q参数(四个参数取值均从0至3);并将最优参数值输出。

    1.6.预测模块

    1.6.1.预测数目(个) 显示需要预测数据的个数,程序自动从实际值输入文本框识别个数并输出。

    1.6.2.模型参数 输入模型7个参数,其中周期s默认为12,可以根据需要修改。

    1.6.3.预测 点击预测按钮后,输出AIC值、BIC值、预测值、实际值,弹出模型参数检验的窗口,并在曲线图模块显示实际值和预测值的曲线图,在误差模块显示预测误差的四个指标。

    1.7.曲线图模块

    1.7.1.拟合 点击拟合按钮后,显示模型拟合效果曲线图,并在误差模块输出拟合误差的四个指标,弹出显示模型具体拟合值的窗口。

    1.7.2.预测 点击拟合按钮后,显示模型拟合效果曲线图,并在误差模块输出拟合误差的四个指标。

    1.8.误差模块

    1.8.1.拟合误差 MAE 输出模型预测的平均绝对误差;

              MAPE 输出模型预测的平均相对误差;

              MSE 输出模型预测的均方误差;

              RMSE 输出模型预测的均方根误差。

    1.8.2.预测误差 MAE 输出模型预测的平均绝对误差;

              MAPE 输出模型预测的平均相对误差;

              MSE 输出模型预测的均方误差;

              RMSE 输出模型预测的均方根误差。

    2.实例演示

    2.1.打开软件,输入原始数据实际值,点击原始数据绘图(这里我们用于测试模型精度,故实际值已知),如图

    2.2.点击原始数据检验按钮,检验结果显示不平稳如图三;

    2.3.可以看到12logs处数值很高,显示具有季节性需进行一次季节性拆分;在季节性拆分按钮后的文本框输入1,点击季节性拆分按钮,检验结果显示平稳如图四;

    2.4.此时可在进行一次一般拆分,在一般拆分按钮后的文本框输入1,点击一般+季节性拆分按钮,检验结果显示平稳,如图

    2.5.输入参数d、D,点击寻找按钮,程序开始寻找最优参数输出,如图六、七;

    2.6.输入参数七个模型参数,点击预测按钮,输出AIC值、BIC值、预测值、实际值,弹出模型参数检验的窗口,并在曲线图模块显示实际值和预测值的曲线图,在误差模块显示预测误差的四个指标,如图

    2.7.在曲线图模块点击拟合按钮,显示模型拟合效果曲线图,并在误差模块输出拟合误差的四个指标,弹出显示模型具体拟合值的窗口,如图

    2.8.拟合预测结果比较

    模型

    预测误差

    拟合误差

    MAE

    MAPE

    MAE

    MAPE

    Matlab ARIMA

    0.0074

    0.4148

    0.0085

    0.4246

    SPSS ARIMA

    0.0090

    0.4859

    0.0089

    0.4219

    由以上图表可知,Matlab所构建的ARIMA模型拟合以及预测效果跟SPSS基本一致。

    三、小软件安装在此处

    1. 双击MCRInstaller.exe安装

    2. 自动解压:

    3. 无脑点击下一步

    4. 安装完成。

    四、底层代码

    可能有需要,我就贴上吧:

    1. function varargout = ARIMAb(varargin)
    2. gui_Singleton = 1;
    3. gui_State = struct('gui_Name', mfilename, ...
    4. 'gui_Singleton', gui_Singleton, ...
    5. 'gui_OpeningFcn', @ARIMA2_OpeningFcn, ...
    6. 'gui_OutputFcn', @ARIMA2_OutputFcn, ...
    7. 'gui_LayoutFcn', [] , ...
    8. 'gui_Callback', []);
    9. if nargin && ischar(varargin{1})
    10. gui_State.gui_Callback = str2func(varargin{1});
    11. end
    12. if nargout
    13. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    14. else
    15. gui_mainfcn(gui_State, varargin{:});
    16. end
    17. function ARIMA2_OpeningFcn(hObject, eventdata, handles, varargin)
    18. global objs
    19. handles.output = hObject;
    20. movegui(hObject,'north')
    21. objs.log=handles.logp;
    22. objs.axes = [handles.axes1;handles.axes2;handles.axes3];
    23. objs.disps1=[handles.jianyanjieguo;handles.yibanchaifen;handles.jijiexingchaifen];
    24. objs.disps2=[handles.ppx;handles.d;handles.q;handles.pp;handles.dd;handles.qq];
    25. objs.disps3 =[handles.ppp;handles.d2;handles.q2;handles.pp2;handles.dd2;handles.qq2];
    26. objs.disps4=[handles.aic2;handles.bic2;handles.yucezhi2;handles.shijizhi2];
    27. objs.disps5=[handles.mae;handles.mse;handles.mape;handles.rmse;handles.mae2;handles.mse2;handles.mape2;handles.rmse2];
    28. objs.disps6=[handles.yuceshumu2;handles.s;handles.s2];
    29. guidata(hObject, handles);
    30. function varargout = ARIMA2_OutputFcn(hObject, eventdata, handles)
    31. varargout{1} = handles.output;
    32. function shujushuru_Callback(hObject, eventdata, handles)
    33. input = str2num(get(hObject,'String'));
    34. guidata(hObject,handles);
    35. function shujushuru_CreateFcn(hObject, eventdata, handles)
    36. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    37. set(hObject,'BackgroundColor','white');
    38. end
    39. function yuanshishujujianyan_Callback(hObject, eventdata, handles)
    40. global X objs
    41. X = str2num(get(handles.shujushuru,'String'));
    42. if isempty(X)
    43. return
    44. end
    45. if eq(get(objs.log,'Value'),1)
    46. X = log(X);
    47. end
    48. h = adftest (X);
    49. if h == 1
    50. U = {'平稳'}
    51. set (handles.jianyanjieguo,'String',U);
    52. else
    53. U = {'不平稳'}
    54. set (handles.jianyanjieguo,'String',U);
    55. end
    56. axes(handles.axes1)
    57. autocorr(X);
    58. axes(handles.axes2)
    59. parcorr(X);
    60. guidata(hObject,handles);
    61. function chaifenshujujianyan_Callback(hObject, eventdata, handles)
    62. global X T W Z objs
    63. X = str2num(get(handles.shujushuru,'String'));
    64. W = str2num(get(handles.jijiexingchaifen,'String'));
    65. Z = str2num(get(handles.zhouqi,'String'));
    66. if isempty(X) || isempty(T) || isempty(W) || isempty(Z)
    67. return
    68. end
    69. if eq(get(objs.log,'Value'),1)
    70. X = log(X);
    71. end
    72. o = length (X')/Z;
    73. for R = 1:1:o;
    74. Q = X (:,((R-1)*Z+1):Z*R)
    75. data{R} = Q
    76. end;
    77. for S= 1:1:W;
    78. test =[];
    79. for R = 1:1:(o-S);
    80. sea = data{R+1} - data{R}
    81. test=[test,sea]
    82. end
    83. end;
    84. h = adftest(test);
    85. if h == 1
    86. U={'ƽÎÈ'}
    87. set(handles.jianyanjieguo,'String',U)
    88. else
    89. U={'²»Æ½ÎÈ'}
    90. set(handles.jianyanjieguo,'String',U)
    91. end
    92. axes(handles.axes1)
    93. autocorr(test);
    94. axes(handles.axes2)
    95. parcorr(test);
    96. guidata(hObject,handles);
    97. function yuceshumu1_Callback(hObject, eventdata, handles)
    98. input = str2num(get(hObject,'String'));
    99. if (isempty(input))
    100. set(hObject,'String','0')
    101. end
    102. guidata(hObject,handles);
    103. function yuceshumu1_CreateFcn(hObject, eventdata, handles)
    104. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    105. set(hObject,'BackgroundColor','white');
    106. end
    107. function ppx_Callback(hObject, eventdata, handles)
    108. function ppx_CreateFcn(hObject, eventdata, handles)
    109. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    110. set(hObject,'BackgroundColor','white');
    111. end
    112. function d_Callback(hObject, eventdata, handles)
    113. function d_CreateFcn(hObject, eventdata, handles)
    114. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    115. set(hObject,'BackgroundColor','white');
    116. end
    117. function q_Callback(hObject, eventdata, handles)
    118. input = str2num(get(hObject,'String'));
    119. if (isempty(input))
    120. set(hObject,'String','0')
    121. end
    122. guidata(hObject,handles);
    123. function q_CreateFcn(hObject, eventdata, handles)
    124. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    125. set(hObject,'BackgroundColor','white');
    126. end
    127. function pp_Callback(hObject, eventdata, handles)
    128. function pp_CreateFcn(hObject, eventdata, handles)
    129. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    130. set(hObject,'BackgroundColor','white');
    131. end
    132. function dd_Callback(hObject, eventdata, handles)
    133. function dd_CreateFcn(hObject, eventdata, handles)
    134. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    135. set(hObject,'BackgroundColor','white');
    136. end
    137. function qq_Callback(hObject, eventdata, handles)
    138. function qq_CreateFcn(hObject, eventdata, handles)
    139. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    140. set(hObject,'BackgroundColor','white');
    141. end
    142. function s_Callback(hObject, eventdata, handles)
    143. input = str2num(get(hObject,'String'));
    144. if (isempty(input))
    145. set(hObject,'String','0')
    146. end
    147. guidata(hObject,handles);
    148. function s_CreateFcn(hObject, eventdata, handles)
    149. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    150. set(hObject,'BackgroundColor','white');
    151. end
    152. function pushbutton5_Callback(hObject, eventdata, handles)
    153. global X objs
    154. X = str2num(get(handles.shujushuru,'String'));
    155. ss = str2num(get(handles.s,'String'));
    156. value1 = str2num(get(handles.d,'String'));
    157. value2 = str2num(get(handles.dd,'String'));
    158. if isempty(X) || isempty(value1) || isempty(value2) || isempty(ss)
    159. return
    160. end
    161. X = X';
    162. if eq(get(objs.log,'Value'),1)
    163. X = log(X);
    164. end
    165. test =[];
    166. ind = [];
    167. for p =0:1:3
    168. for d = value1
    169. for q = 0:1:3
    170. for dap =0:1:3
    171. for dad =value2;
    172. for daq = 0:1:3
    173. ind = [ind;p d q dap dad daq];
    174. end
    175. end
    176. end
    177. end
    178. end
    179. end
    180. T = size(ind,1);
    181. tl = length(X);
    182. v1 = zeros(T,1);
    183. v2 = zeros(T,1);
    184. h = waitbar(0,'1','Name','优化ARIMA参数',...
    185. 'CreateCancelBtn',...
    186. 'setappdata(gcbf,''canceling'',1)');
    187. setappdata(h,'canceling',0)
    188. for i = 1:T
    189. if getappdata(h,'canceling')
    190. break
    191. end
    192. p = ind(i,1);
    193. d = ind(i,2);
    194. q = ind(i,3);
    195. dap=ind(i,4);
    196. dad=ind(i,5);
    197. daq=ind(i,6);
    198. if eq(p,0) && eq(q,0) && eq(dap,0) && eq(daq,0)
    199. amodel = arima('D',d,'Seasonality',ss*dad,'Constant',0);
    200. elseif ~eq(p,0) && eq(q,0) && eq(dap,0) && eq(daq,0)
    201. amodel = arima('ARLags',1:p,'D',d,'Seasonality',ss*dad,'Constant',0);
    202. elseif eq(p,0) && ~eq(q,0) && eq(dap,0) && eq(daq,0)
    203. amodel = arima('MALags',1:q,'D',d,'Seasonality',ss*dad,'Constant',0);
    204. elseif eq(p,0) && eq(q,0) && ~eq(dap,0) && eq(daq,0)
    205. amodel = arima('SARLags',1:dap,'D',d,'Seasonality',ss*dad,'Constant',0);
    206. elseif eq(p,0) && eq(q,0) && eq(dap,0) && ~eq(daq,0)
    207. amodel = arima('SMALags',1:daq,'D',d,'Seasonality',ss*dad,'Constant',0);
    208. elseif ~eq(p,0) && ~eq(q,0) && eq(dap,0) && eq(daq,0)
    209. amodel = arima('ARLags',1:p,'MALags',1:q,'D',d,'Seasonality',ss*dad,'Constant',0);
    210. elseif ~eq(p,0) && eq(q,0) && ~eq(dap,0) && eq(daq,0)
    211. amodel = arima('ARLags',1:p,'SARLags',(1:dap)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    212. elseif ~eq(p,0) && eq(q,0) && eq(dap,0) && ~eq(daq,0)
    213. amodel = arima('ARLags',1:p,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    214. elseif eq(p,0) && ~eq(q,0) && ~eq(dap,0) && eq(daq,0)
    215. amodel = arima('MALags',1:q,'SARLags',(1:dap)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    216. elseif eq(p,0) && ~eq(q,0) && eq(dap,0) && ~eq(daq,0)
    217. amodel = arima('MALags',1:q,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    218. elseif eq(p,0) && eq(q,0) && ~eq(dap,0) && ~eq(daq,0)
    219. amodel = arima('SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    220. elseif ~eq(p,0) && ~eq(q,0) && ~eq(dap,0) && eq(daq,0)
    221. amodel = arima('ARLags',1:p,'MALags',1:q,'SARLags',(1:dap)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    222. elseif ~eq(p,0) && ~eq(q,0) && eq(dap,0) && ~eq(daq,0)
    223. amodel = arima('ARLags',1:p,'MALags',1:q,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    224. elseif ~eq(p,0) && eq(q,0) && ~eq(dap,0) && ~eq(daq,0)
    225. amodel = arima('ARLags',1:p,'SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    226. elseif eq(p,0) && ~eq(q,0) && ~eq(dap,0) && ~eq(daq,0)
    227. amodel = arima('MALags',1:q,'SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    228. else
    229. amodel = arima('ARLags',1:p,'MALags',1:q,'SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    230. end
    231. if numel(X) >= max(amodel.P + amodel.Q + 1);
    232. [EstMdl,VarCov,logL,info]=estimate(amodel,X,'Display','off');
    233. f = length(X)-EstMdl.P;
    234. errors = sqrt(diag(VarCov));
    235. parameters = info.X;
    236. tvalues = parameters./errors;
    237. pvalues = zeros(size(tvalues));
    238. for ii = 1:length(pvalues)
    239. pvalues(ii) = (1-tcdf(abs(tvalues(ii)),f))*2;
    240. end
    241. n = size (VarCov,1);
    242. [aic,bic] = aicbic (logL,n,tl);
    243. v1(i) = aic;
    244. v2(i) = bic;
    245. if length(pvalues)>2
    246. pvalues = pvalues(2:end-1);
    247. if any(pvalues>0.05)
    248. v1(i) = 3*10e8;
    249. end
    250. end
    251. else
    252. v1(i) = 4*10e8;
    253. v2(i) = 4*10e8;
    254. end
    255. waitbar(i/T,h,['Runing ',num2str(i),' out of ',num2str(T)]);
    256. end
    257. delete(h);
    258. [a,b] = min(v1);
    259. re = ind(b,:);
    260. set(handles.ppx,'String',num2str(re(1)));
    261. set(handles.d,'String',num2str(re(2)));
    262. set(handles.q,'String',num2str(re(3)));
    263. set(handles.pp,'String',num2str(re(4)));
    264. set(handles.dd,'String',num2str(re(5)));
    265. set(handles.qq,'String',num2str(re(6)));
    266. set(handles.s,'String',num2str(12));
    267. guidata(hObject,handles);
    268. function yuanshishujuxiangguantu_Callback(hObject, eventdata, handles)
    269. global X objs
    270. if eq(get(objs.log,'Value'),1)
    271. X = log(X);
    272. end
    273. axes(handles.axes1)
    274. autocorr(X);
    275. axes(handles.axes2)
    276. parcorr(X);
    277. function chaifenshujuxiangguantu_Callback(hObject, eventdata, handles)
    278. global X T W Z objs
    279. X = str2num(get(handles.shujushuru,'String'));
    280. T = str2num(get(handles.yibanchaifend,'String'));
    281. W = str2num(get(handles.jijiexingchaifen,'String'));
    282. Z = str2num(get(handles.zhouqi,'String'));
    283. if eq(get(objs.log,'Value'),1)
    284. X = log(X);
    285. end
    286. o = length (X')/Z;
    287. for R = 1:1:o;
    288. Q= X (:,((R-1)*Z+1):Z*R)
    289. data{R}=Q
    290. end;
    291. for S= 1:1:W;
    292. test =[];
    293. for R = 1:1:(o-S);
    294. sea = data{R+1} - data{R};
    295. test=[test,sea] ;
    296. end
    297. end;
    298. Y = diff(test,T);
    299. axes(handles.axes1)
    300. autocorr(Y);
    301. axes(handles.axes2)
    302. parcorr(Y);
    303. function yibanchaifend_Callback(hObject, eventdata, handles)
    304. global X T objs
    305. X = str2num(get(handles.shujushuru,'String'));
    306. T = str2num(get(handles.yibanchaifen,'String'));
    307. if isempty(X) || isempty(T)
    308. return
    309. end
    310. if eq(get(objs.log,'Value'),1)
    311. X = log(X);
    312. end
    313. X =X';
    314. Y = diff (X,T);
    315. h = adftest (Y);
    316. if h == 1
    317. U={'ƽÎÈ'};
    318. set(handles.jianyanjieguo,'String',U)
    319. else
    320. U={'²»Æ½ÎÈ'};
    321. set(handles.jianyanjieguo,'String',U)
    322. end
    323. axes(handles.axes1)
    324. autocorr(Y);
    325. axes(handles.axes2)
    326. parcorr(Y);
    327. guidata(hObject,handles);
    328. function yibanchaifend_CreateFcn(hObject, eventdata, handles)
    329. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    330. set(hObject,'BackgroundColor','white');
    331. end
    332. function jijiexingchaifen_Callback(hObject, eventdata, handles)
    333. input = str2num(get(hObject,'String'));
    334. if (isempty(input))
    335. set(hObject,'String','0')
    336. end
    337. guidata(hObject,handles);
    338. function jijiexingchaifen_CreateFcn(hObject, eventdata, handles)
    339. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    340. set(hObject,'BackgroundColor','white');
    341. end
    342. function zhouqi_Callback(hObject, eventdata, handles)
    343. input = str2num(get(hObject,'String'));
    344. if (isempty(input))
    345. set(hObject,'String','0')
    346. end
    347. guidata(hObject,handles);
    348. function zhouqi_CreateFcn(hObject, eventdata, handles)
    349. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    350. set(hObject,'BackgroundColor','white');
    351. end
    352. function jianyanjieguo_Callback(hObject, eventdata, handles)
    353. function jianyanjieguo_CreateFcn(hObject, eventdata, handles)
    354. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    355. set(hObject,'BackgroundColor','white');
    356. end
    357. function shijizhi_Callback(hObject, eventdata, handles)
    358. function shijizhi_CreateFcn(hObject, eventdata, handles)
    359. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    360. set(hObject,'BackgroundColor','white');
    361. end
    362. function aic_Callback(hObject, eventdata, handles)
    363. function aic_CreateFcn(hObject, eventdata, handles)
    364. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    365. set(hObject,'BackgroundColor','white');
    366. end
    367. function yucezhi_Callback(hObject, eventdata, handles)
    368. function yucezhi_CreateFcn(hObject, eventdata, handles)
    369. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    370. set(hObject,'BackgroundColor','white');
    371. end
    372. function yuceshumu2_Callback(hObject, eventdata, handles)
    373. input = str2num(get(hObject,'String'));
    374. if (isempty(input))
    375. set(hObject,'String','0')
    376. end
    377. guidata(hObject,handles);
    378. function yuceshumu2_CreateFcn(hObject, eventdata, handles)
    379. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    380. set(hObject,'BackgroundColor','white');
    381. end
    382. function canshup_Callback(hObject, eventdata, handles)
    383. input = str2num(get(hObject,'String'));
    384. if (isempty(input))
    385. set(hObject,'String','0')
    386. end
    387. guidata(hObject,handles);
    388. function canshup_CreateFcn(hObject, eventdata, handles)
    389. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    390. set(hObject,'BackgroundColor','white');
    391. end
    392. function d2_Callback(hObject, eventdata, handles)
    393. input = str2num(get(hObject,'String'));
    394. if (isempty(input))
    395. set(hObject,'String','NaN')
    396. end
    397. guidata(hObject,handles);
    398. function d2_CreateFcn(hObject, eventdata, handles)
    399. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    400. set(hObject,'BackgroundColor','white');
    401. end
    402. function q2_Callback(hObject, eventdata, handles)
    403. input = str2num(get(hObject,'String'));
    404. if (isempty(input))
    405. set(hObject,'String','NaN')
    406. end
    407. guidata(hObject,handles);
    408. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    409. set(hObject,'BackgroundColor','white');
    410. end
    411. function pp2_Callback(hObject, eventdata, handles)
    412. input = str2num(get(hObject,'String'));
    413. if (isempty(input))
    414. set(hObject,'String','NaN')
    415. end
    416. guidata(hObject,handles);
    417. function pp2_CreateFcn(hObject, eventdata, handles)
    418. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    419. set(hObject,'BackgroundColor','white');
    420. end
    421. function dd2_Callback(hObject, eventdata, handles)
    422. input = str2num(get(hObject,'String'));
    423. if (isempty(input))
    424. set(hObject,'String','NaN')
    425. end
    426. guidata(hObject,handles);
    427. function dd2_CreateFcn(hObject, eventdata, handles)
    428. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    429. set(hObject,'BackgroundColor','white');
    430. end
    431. function qq2_Callback(hObject, eventdata, handles)
    432. input = str2num(get(hObject,'String'));
    433. if (isempty(input))
    434. set(hObject,'String','NaN')
    435. end
    436. guidata(hObject,handles);
    437. function qq2_CreateFcn(hObject, eventdata, handles)
    438. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    439. set(hObject,'BackgroundColor','white');
    440. end
    441. function s2_Callback(hObject, eventdata, handles)
    442. input = str2num(get(hObject,'String'));
    443. if (isempty(input))
    444. set(hObject,'String','NaN')
    445. end
    446. guidata(hObject,handles);
    447. function s2_CreateFcn(hObject, eventdata, handles)
    448. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    449. set(hObject,'BackgroundColor','white');
    450. end
    451. function yuce2_Callback(hObject, eventdata, handles)
    452. global X K B C A E F G H I L M T objs model
    453. X = str2num(get(handles.shujushuru,'String'));
    454. K = str2num(get(handles.ppp,'String'));
    455. B = str2num(get(handles.d2,'String'));
    456. C = str2num(get(handles.q2,'String'));
    457. A = str2num(get(handles.pp2,'String'));
    458. E = str2num(get(handles.dd2,'String'));
    459. F = str2num(get(handles.qq2,'String'));
    460. G = str2num(get(handles.s2,'String'));
    461. H = str2num(get(handles.yuceshumu2,'String'));
    462. M = str2num(get(handles.shijizhishuru,'String'));
    463. if isempty(X) || isempty(K) || isempty(B) || isempty(C) || isempty(A) || isempty(E) || isempty(F) || isempty(G) || isempty(H) ||isempty(M)
    464. return
    465. end
    466. if eq(get(objs.log,'Value'),1)
    467. I = log(X');
    468. else
    469. I = X';
    470. end
    471. p = K;d=B;q = C;dap=A;daq=F;dad=E;ss=G;
    472. if eq(p,0) && eq(q,0) && eq(dap,0) && eq(daq,0)
    473. amodel = arima('D',d,'Seasonality',ss*dad,'Constant',0);
    474. elseif ~eq(p,0) && eq(q,0) && eq(dap,0) && eq(daq,0)
    475. amodel = arima('ARLags',1:p,'D',d,'Seasonality',ss*dad,'Constant',0);
    476. elseif eq(p,0) && ~eq(q,0) && eq(dap,0) && eq(daq,0)
    477. amodel = arima('MALags',1:q,'D',d,'Seasonality',ss*dad,'Constant',0);
    478. elseif eq(p,0) && eq(q,0) && ~eq(dap,0) && eq(daq,0)
    479. amodel = arima('SARLags',1:dap,'D',d,'Seasonality',ss*dad,'Constant',0);
    480. elseif eq(p,0) && eq(q,0) && eq(dap,0) && ~eq(daq,0)
    481. amodel = arima('SMALags',1:daq,'D',d,'Seasonality',ss*dad,'Constant',0);
    482. elseif ~eq(p,0) && ~eq(q,0) && eq(dap,0) && eq(daq,0)
    483. amodel = arima('ARLags',1:p,'MALags',1:q,'D',d,'Seasonality',ss*dad,'Constant',0);
    484. elseif ~eq(p,0) && eq(q,0) && ~eq(dap,0) && eq(daq,0)
    485. amodel = arima('ARLags',1:p,'SARLags',(1:dap)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    486. elseif ~eq(p,0) && eq(q,0) && eq(dap,0) && ~eq(daq,0)
    487. amodel = arima('ARLags',1:p,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    488. elseif eq(p,0) && ~eq(q,0) && ~eq(dap,0) && eq(daq,0)
    489. amodel = arima('MALags',1:q,'SARLags',(1:dap)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    490. elseif eq(p,0) && ~eq(q,0) && eq(dap,0) && ~eq(daq,0)
    491. amodel = arima('MALags',1:q,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    492. elseif eq(p,0) && eq(q,0) && ~eq(dap,0) && ~eq(daq,0)
    493. amodel = arima('SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    494. elseif ~eq(p,0) && ~eq(q,0) && ~eq(dap,0) && eq(daq,0)
    495. amodel = arima('ARLags',1:p,'MALags',1:q,'SARLags',(1:dap)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    496. elseif ~eq(p,0) && ~eq(q,0) && eq(dap,0) && ~eq(daq,0)
    497. amodel = arima('ARLags',1:p,'MALags',1:q,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    498. elseif ~eq(p,0) && eq(q,0) && ~eq(dap,0) && ~eq(daq,0)
    499. amodel = arima('ARLags',1:p,'SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    500. elseif eq(p,0) && ~eq(q,0) && ~eq(dap,0) && ~eq(daq,0)
    501. amodel = arima('MALags',1:q,'SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    502. else
    503. amodel = arima('ARLags',1:p,'MALags',1:q,'SARLags',(1:dap)*ss,'SMALags',(1:daq)*ss,'D',d,'Seasonality',ss*dad,'Constant',0);
    504. end
    505. model3=amodel;
    506. if numel(X) <= max(amodel.P + amodel.Q + 1);
    507. msgbox('待估计变量数目大于样本数目,无法计算!');
    508. return
    509. end
    510. [fit3,VarCov,logL,info] = estimate(model3,I);
    511. f = length(I)-fit3.P;
    512. errors = sqrt(diag(VarCov));
    513. parameters = info.X;
    514. tvalues = parameters./errors;
    515. pvalues = zeros(size(tvalues));
    516. for i = 1:length(pvalues)
    517. pvalues(i) = (1-tcdf(abs(tvalues(i)),f))*2;
    518. end
    519. strs = [];
    520. if ~eq(p,0)
    521. for i = 1:p
    522. strs = [strs,{['AR(',num2str(i),')']}];%%%%
    523. end
    524. end
    525. if ~eq(dap,0)
    526. for i = 1:dap
    527. strs = [strs,{['SAR(',num2str(i*ss),')']}];%%%%
    528. end
    529. end
    530. if ~eq(q,0)
    531. for i = 1:q
    532. strs = [strs,{['MA(',num2str(i),')']}];%%%%
    533. end
    534. end
    535. if ~eq(daq,0)
    536. for i=1:daq
    537. strs = [strs,{['SMA(',num2str(i*ss),')']}];
    538. end
    539. end
    540. info1 = {'Parameter','Value','Standard Error','t Statistic','p Statistic'};
    541. info2 = [{'Constant'},num2cell(0),{'Fixed'},{'Fixed'},{'Fixed'}];
    542. info3 = [strs,{'Variance'}]';
    543. info4 = [info.X(2:end),errors(2:end),tvalues(2:end),pvalues(2:end)];
    544. info5 = [info1;info2;info3 num2cell(info4)];
    545. f = figure;
    546. setpixelposition(f,[680,558,560,220]);
    547. uitable(f,'Data',info5,'unit','normalized','position',[0 0 1 1],'ColumnWidth',{100});
    548. [yF,yMSE] = forecast(fit3,H,'Y0',I);
    549. if eq(get(objs.log,'Value'),1)
    550. L = exp(yF);
    551. end
    552. M = M';
    553. MAE = mean(abs(L - M));
    554. MAPE = mean(abs(L - M)./M);
    555. MSE = mse (L - M);
    556. RMSE = sqrt(mse(L - M));
    557. [hang,lie] = size (VarCov);
    558. T = length(X);
    559. [aic,bic] = aicbic (logL,hang,T);
    560. set (handles.aic2,'String',num2str(aic));
    561. set (handles.bic2,'String',num2str(bic));
    562. set (handles.mae2,'String',num2str(MAE));
    563. set (handles.mape2,'String',num2str(MAPE));
    564. set (handles.mse2,'String',num2str(MSE));
    565. set (handles.rmse2,'String',num2str(RMSE));
    566. set (handles.yucezhi2,'String',num2str(L),'Max',2);
    567. set (handles.shijizhi2,'String',num2str(M),'Max',2);
    568. axes(handles.axes3)
    569. plot(M,'r','LineWidth',2);
    570. hold on
    571. plot(L,'k--','LineWidth',1.5);
    572. xlim([0,H])
    573. title('预测效果拟合曲线')
    574. legend('实际值','预测值','Location','NorthEast')
    575. hold off
    576. model = fit3;
    577. guidata(hObject,handles);
    578. function shijizhi2_Callback(hObject, eventdata, handles)
    579. function shijizhi2_CreateFcn(hObject, eventdata, handles)
    580. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    581. set(hObject,'BackgroundColor','white');
    582. end
    583. function aic2_Callback(hObject, eventdata, handles)
    584. function aic2_CreateFcn(hObject, eventdata, handles)
    585. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    586. set(hObject,'BackgroundColor','white');
    587. end
    588. function yucezhi2_Callback(hObject, eventdata, handles)
    589. function yucezhi2_CreateFcn(hObject, eventdata, handles)
    590. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    591. set(hObject,'BackgroundColor','white');
    592. end
    593. function nihexiaoguo_Callback(hObject, eventdata, handles)
    594. global model X objs
    595. if isempty(X) || isempty(model)
    596. return
    597. end
    598. if eq(get(objs.log,'Value'),1)
    599. y = log(X');
    600. else
    601. y = X';
    602. end
    603. yv = zeros(size(y));
    604. h = waitbar(0,'ÇëµÈ´ý');
    605. for i = model.P:length(yv)-1
    606. vF1 = forecast(model,1,'Y0',y(1:i));
    607. yv(i+1) = vF1;
    608. waitbar(i/(length(yv)-1),h);
    609. end
    610. delete(h);
    611. yv(1:model.P) =[];
    612. y(1:model.P)=[];
    613. if eq(get(objs.log,'Value'),1)
    614. y = exp(y);
    615. yv=exp(yv);
    616. end
    617. f = figure;
    618. dispdata = [{'y','yp'};num2cell([y yv])];
    619. uitable(f,'Data',dispdata,'unit','normalized','position',[0 0 1 1],'ColumnWidth',{100});
    620. MAE = mean(abs(y - yv));
    621. MAPE = mean(abs(y - yv)./y);
    622. MSE = mse(y - yv);
    623. RMSE = sqrt(mse(y - yv));
    624. set(objs.disps5(1),'String',MAE);
    625. set(objs.disps5(2),'String',MSE);
    626. set(objs.disps5(3),'String',MAPE);
    627. set(objs.disps5(4),'String',RMSE);
    628. axes(handles.axes3)
    629. plot(y,'r','LineWidth',2);
    630. hold on
    631. plot(yv,'k--','LineWidth',1.5);
    632. xlim([0,length(y)])
    633. title('拟合曲线')
    634. legend('实际值','拟合值','Location','NorthEast')
    635. hold off
    636. guidata(hObject,handles);
    637. function yucexiaoguo_Callback(hObject, eventdata, handles)
    638. global X K B C A E F G H I L M T objs model
    639. X = str2num(get(handles.shujushuru,'String'));
    640. K = str2num(get(handles.ppp,'String'));
    641. B = str2num(get(handles.d2,'String'));
    642. C = str2num(get(handles.q2,'String'));
    643. A = str2num(get(handles.pp2,'String'));
    644. E = str2num(get(handles.dd2,'String'));
    645. F = str2num(get(handles.qq2,'String'));
    646. G = str2num(get(handles.s2,'String'));
    647. H = str2num(get(handles.yuceshumu2,'String'));
    648. M = str2num(get(handles.shijizhishuru,'String'));
    649. if isempty(X) || isempty(K) || isempty(B) || isempty(C) || isempty(A) || isempty(E) || isempty(F) || isempty(G) || isempty(H) ||isempty(M) ||isempty(model)
    650. return
    651. end
    652. if eq(get(objs.log,'Value'),1)
    653. I = log(X');
    654. else
    655. I = X';
    656. end
    657. fit3=model;
    658. [yF,yMSE] = forecast(fit3,H,'Y0',I);
    659. if eq(get(objs.log,'Value'),1)
    660. L = exp(yF);
    661. end
    662. axes(handles.axes3)
    663. plot(M,'r','LineWidth',2);
    664. hold on
    665. plot(L,'k--','LineWidth',1.5);
    666. xlim([0,H])
    667. title('预测效果拟合曲线')
    668. legend('实际值','预测值','Location','NorthEast')
    669. hold off
    670. model = fit3;
    671. guidata(hObject,handles);
    672. function mae_Callback(hObject, eventdata, handles)
    673. function mae_CreateFcn(hObject, eventdata, handles)
    674. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    675. set(hObject,'BackgroundColor','white');
    676. end
    677. function mape_Callback(hObject, eventdata, handles)
    678. function mape_CreateFcn(hObject, eventdata, handles)
    679. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    680. set(hObject,'BackgroundColor','white');
    681. end
    682. function mse_Callback(hObject, eventdata, handles)
    683. function mse_CreateFcn(hObject, eventdata, handles)
    684. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    685. set(hObject,'BackgroundColor','white');
    686. end
    687. function rmse_Callback(hObject, eventdata, handles)
    688. function rmse_CreateFcn(hObject, eventdata, handles)
    689. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    690. set(hObject,'BackgroundColor','white');
    691. end
    692. function mae2_Callback(hObject, eventdata, handles)
    693. function mae2_CreateFcn(hObject, eventdata, handles)
    694. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    695. set(hObject,'BackgroundColor','white');
    696. end
    697. function mape2_Callback(hObject, eventdata, handles)
    698. function mape2_CreateFcn(hObject, eventdata, handles)
    699. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    700. set(hObject,'BackgroundColor','white');
    701. end
    702. function mse2_Callback(hObject, eventdata, handles)
    703. function mse2_CreateFcn(hObject, eventdata, handles)
    704. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    705. set(hObject,'BackgroundColor','white');
    706. end
    707. function rmse2_Callback(hObject, eventdata, handles)
    708. function rmse2_CreateFcn(hObject, eventdata, handles)
    709. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    710. set(hObject,'BackgroundColor','white');
    711. end
    712. function ppp_Callback(hObject, eventdata, handles)
    713. input = str2num(get(hObject,'String'));
    714. if (isempty(input))
    715. set(hObject,'String','NaN')
    716. end
    717. guidata(hObject,handles);
    718. function ppp_CreateFcn(hObject, eventdata, handles)
    719. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    720. set(hObject,'BackgroundColor','white');
    721. end
    722. function shijizhishuru_Callback(hObject, eventdata, handles)
    723. global objs
    724. num = str2num(get(hObject,'String'));
    725. if length(num)>1
    726. set(objs.disps6(1),'String',num2str(length(num)));
    727. end
    728. guidata(hObject,handles);
    729. function shijizhishuru_CreateFcn(hObject, eventdata, handles)
    730. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    731. set(hObject,'BackgroundColor','white');
    732. end
    733. function yuanshishujuhuitu_Callback(hObject, eventdata, handles)
    734. global X T
    735. X = str2num(get(handles.shujushuru,'String'));
    736. if isempty(X)
    737. return
    738. end
    739. T = length (X);
    740. figure
    741. hold on
    742. plot(X,'k-','LineWidth',1.5)
    743. xlim([0,T])
    744. title('原始数据曲线图')
    745. hold off
    746. guidata(hObject,handles);
    747. function yibanjijiexingchaifen_Callback(hObject, eventdata, handles)
    748. global X T W Z objs
    749. X = str2num(get(handles.shujushuru,'String'));
    750. T = str2num(get(handles.yibanchaifen,'String'));
    751. W = str2num(get(handles.jijiexingchaifen,'String'));
    752. Z = str2num(get(handles.zhouqi,'String'));
    753. if isempty(X) || isempty(T) || isempty(W) || isempty(Z)
    754. return
    755. end
    756. if eq(get(objs.log,'Value'),1)
    757. X = log(X);
    758. end
    759. o = length (X')/Z;
    760. for R = 1:1:o;
    761. Q = X (:,((R-1)*Z+1):Z*R)
    762. data{R} = Q
    763. end;
    764. for S= 1:1:W;
    765. test =[];
    766. for R = 1:1:(o-S);
    767. sea = data{R+1} - data{R}
    768. test=[test,sea]
    769. end
    770. end;
    771. Y = diff(test,T);
    772. h = adftest(Y);
    773. if h == 1
    774. U={'平稳'}
    775. set(handles.jianyanjieguo,'String',U)
    776. else
    777. U={'不平稳'}
    778. set(handles.jianyanjieguo,'String',U)
    779. end
    780. axes(handles.axes1)
    781. autocorr(Y);
    782. axes(handles.axes2)
    783. parcorr(Y);
    784. guidata(hObject,handles);
    785. function bic2_Callback(hObject, eventdata, handles)
    786. function bic2_CreateFcn(hObject, eventdata, handles)
    787. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    788. set(hObject,'BackgroundColor','white');
    789. end
    790. function bic_Callback(hObject, eventdata, handles)
    791. function bic_CreateFcn(hObject, eventdata, handles)
    792. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    793. set(hObject,'BackgroundColor','white');
    794. end
    795. function pushbutton12_Callback(hObject, eventdata, handles)
    796. global X K B C A E F G H I L M T
    797. X = str2num(get(handles.shujushuru,'String'));
    798. K = str2num(get(handles.ppx,'String'));
    799. B = str2num(get(handles.d,'String'));
    800. C = str2num(get(handles.q,'String'));
    801. A = str2num(get(handles.pp,'String'));
    802. E = str2num(get(handles.dd,'String'));
    803. F = str2num(get(handles.qq,'String'));
    804. G = str2num(get(handles.s,'String'));
    805. H = str2num(get(handles.yuceshumu,'String'));
    806. M = str2num(get(handles.shijizhishuru,'String'));
    807. I = log(X');
    808. model3 = arima('ARLags',K,'MALags',C,'D',B,'SARLags',A*G,'SMALags',F*G,'Seasonality',G,'Constant',0);
    809. [fit3,VarCov,logL,info] = estimate(model3,I);
    810. [yF,yMSE] = forecast(fit3,H,'Y0',I);
    811. L = exp (yF);
    812. M = M';
    813. MAE = mean(abs(L - M));
    814. MAPE = mean(abs(L - M)./M);
    815. MSE = mse (L - M);
    816. RMSE = sqrt(mse(L - M));
    817. [hang,lie] = size (VarCov);
    818. T = length(X);
    819. [aic,bic] = aicbic (logL,hang,T);
    820. set (handles.aic,'String',num2str(aic));
    821. set (handles.bic,'String',num2str(bic));
    822. set (handles.mae2,'String',num2str(MAE));
    823. set (handles.mape2,'String',num2str(MAPE));
    824. set (handles.mse2,'String',num2str(MSE));
    825. set (handles.rmse2,'String',num2str(RMSE));
    826. set (handles.yucezhi,'String',num2str(L),'Max',2);
    827. set (handles.shijizhi,'String',num2str(M),'Max',2);
    828. axes(handles.axes3)
    829. plot(M,'r','LineWidth',2);
    830. hold on
    831. plot(L,'k--','LineWidth',1.5);
    832. xlim([0,H])
    833. title('Ô¤²âЧ¹ûÄâºÏÇúÏß')
    834. legend('ʵ¼ÊÖµ','Ô¤²âÖµ','Location','NorthEast')
    835. hold off
    836. guidata(hObject,handles);
    837. function yibanchaifen_Callback(hObject, eventdata, handles)
    838. function yibanchaifen_CreateFcn(hObject, eventdata, handles)
    839. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    840. set(hObject,'BackgroundColor','white');
    841. end
    842. function logp_Callback(hObject, eventdata, handles)
    843. global objs
    844. for i = 1:length(objs.axes)
    845. cla(objs.axes(i))
    846. end
    847. set(objs.disps1,'String','');
    848. set(objs.disps2,'String','');
    849. set(objs.disps3,'String','');
    850. set(objs.disps4,'String','');
    851. set(objs.disps5,'String','');
    852. function tStatistic= print1(Mdl, covariance)
    853. if size(covariance,1) ~= size(covariance,2)
    854. error(message('econ:arima:print:NonSquareCovarianceMatrix'))
    855. end
    856. constant = Mdl.Constant;
    857. beta = Mdl.Beta;
    858. beta = beta(:)';
    859. AR = reflect(getLagOp(Mdl, 'AR'));
    860. SAR = reflect(getLagOp(Mdl, 'SAR'));
    861. MA = getLagOp(Mdl, 'MA');
    862. SMA = getLagOp(Mdl, 'SMA');
    863. LagsAR = AR.Lags;
    864. LagsSAR = SAR.Lags;
    865. LagsMA = MA.Lags;
    866. LagsSMA = SMA.Lags;
    867. LagsAR = LagsAR(LagsAR > 0);
    868. LagsSAR = LagsSAR(LagsSAR > 0);
    869. LagsMA = LagsMA(LagsMA > 0);
    870. LagsSMA = LagsSMA(LagsSMA > 0);
    871. if isempty(LagsAR)
    872. AR = [];
    873. else
    874. AR = AR.Coefficients;
    875. AR = [AR{LagsAR}];
    876. end
    877. if isempty(LagsSAR)
    878. SAR = [];
    879. else
    880. SAR = SAR.Coefficients;
    881. SAR = [SAR{LagsSAR}];
    882. end
    883. if isempty(LagsMA)
    884. MA = [];
    885. else
    886. MA = MA.Coefficients;
    887. MA = [MA{LagsMA}];
    888. end
    889. if isempty(LagsSMA)
    890. SMA = [];
    891. else
    892. SMA = SMA.Coefficients;
    893. SMA = [SMA{LagsSMA}];
    894. end
    895. isDistributionT = strcmpi(Mdl.Distribution.Name, 'T');
    896. isVarianceConstant = ~isa(Mdl.Variance, 'internal.econ.LagIndexableTimeSeries');
    897. nARIMA = 1 + numel(LagsAR) + numel(LagsSAR) + ...
    898. numel(LagsMA) + numel(LagsSMA) + numel(beta);
    899. if isVarianceConstant
    900. if isDistributionT
    901. parameters = zeros(nARIMA + 2,1);
    902. parameters(end - 1) = Mdl.Variance;
    903. parameters(end) = Mdl.Distribution.DoF;
    904. else
    905. parameters = zeros(nARIMA + 1,1);
    906. parameters(end) = Mdl.Variance;
    907. end
    908. parameters(1:nARIMA) = [constant AR SAR MA SMA beta];
    909. if numel(parameters) ~= numel(solve)
    910. error(message('econ:arima:print:ModelCovarianceInconsistency'))
    911. end
    912. else
    913. if isDistributionT
    914. parameters(nARIMA + 1) = Mdl.Distribution.DoF;
    915. parameters(1:nARIMA) = [constant AR SAR MA SMA beta];
    916. else
    917. parameters = [constant AR SAR MA SMA beta];
    918. end
    919. end
    920. Fix = ~solve;
    921. errors = sqrt(diag(covariance));
    922. tStatistic = parameters ./ errors;
    923. end
    924. function pushbutton13_Callback(hObject, eventdata, handles)
    925. close ARIMAb
    926. main
    927. function pushbutton14_Callback(hObject, eventdata, handles)
    928. set(handles.shujushuru,'String',[]);
    929. set(handles.shijizhishuru,'String',[]);
    930. set(handles.jianyanjieguo,'String',[]);
    931. set(handles.yibanchaifen,'String',[]);
    932. set(handles.jijiexingchaifen,'String',[]);
    933. set(handles.zhouqi,'String',[]);
    934. set(handles.ppx,'String',[]);
    935. set(handles.d,'String',[]);
    936. set(handles.p,'String',[]);
    937. set(handles.pp,'String',[]);
    938. set(handles.dd,'String',[]);
    939. set(handles.qq,'String',[]);
    940. set(handles.s,'String',[]);
    941. set(handles.yuceshumu2,'String',[]);
    942. set(handles.ppp,'String',[]);
    943. set(handles.d2,'String',[]);
    944. set(handles.p2,'String',[]);
    945. set(handles.pp2,'String',[]);
    946. set(handles.dd2,'String',[]);
    947. set(handles.qq2,'String',[]);
    948. set(handles.s2,'String',[]);
    949. cla(handles.axes2);
    950. cla(handles.axes3);
    951. set(handles.aic2,'String',[]);
    952. set(handles.bic2,'String',[]);
    953. set(handles.yucezhi2,'String',[]);
    954. set(handles.shijizhi2,'String',[]);
    955. set(handles.mae,'String',[]);
    956. set(handles.mape,'String',[]);
    957. set(handles.mse,'String',[]);
    958. set(handles.rmse,'String',[]);
    959. cla(handles.axes1);
    960. set(handles.mae2,'String',[]);
    961. set(handles.mape2,'String',[]);
    962. set(handles.mse2,'String',[]);
    963. set(handles.rmse2,'String',[]);

    五、软件和数据

    链接:https://pan.baidu.com/s/1ZZtT6VTUnqGtQaAZ9NlyCg?pwd=hk4p

    提取码:hk4p

  • 相关阅读:
    元数据介绍
    ESP32S3在VScode中使用USB口调试
    python学习27
    win10系统单独编译和使用WebRTC的回声消除(AEC)、音频增益(AGC)、去噪(NS)模块
    Flutter系列文章-实战项目
    Android应用性能优化
    浙大陈越何钦铭数据结构07-图6 旅游规划【最小堆实现】
    经验分享-Windows共享文件夹,让其他主机访问。
    像素坐标和实际坐标的转换
    Express操作MongoDB
  • 原文地址:https://blog.csdn.net/qq_30452897/article/details/132773016