www.gusucode.com > econ 案例源码程序 matlab代码 > econ/IllustrateRegARIMAToARIMAXConversionExample.m
%% Illustrate regARIMA to ARIMAX conversion %% Specify the regARIMA model % Copyright 2015 The MathWorks, Inc. Mdl1 = regARIMA('Intercept',0.2,'AR',{0.8 -0.4},... 'MA',0.3,'Beta',[0.3 -0.2],'Variance',0.2); %% Generate presample observations rng(1); % For reproducibility T = 100; maxPQ = max(Mdl1.P,Mdl1.Q); numObs = T + maxPQ;... % Adjust number of observations to account for presample X1 = randn(numObs,2); % Simulate predictor data u0 = randn(maxPQ,1); % Presample unconditional disturbances u(t) e0 = randn(maxPQ,1); % Presample innovations e(t) %% Simulate from Mdl1 rng(100) % For reproducibility [y1,e1,u1] = simulate(Mdl1,T,'U0',u0,... 'E0',e0,'X',X1); %% Convert Mdl1 to ARIMAX [Mdl2,X2] = arima(Mdl1,'X',X1); Mdl2 %% Generate presample responses for the ARIMAX model and simulate y0 = Mdl1.Intercept + X1(1:maxPQ,:)*Mdl1.Beta' + u0; rng(100) y2 = simulate(Mdl2,T,'Y0',y0,'E0',e0,'X',X2); figure plot(y1,'LineWidth',3) hold on plot(y2,'r:','LineWidth',2.5) hold off title('{\bf Simulated Paths for Both Models}') legend('regARIMA Model','ARIMAX Model','Location','Best') %% Fit a regARIMA model to the data ToEstMdl1 = regARIMA('ARLags',[1 2],'MALags',1); EstMdl1 = estimate(ToEstMdl1,y1,'E0',e0,'U0',u0,'X',X1); %% Fit ARIMAX to the simulated data ToEstMdl2 = arima('ARLags',[1 2],'MALags',1); EstMdl2 = estimate(ToEstMdl2,y2,'E0',e0,'Y0',... y0,'X',X2); %% Convert EstMdl1 to ARIMAX ConvertedMdl2 = arima(EstMdl1,'X',X1)