www.gusucode.com > econ 案例源码程序 matlab代码 > econ/RegresstheGDPontotheCPIandExamineResidualsExample.m

    %% Regress the GDP onto the CPI and Examine Residuals  
% Regress the log GDP onto the CPI using a regression model with ARMA(1,1)
% errors, and then examine the residuals.   

% Copyright 2015 The MathWorks, Inc.


%% 
% Load the U.S. Macroeconomic data set and preprocess the data. 
load Data_USEconModel;
logGDP = log(DataTable.GDP);
dlogGDP = diff(logGDP);        % For stationarity
dCPI = diff(DataTable.CPIAUCSL); % For stationarity
T = length(dlogGDP); % Effective sample size  

%% 
% Fit a regression model with ARMA(1,1) errors. 
ToEstMdl = regARIMA(1,0,1);
EstMdl = estimate(ToEstMdl,dlogGDP,'X',dCPI);  

%% 
% Infer the residuals over all observations. By default, |infer| backcasts
% for the necessary unconditional disturbances. 
e = infer(EstMdl,dlogGDP,'X',dCPI);  

%% 
% Plot the inferred residuals. 
figure
plot(1:T,e,[1 T],[0 0],'r')
title('{\bf Inferred Residuals}')    

%%
% The residuals are centered around 0, but show signs of heteroscedasticity.