%% Convert a Regression Model with ARIMA Errors to an ARIMAX Model
% Convert a regression model with seasonal ARIMA errors to an ARIMAX model using the arima converter.
% Specify the regression model with \rm{ARIMA(2,1,1)}\times\rm{(1,1,0)}_2 errors:
% \begin{array}{c}
% {y_t} = {X_t}\left[ \begin{array}{c}
%  - 2\\
% 1
% \end{array} \right] + {u_t}\\
% (1 - 0.3L + 0.15{L^2})(1 - L)(1 - 0.2{L^2})(1 - {L^2}){u_t} = (1 + 0.1L){\varepsilon _t},
% \end{array}
% where \varepsilon_t is Gaussian with mean 0 and variance 1.

Mdl = regARIMA('AR',{0.3, -0.15},'MA',0.1,...
    'ARLags',[1 2],'SAR',0.2,'SARLags',2,...
    'Intercept',0,'Beta',[-2; 1],'Variance',1,'D',1,...
    'Seasonality',2)

%
% Generate predictor data.

rng(1); % For reproducibility
T = 20;
X = randn(T,2);

%
% Convert Mdl to an ARIMAX model.

[ARIMAX,XNew] = arima(Mdl,'X',X);
ARIMAX

% Mdl.Beta has length 2, but ARIMAX.Beta has length 8. This is because the product of the autoregressive and integration polynomials, \phi (L)(1 - L)\Phi (L)(1 - {L^s}), is
% 1 - 1.3L - 0.75{L^2} + 1.41{L^3} - 0.34{L^4} - 0.08{L^5} + 0.09{L^6} - 0.03{L^7}.
% You can see that when you add seasonality, seasonal lag terms, and integration to a model, the size of XNew can grow quite large. A conversion such as this might not be ideal for analyses involving small sample sizes.
% Copyright 2015 The MathWorks, Inc.