%% Box-Jenkins Differencing vs. ARIMA Estimation
% This example shows how to estimate an ARIMA model with nonseasonal integration using estimate. The series is not differenced before estimation. The results are compared to a Box-Jenkins modeling strategy, where the data are first differenced, and then modeled as a stationary ARMA model (Box et al., 1994).
% The time series is the log quarterly Australian Consumer Price Index (CPI) measured from 1972 through 1991.
%% Load the Data
% Load and plot the Australian CPI data.

load Data_JAustralian
y = DataTable.PAU;
T = length(y);

figure
plot(y);
h = gca;        % Define a handle for the current axes
h.XLim = [0,T]; % Set x-axis limits
h.XTickLabel = datestr(dates(1:10:T),17); % Label x-axis tick marks
title('Log Quarterly Australian CPI')

% The series is nonstationary, with a clear upward trend. This suggests differencing the data before using a stationary model (as suggested by the Box-Jenkins methodology), or fitting a nonstationary ARIMA model directly.
%
%% Estimate an ARIMA Model
% Specify an ARIMA(2,1,0) model, and estimate.

Mdl = arima(2,1,0);
EstMdl = estimate(Mdl,y);

% The estimated model is
% \Delta {y_t} = 0.01 + 0.21\Delta {y_{t - 1}} + 0.34\Delta {y_{t - 2}} + {\varepsilon _t},
% where \varepsilon_t is normally distributed with standard deviation 0.01.
% The signs of the estimated AR coefficients correspond to the AR coefficients on the right side of the model equation. In lag operator polynomial notation, the fitted model is
% (1 - 0.21L - 0.34{L^2})(1 - L){y_t} = {\varepsilon _t},
% with the opposite sign on the AR coefficients.
%
%% Difference the Data Before Estimating
% Take the first difference of the data. Estimate an AR(2) model using the differenced data.

dY = diff(y);
MdlAR = arima(2,0,0);
EstMdlAR = estimate(MdlAR,dY);

% The parameter point estimates are very similar to those in EstMdl. The standard errors, however, are larger when the data is differenced before estimation.
% Forecasts made using the estimated AR model (EstMdlAR) will be on the differenced scale. Forecasts made using the estimated ARIMA model (EstMdl) will be on the same scale as the original data.
% References:
% Box, G. E. P., G. M. Jenkins, and G. C. Reinsel. Time Series Analysis: Forecasting and Control. 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1994.
% Copyright 2015 The MathWorks, Inc.